Orient a missile along it's velocity vector

Started by
2 comments, last by Moagly 20 years, 4 months ago
If i have a missile that is travelling along a velocity vector, and i want to rotate the missile so that it is always facing in the direction of the velocity vector what do i need to do? At the moment i am retreiving the modelview matrix and changing the z rotation for the model to the y component of the normalised velocity vector like this :


	Vector3d temp = velocity;
	temp.Normalise();

	float modelview[16];
	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	modelview[8]  *= temp.y;
	modelview[9]  *= temp.y;
	modelview[10] *= temp.y;

	glLoadMatrixf(modelview);

But this just seems flatten the missile in the z axis and orient the plane to the vector perpendicular to the velocity vector. I have tried crossing the velocity vector with up (0,0,1) but this just gives the same results! Does anyone have any ideas or suggestions as to what i might be doing wrong?
Advertisement
*cross post in the Graphics forum*

You have to remember that you''re unique, just like everybody else.
If at first you don't succeed, redefine success.
if u have the direction/facing vector of the missile and subsequently the velocity vector... u have all the details to obtain the angle from the dot product.. cant you?
- To learn, we share... Give some to take some -
and the cross product

Everything is better with Metal.

This topic is closed to new replies.

Advertisement