# Orientation on missile

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

## 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 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 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.

:-D

##### Share on other sites
Kudos anegri! You just deftly avoided one of the most annoying problems people tend to have in a 3D space -- gimbal lock. Good Job.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632931
• Total Posts
3009292
• ### Who's Online (See full list)

There are no registered users currently online

×