Getting Eyepoint from View Matrix

Started by
5 comments, last by viscoder 22 years, 4 months ago
Does anyone know how to calculate the camera eyepoint directly from the view matrix? I am doing matrix multiplicatons (translation and rotation) directly on the view matrix to change my viewpoint, as opposed to using the D3DXMatrixLookAtLH, but still need to keep track of my position in world coordinates. Any help is appreciated.
Advertisement
Oooh! You''re not using LookAtLH! I can''t figure out how to make it work without using that! Plz can I ''borrow'' a bit of your source code? Have pity on a poor newbie to 3D stuff!

---------------

I finally got it all together...
...and then forgot where I put it.
Check the Point Sprites sample code in DirectX 8.1 - UpdateCamera().

Back to the original question - Does anyone know how to get eyepoint position directly from the view matrix?
Thanks. About your question - shouldn''t you be building your view matrix from your eye co-ords? If you are, what''s the problem with just storing them?

---------------

I finally got it all together...
...and then forgot where I put it.
I am building it from mouse or key presses to change the viewpoint translation/rotation (like the point sprites sample), so I do not input eyepoint position.
Matrices are nothing more than transformations from one coordinate system to another. A ''view'' matrix takes coordinates from world space, and transforms them to view space. If you invert the view matrix, you will have a matrix that takes coordinates from view space, and transforms them to world space. Since the camera is defined to be at the origin in view space, all you need to do is transform (0,0,0,1) by this inverse view matrix, and you will have the camera''s position in world space. (Node that transforming (0,0,0,1) by a matrix is equivalent to simply copying the last row.)
D3DXMATRIX mViewInv;D3DXMatrixInverse(&mViewInv, NULL, &mView);D3DXVECTOR3 vPosition;vPosition.x = mViewInv._41;vPosition.y = mViewInv._42;vPosition.z = mViewInv._43; 

xyzzy
Thanks for the little tutorial & code! It works great.

This topic is closed to new replies.

Advertisement