Sign in to follow this  

finding a vector projected from from another using a matrix??

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

..i am just making a simple fps camera.. I have a position vector (xyz) and i have a matrix4X4 that defines its rotation and translation... how do i go about finding the direction to move towards the way i am looking? i am thinking i will just find the a unit vector in the way the camera is facing from the position the camera is at.. i am not sure of how to do the math to accomplish this... i am using directx so explaining this to me with D3DX functions is ok, but not imperative

Share this post


Link to post
Share on other sites
The direction vectors (side, up, forward) can be extracted directly from the transformation matrix. They are in the first three rows if the matrix is a local->world matrix, or the columns if it's a world->local (i.e. view) matrix. Here's an example of extracting the vectors from the rows using 1d indexing:
Vector3 x(m[0], m[1], m[2]);
Vector3 y(m[4], m[5], m[6]);
Vector3 z(m[8], m[9], m[10]);
And using named 2d-index variables:
Vector3 x(m11, m12, m13);
Vector3 y(m21, m22, m23);
Vector3 z(m31, m32, m33);
For a view matrix, simply transpose the examples.

Share this post


Link to post
Share on other sites
Quote:
Original post by MTclip
I have a position vector (xyz) and i have a matrix4X4 that defines its rotation and translation...

Not sure if this is a typo, but the position and translation are the same. IE, the translation vector of the matrix is the camera position.

I can't remember the exact object names in D3DX, but something like this, I believe..

PositionVector += VECTOR( CamMatrix._31, CamMatrix._32, CamMatrix._33 ) * DesiredDistance;

The 31,32,33 values are what jyk referred to as the z vector. Which is basically like a direction pointing forward. The y vector points up, and the x vector points to the right of the object.

Share this post


Link to post
Share on other sites
Sign in to follow this