how to get the viewpoint ?

Started by
5 comments, last by Gammastrahler 21 years ago
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
Advertisement
do you meen the position of the view? its just m41, m42, m43 (the last row of the 4x4 matrix);
no, i have muddled this with the lookat vector. actually i mean the eye point, i need it to test for backface culling.
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 ,-)
f@dzhttp://festini.device-zero.de
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
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)
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon

This topic is closed to new replies.

Advertisement