Skip to main content
gamedev.net
🔒 Locked

Modelview matrix hell...

Started by Slug Jan 28, 2006 at 9:10 PM 6 replies 750+ views
Original Post
Slug
Slug
Hi, i got some problem with matrix... In my game, i do my camera rotation by rotating the scene with glRotate, so i dunno where my camera is in xyz coordinate. I know how to extract the modelview matrix value from opengl but dunno how to find what i want. Any idea?
Zakwayda
Zakwayda
Quote:
Original post by Slug
Any idea?
Sure, but we'll need more info. I would start by posting the code where you set up the transformation for your camera.
Slug
Slug
ok, so here how it's done in my game:

glPushMatrix();
//Rotate around the scene
glRotatef(xRotation, 1.0f, 0.0f, 0.0f)
glRotatef(yRotation, 0.0f, 1.0f, 0.0f)
//Translate the scene
glTranslatef(xTranslation, yTranslation, zTranslation);

//more code
...

glPopMatrix();


So, i wanna know where the camera is now, in a xyz coordinate.
How did i find that?
smitty1276
smitty1276
You need to position the camera...
glTranslatef(camera.x, camera.y, camera.z);

Then do the camera's rotations...
glRotatef(...)
...


Then push the matrix on the stack and translate/rotate for all objects.



smitty1276
smitty1276
Actually... make that...
glTranslatef(-camera.x, -camera.y, -camera.z);

Zakwayda
Zakwayda
Quote:
Original post by Slug
ok, so here how it's done in my game:

glPushMatrix();
//Rotate around the scene
glRotatef(xRotation, 1.0f, 0.0f, 0.0f)
glRotatef(yRotation, 0.0f, 1.0f, 0.0f)
//Translate the scene
glTranslatef(xTranslation, yTranslation, zTranslation);

//more code
...

glPopMatrix();


So, i wanna know where the camera is now, in a xyz coordinate.
How did i find that?
You usually don't need to 'find out' where the camera is in OpenGL, because you're the one who told OpenGL where it is in the first place. As suggested in the above posts, the problem may be that you're not setting up your camera transform properly: all of the 'Translation' and 'Rotation' values in the above code should be negated.
StPapyna
StPapyna
All the above is rotate the scene

if you do not want to rotate the whole scene but just like change the view point:

glMatrixMode(GL_MODELVIEW)
gluLookAt(XXXXXXXXX)

haegarr
haegarr
To give an explanation: Notice that a camera (if using such) is given in the same scene as the objects are. The belonging co-ordinate frame is normally named the "global" or "world" frame. But what you want to display is not the world itself but the cut scene as seen through the camera. So you don't have to render in the global frame but in the local frame of the camera. To come from the global to the camera local frame, you have to apply the _inverse_ transformation of the camera frame (since the frame describes how to come from the local to the global frame), i.e. the inverse (negated) translation and inverse rotation. Notice please that also the typical order is reversed. This inverse transformation is what is meant with the VIEW portion of the MODELVIEW matrix.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.