Sign in to follow this  

Orientation on missile

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am working on a project where I have a missile following a path of points. So I obtain the angle between the two vectors v0 is the missile from the origin and v1 is a point in space with respected to the origin as well. The origin (0, 0, 0) is the starting position of the missile and v0 denotes the end of the missile. I use the dot product and obtained the angle in radians then I transform the angle to degrees. How do I rotate the missile based on the acquired angle with OpenGL? Should I use glRotate(theta, v1.x, v1.y, v1.z)? or a sequence of rotates: glRotate(theta, v1.x, 0.0, 0.0) glRotate(theta, 0.0, v1.y, 0.0) glRotate(theta, 0.0, 0.0, v1.z) or the glMulMatrix function? I cannot seem to get the right orientation, any sample or help would be much appreciated. Many thanks, Alessandro

Share this post


Link to post
Share on other sites
There is a variety of ways to tackle this, but the simplest is probably to use axis-angle representation.

1. Compute and normalise the two heading vectors, current and default, corresponding to the world-space orientation of the object before and after transformation. In your case, current = v1 and default is whichever way the missile is oriented in its object-space.

2. Compute the dot-product dot = current • default.

3. Make sure the missile needs to be rotated, by testing (dot < 1.0f - EPSILON).

4. Compute the angle through which the rotation needs to be performed: angle = acos(dot).

5. Compute the axis about which to rotate via a cross-product: axis = current × default.

6. Perform the rotation using glRotate(angle, axis.x, axis.y, axis.z).

Share this post


Link to post
Share on other sites
It worked like a charm!!!!

Thanks so much for the quick reply... the step I had missing was the cross product calculation for the axis.

I salute you Mr. Admiral!
:-D

Share this post


Link to post
Share on other sites

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this