 # Pointing your model in the correct direction?

I am using a matrix (m) to hold all data, and my problem is I don’t know how to point the model in the correct direction. In this case, I have a missile, which has 6DOF, and it was fired from a ship that also has 6 DOF.

Is there a simple way to point the missile in the direction it is heading? At first I tried to use m,m,m, since that is dirX,dirY,dirZ, but that didn’t work all the time, that only works when the missile is fired down the Z axsis.

Any pointers to this?

try using euler angles!

given the desired rotation for the current frame in angles, you convert these angles to a matrix. Then you multiply this newly created matrix by the object’s matrix.

Additionally you can create a new identity matrix and set it’s 12, 13 and 14th elements to the x, y and z position change for the frame and multiply this matrix by the object’s matrix. This will change the object’s translation in the object space.

If you want i can send you some code(just mail me), while its not exactly what you want (I have a camera class) it does the same thing, except that it puts the inverted matrix on an opengl’s modelview matrix stack.

-Lev
levp@gmx.net

Are you sure m,m,m is the direction of your missle. I’m using m,m,m and I think it’s working.

It depends upon the type of matrix being used, and the orientation of the object in object space.

I just noticed something, I was looking at this:

Xx Yx Zx Tx
Xy Yy Zy Ty
Xz Yz Zz Tz
0 0 0 1

and then I have seen this:

Xx Xy Xz Tx
Yx Yy Yz Ty
Zx Zy Zz Tz
0 0 0 1

Which both map to

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

The first matrix is correct right?

As for euler angles, the problem is the gimbal lock, so I switched to quaternion + matrix, which doesn’t have gimbal lock.

I am checking out the source code now Lev, thanks again.

[This message has been edited by Elixer (edited 01-22-2001).]

As far as I know, the reason it does work to simply set the “front” vector portion of the matrix is because you also need a correct “up” vector and “right” vector to go with it. Get the vector to what you’re wanting the missile to look at (destinationPosition - missilePosition) then nomralise it and stick it in your “front” vector portion of your matrix. If you set the front vector, then make an assumption about the “up” vector (like up the positive Y axis - 0,1,0 or get it from whatever launched the missile), then get the crossproduct of these two to get a vector that is at a right angle to both of these to obtain your “right” vector. Then, go back and do a crossproduct on your front and right vectors to get the correct up vector. That should complete your matrix. It should now be pointing in the desired direction.