About vectors

Started by
10 comments, last by alvaro 11 years, 11 months ago
I am reading "3d math primer for graphics and game development" book, and i have made simple project to practice on as i read.
I have made a arrow model with tail at origin and tip pointing 0 0 1 (forward).

So i can assume that basis vectors is this?:

right 1 0 0
up 0 1 0
forward 0 0 1


and then i take some arbitrary point to be my new target at witch arrow will point.


newForwardDir = targetPos - myPosition;


and now i want to buid new matrix so i need all other vectors transformed.

So i am thinking that new UP vector is:

newUPDir = newForwardDir cross oldForwardDir

right? yes/no?

And if so then:

newRightDIr = newUpDir cross newForwardDir

right?

Then i tried:

D3DXMATRIX mat;
D3DXMatrixIdentity(&mat);
mat._11 = rightDir.x;
mat._12 = rightDir.y;
mat._13 = rightDir.z;
mat._21 = upDir.x;
mat._22 = upDir.y;
mat._23 = upDir.z;
mat._31 = forwDir.x;
mat._32 = forwDir.y;
mat._33 = forwDir.z;

D3DDevice->SetTransform(D3DTS_WORLD, &mat);
arrowMesh->DrawSubset(0);

and it looks ok but i don't know am i right?

And my questions is :
1. As book says about cross product that it depends on order of vectors as a cross b is not same as b cross a as it will point in opposite directions, how should i know in witch order to set vectors as parameters?

2. How can i build a rot. matrix with D3DXMatrixRotationAxis as i don't know what to specify for rotation axis, what is it?
What about angle parameter for that function, is that a :

angle = acos( newForward dot oldForward )


Thanks for your patience.
Advertisement
You only have the direction that (0,0,1) should map to, but that's not enough information to determine the whole transformation. What you are doing breaks down if newForwardDir == oldForwardDir.

1. It depends on what you are using the cross product for. But this is usually not too hard to figure out if you think of examples.

2. If you already have a rotation matrix, I am sure you don't need to use D3DXMatrixRotationAxis. But if you ever need to compute the rotation axis, it is an eigenvector of the rotation matrix.

This topic is closed to new replies.

Advertisement