PDA

View Full Version : Getting Viewing direction from World Matrix



markun
06-22-2004, 03:27 AM
Hello?
Can someone tell me how can i get the viewing
vector from the World Matrix?

Corrail
06-22-2004, 05:13 AM
You can get the view vector by doing the following:

First you invert the View-Matrix and than you multipy the invers-View-Matrix with the vector (0,0,1)

zed
06-22-2004, 12:17 PM
is it necessary to invert it, i just use

forward_direction_vector = VECTOR( use_cam_rotMATRIX.m[2], use_cam_rotMATRIX.m[5], use_cam_rotMATRIX.m[8] );
which has worked flawlessly until now.
could this run into problems?

SirKnight
06-22-2004, 01:58 PM
This is how I do it in my camera class and it works great.


Matrix4 camRot, cx, cy;

camRot.ToIdentity();
cx.ToIdentity();
cy.ToIdentity();

cx.RotateX( m_fPitchAngle * DEGTORAD );
cy.RotateY( m_fYawAngle * DEGTORAD );

camRot = cy * cx;

vector_t dir = camRot * m_vVelocity;

if( dt > 0 )
VectorMulFloat( &dir, dir, dt );-SirKnight

Jared
06-22-2004, 11:52 PM
Originally posted by zed:
is it necessary to invert it, i just use

forward_direction_vector = VECTOR( use_cam_rotMATRIX.m[2], use_cam_rotMATRIX.m[5], use_cam_rotMATRIX.m[8] );
which has worked flawlessly until now.
could this run into problems?unless you have scaling or sheering in your matrix (which shouldnt be the case) the inverted rotation part is the transposed. multiplying the "z"vector with that should result in the z axis of the matrix. ie. it should be pretty much what youre doing.

knackered
06-23-2004, 02:15 AM
None of this is the viewing vector if the model has been orientated in world space using the modelview matrix. You're extracting a vector that is the concatonation of the models transform and the viewing (camera) transform.
In d3d the 2 transforms are kept seperate, but in GL they're fused into 1 transform.

Jared
06-23-2004, 11:16 AM
Originally posted by knackered:
None of this is the viewing vector if the model has been orientated in world space using the modelview matrix.hm, i guess we simply expected he is aware that he has to do it BEFORE any additional transformations are applied. but i admit i like the seperate matrices of d3d better.