Archived

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

viscoder

Getting Eyepoint from View Matrix

Recommended Posts

viscoder    122
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.

Share this post


Link to post
Share on other sites
AdmiralBinary    100
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.

Share this post


Link to post
Share on other sites
viscoder    122
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?

Share this post


Link to post
Share on other sites
AdmiralBinary    100
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.

Share this post


Link to post
Share on other sites
viscoder    122
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.

Share this post


Link to post
Share on other sites
xyzzy00    307
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

Share this post


Link to post
Share on other sites