#### Archived

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

# how to get the viewpoint ?

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

## 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 on other sites
do you meen the position of the view? its just m41, m42, m43 (the last row of the 4x4 matrix);

##### Share on other sites
no, i have muddled this with the lookat vector. actually i mean the eye point, i need it to test for backface culling.

##### 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 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 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 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)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013601
×