Michael George wrote:
I'm not sure, but I think using that terminology, if you have a quaternion representing your position/orientation on the surface of the sphere, then converting it to euler angles gives your (longitude, latitude, heading) = their (heading, attitude, bank). Your motion routines should all be straightforward: convert each of your directions to quaternions, and then multiply.
There isn't much advantage to using quaternions rather than rotation matrices if all you want to do is compose rotations. It's straightforward to calculate rotation matrices for given angles around the x, y and z axes and multiply them together. Although multiplying quaternions is slightly easier than multiplying matrices, you have to convert the result to a matrix in order to transform points with it, and the extra computation required to do that loses most of the advantage. Another thing you need to be aware of is that Euler angles are not a good coordinate system for incrementally keeping track of the orientation of an object. In a physics simulation, the orientation of a body should be represented by either a rotation matrix or a quaternion. If you try to do this using angles in some way, you'll run into problems with singularities in the coordinate system. For example, when your observer is at the north pole, you have no way of keeping track of its heading, because all directions are "south". The way I would approach this is that it's essentially a flight simulator in which the observer is constrained to move on the surface of a sphere instead of moving freely in 3D space. The state of the observer is represented by a position P and a rotation matrix R. Let's adopt the convention that the observer's local x axis points forward from his point of view, his y axis points to the left, and his z axis points upwards. We initialise P and R so that P is somewhere on the surface of the earth and his local z axis is pointing directly away from the centre of the earth. If the observer moves at constant speed, then in one time unit he will move forward by some constant distance dx. If he weren't constrained to the surface of the earth, he would simply move by a vector dX = (d, 0, 0) in his local coordinates, or R * dX in global coordinates. However, because he's on a sphere, he will also move a small distance downwards, so his local movement vector is dP = (dx, dy, 0) where dy can be calculated from dx and the radius of the earth, or R * dP in global coordinates. As well as that, he will also pitch downwards slightly so that his x axis remains parallel with the surface of the earth. The angle of this pitch change will be equal to the angle between his old and new positions as measured from the centre of the earth. For a constant step size, we can precalculate this angle, let's call it a, and a corresponding rotation matrix Ry(a) (a rotation by angle a around the y axis) representing his local change in orientation. We can now update the observer's state in global coordinates using the following formulas: P' = P + R * dP R' = R * Ry(a) -- Greg