Jump to content
  • Advertisement
Sign in to follow this  
sjf

How to get camera position?

This topic is 4419 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

How do I determine the camera position when my scene is drawn from the following Point-of-view?: glLoadIdentity(); glTranslatef(0.0f, 0.0f, -20.0f); glRotatef(+g_mouse_z, 0.0f, 0.0f, 1.0f ); glRotatef(-g_mouse_y, 1.0f, 0.0f, 0.0f ); glRotatef(-g_mouse_x, 0.0f, 1.0f, 0.0f ); Th8ks peeps!

Share this post


Link to post
Share on other sites
Advertisement
It's the arguments to the first glTranslate, negated. In this case, the camera is at (0,0,20).

Note that, given a MODELVIEW matrix, it's impossible to tell where the camera is, and where the object is, as they've been multiplied together. However, in eye space (post-MODELVIEW), the camera is always at (0,0,0).

You might want to look at My simple camera tutorial.

Share this post


Link to post
Share on other sites
So then how can I track the camera position when the mouse is moved?

Share this post


Link to post
Share on other sites
In my own code I keep track of it, but I get the info from OpenGL. I don't remember why, precisely, but it appears to work.

    GLfloat mdl[16];
float camera_org[3];
glGetDoublev(GL_MODELVIEW_MATRIX, mdl);
camera_org[0] = -(mdl[0] * mdl[12] + mdl[1] * mdl[13] + mdl[2] * mdl[14]);
camera_org[1] = -(mdl[4] * mdl[12] + mdl[5] * mdl[13] + mdl[6] * mdl[14]);
camera_org[2] = -(mdl[8] * mdl[12] + mdl[9] * mdl[13] + mdl[10] * mdl[14]);


It appears given the modelview matrix (which is an array of 16 floating point values), the origin is the negative of each axis component scaled by the matrices corresponding translation component. Or something. I don't pretend to completely understand it, but it seems to work for me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Wudan
It appears given the modelview matrix (which is an array of 16 floating point values), the origin is the negative of each axis component scaled by the matrices corresponding translation component. Or something. I don't pretend to completely understand it, but it seems to work for me.


What you got there is the collapsed form of applying the negative translation matrix to the rotation matrix (which only works if you stay away from scaling). Or the other way round. Or the transposed (in this case the same as inversed) rotation matrix. It's just been too long. Plus I'd probably apply the inverse rotation and translation in the INVERSE order to set up the view.. if I wouldn't have packed all that stuff in a camera class long ago and never touched it again.

Share this post


Link to post
Share on other sites
Thanks heaps everyone! Wudan, your snippet worked like a gem. A huge Thanks to you (++rating).

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!