• Create Account

### #Actuallukesmith123

Posted 17 March 2012 - 10:07 AM

Hi,

I have a direction vector and I want to create a rotation matrix from it. This is what I am trying:

//direction = 0, 0, 1
//up		   = 0, 1, 0
//right		= 0, 0, 0

D3DXVec3Normalize(&direction, &direction);
//right
D3DXVec3Cross(&right, &up, &direction);
D3DXVec3Normalize(&right, &right);

rot(0,0) = right.x;
rot(1,0) = right.y;
rot(2,0) = right.z;
rot(3,0) = 0;
rot(0,1) = up.x;
rot(1,1) = up.y;
rot(2,1) = up.z;
rot(3,1) = 0;
rot(0,2) = direction.x;
rot(1,2) = direction.y;
rot(2,2) = direction.z;
rot(3,2) = 0;
rot(0,3) = 0.0f;
rot(1,3) = 0.0f;
rot(2,3) = 0.0f;
rot(3,3) = 1.0f;

I had thought that his would work however it gives me an error where the model that uses the matrix is stretched and appears as a giant line across the screen.

Am I doing something wrong?

### #1lukesmith123

Posted 17 March 2012 - 10:04 AM

Hi,

I have a direction vector and I want to create a rotation matrix from it. This is what I am trying:

//direction = 0, 0, 1
//up  = 0, 1, 0
//right  = 0, 0, 0
D3DXVec3Normalize(&direction, &direction);
//right
D3DXVec3Cross(&right, &up, &direction);
D3DXVec3Normalize(&right, &right);

rot(0,0) = right.x;
rot(1,0) = right.y;
rot(2,0) = right.z;
rot(3,0) = 0;
rot(0,1) = up.x;
rot(1,1) = up.y;
rot(2,1) = up.z;
rot(3,1) = 0;
rot(0,2) = direction.x;
rot(1,2) = direction.y;
rot(2,2) = direction.z;
rot(3,2) = 0;
rot(0,3) = 0.0f;
rot(1,3) = 0.0f;
rot(2,3) = 0.0f;
rot(3,3) = 1.0f;

PARTNERS