Original Post
🔒 Locked
Modelview matrix hell...
Advertisement
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?
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 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.
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.
Actually... make that...
glTranslatef(-camera.x, -camera.y, -camera.z);
glTranslatef(-camera.x, -camera.y, -camera.z);
Quote: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.
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?
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.
Advertisement