Jump to content
  • Advertisement
Sign in to follow this  
Slug

OpenGL Modelview matrix hell...

This topic is 4587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!