Archived

This topic is now archived and is closed to further replies.

how to get the viewpoint ?

This topic is 5374 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 want to get the viewpoint out of the modelview matrix. if i call
  
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
  
i have the right, up, and forward vectors. but how can i compute the viewpoint out of it? would be wonderful if anyone could help me.... thanks Gammastrahler

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
do you meen the position of the view? its just m41, m42, m43 (the last row of the 4x4 matrix);

Share this post


Link to post
Share on other sites
hm.. usually i would go the other way round. have my own matrix camera and feeding it to opengl. the modelview matrix after glulookat (you shouldnt do any transformations before and after except setting it to identity) is the inverse of what you want. the three vectors are transposed and the position (according to the handy formula for d3ds lookat function) is
-dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye)

so you just have to solve for the eye point. but honestly, its a strange concept, where you dont keep track of your camera location and have to extract it from the matrix ,-)

Share this post


Link to post
Share on other sites
If the object being rendered is located at P, and the current model-view matrix is M, then the location of the camera is found like this:

  ex = P[ 0 ] - M[ 12 ];
ey = P[ 1 ] - M[ 13 ];
ez = P[ 2 ] - M[ 14 ];

But I agree with Trienco. This is a strange way of finding the viewpoint. How do you move the camera if you don''t keep track of its location? If you use gluLookAt, you already know the viewpoint.

Share this post


Link to post
Share on other sites
I think after you get the model view (assuming that there is only the World-to-Camera space transform on there, i.e., no object-to-world transforms) you just invert this matrix and get position m41, m42, m43 of the transform(assuming column major). You need to invert the what you get back from the modelview since the camera transform is really the inverse of it''s local-to-world transform.

Share this post


Link to post
Share on other sites
quote:
Original post by Gammastrahler
no, i have muddled this with the lookat vector. actually i mean the eye point, i need it to test for backface culling.


OpenGL can do backface culling for you :


  
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);


After that OpenGL does it for you (you have to provide the normals offcourse)

Share this post


Link to post
Share on other sites