Skip to main content
gamedev.net
🔒 Locked

3d vector => matrix

Started by BeanDog Jan 20, 2001 at 2:50 PM 1 replies 200+ views
Original Post
BeanDog
BeanDog
If I have a normalized vector representing the direction an object is facing, how do I find the rotation matrix that would translate the point (0,0,1), or any other point, onto it? ~BenDilts( void );
BeanDog
BeanDog
actually I have 3 vectors that represent the positive x, y, and z axis relative to the object. If I simply perform rotations on the points around axis represented by one of the vectors I should end up rotating around the relative x,y,z axis, correct? So this should work:

right is the x-axis, dir is the z-axis (where the object is facing), and up is the y-axis.

RotateRelative(float x, float y)
{
D3DXMATRIX m;
D3DXMatrixRotationAxis(&m, &right, D3DXToRadian(x));

D3DXVECTOR4 vec4;
D3DXVec3Transform(&vec4, &dir, &m);
dir.x = vec4.x;
dir.y = vec4.y;
dir.z = vec4.z;

D3DXMatrixRotationAxis(&m, &up, D3DXToRadian(y));
D3DXVec3Transform(&vec4, &dir, &m);
dir.x = vec4.x;
dir.y = vec4.y;
dir.z = vec4.z;

}

But then how do I convert one of those three vectors (or two of them? or all three?) into a rotation matrix?



~BenDilts( void );
3dModelMan
3dModelMan
I have 3 vectors that represent the positive x, y, and z axis relative to the object

Then you don''t need to perform any further rotations..

PlayerMatrix =
[Xvector.x, Xvector.y, Xvector.z, 0]
[Yvector.x, Yvector.y, Yvector.z, 0]
[Zvector.x, Zvector.y, Zvector.z, 0]
[Xposition, Yposition, Zposition, 1]

- Matt



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.