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

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

## 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 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 on other sites
Quote:
 Original post by MTclipI 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.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

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

• Total Topics
633734
• Total Posts
3013587
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!