## 3D Homing Missile

Currently, my missile has a vector for its current location, a float for speed, and a quaternion for orientation. How can I gradually rotate the quaternion to lock onto a specific target, given the aforementioned variables?

Also, how would I apply the quaternion to openGL?

You'll need to convert the Quaternion of the missile's orientation to an OpenGL 4x4 rotation matrix that you can use when drawing the missile.

To turn the missile towards its target, ou'll either need to calculate the minimum arc Quaternion that represents the angle between the direction vector of the missile's flight and the vector from the missile's location to its target location, and apply a fraction of it to the missile's orientation each frame to turn the missile towards the target.

Or calculate the axis the missile has to turn about in order to face the target (the cross product of the missile's direction vector and the vector from the missile to the target), and turn the missile a fraction of an arc about that axis each frame.

Code to calculate the Quaternions to perform each of these steps can be easily found. There's some in my craptacular source to Oolite (vector.c), but I use a different algorithm for my homing missiles (it's more hokey - I wouldn't recommend it).

However, I stumbled upon another interesting way to go about it in the GameDev.net forums:

Take the missile's current heading vector, and the vector from the missile's position to the target's position. These two form a plane that intersects both ships. Take the cross product between the vectors. You now have the normal of that plane. If you rotate around that normal, you are rotating on a plane that contains the missile and target. That is, the problem of steering towards the target is reduced to one variable - the missiles angle on that plane! I haven't tried it, but it seems really really cool and definitely worth investigating.