PDA

View Full Version : Attaching view to the model



11-14-2003, 01:11 AM
Hello,
It seames that Rotating and Translating is one of the toughest parts for a beginner in opengl.
I am Trying to attach the view to a model for quite a while now with now success. I have read quit alot of articles to but just can't get it figured out.

So in other words i have a view (camera) gluLookAt or just loading the identity (glLoadIdentity) and then translate and rotate the view along with the model.

the model(object like car, plane, first person etc..) is translating and rotating like i want it to. Pritty much with this simple formula:
x += sinf(direction)*speed;
y += cosf(direction)*speed;
and roateted correclty around it's origin axis.

now to make a more clear question. How can i let the camera rotate around the same point x,y,z as the model ?

i tried:
glLoadIdentity();
glRotatef(objroll, 0.0, 0.0, -1.0);
glRotatef(objpitch, -1.0, 0.0,0.0);
gluLookAt(x,y,z, lookx, looky, lookz, 0, 1, 0);
.
.
Rotate & Translate model

and:
glLoadIdentity();
glRotatef(objroll, 0.0, 0.0, -1.0);
glRotatef(objpitch, -1.0, 0.0,0.0);
glTranslatef(x,y,z);
gluLookAt(x,y,z, lookx, looky, lookz, 0, 1, 0);
.
.
Rotate & Translate model

But a soon as the model(object) has rotated to some degrees around the x or y axis the camra rotates either around a differen origin or rotates only correct around the z axis.
I hope my question is some what clear.
Thanks for any help on this.

Regards

Fagery

nexusone
11-14-2003, 05:10 AM
You could be what you are seeing is gimble lock. Do a search on this forum under that topic.

Now remember OpenGL does not have a camera per say, but we memic one by using tranlation/rotation, glulookat, etc.

Maybe you should not be moving your model in which you want to follow, but the world around it like we do with the camera.


glLoadIdentity();
gluLookat(......);

Draw_My_Object();

glTranslate
glRotate

//Draw rest of the world here