Finding pitch, bank, heading from Matrix

Hi again :wink:

I went ahead with Spline Interpolators and it’s going quite well! I’m trying to find the heading, pitch and bank from the current Transform3D so I can pass them into the first key frame of my “tweening” interpolation. All the notes I’ve read show you how to set these values in the matrix, but I can’t work out/haven’t found anything to tell me how to get them out again. I find understanding the matrix pretty difficult!

Is it possible to get these values out? How can it be done with the least amount of Maths? (However, I will put in the hard yards if necessary!)

Thanks in advance :slight_smile:

Are you really sure you want to do this? Roll/Pitch/Yaw is known in mathematical terms as ‘Euler angles’. There are conversions from matrix to Euler on the net (googling for Euler & Matrix should find them). However, Euler angles are not very good, as there are sometimes multiple euler specifications for the same angle, and there is a situation called ‘gimbal lock’ where you lose a degree of freedom.

If the matrices that you are tweening are < 90 degrees apart in the axis (the dot products between the axis of each matrix are all positive), you can actually get away with linearly interpolating & re-orthonormalising. This is sufficient for most games. Just adding keyframes to the path to ensure this is the case is usually fairly easy, and does not add too much overhead. At runtime, this is the fastest solution.

For larger differences, you are better off looking at interpolating Quaternions. These accurately describe rotations - although a bit of care is needed to distinguish positive & negative quaternions that evaluate to the same rotation. This is computationally more expensive that a linear interpolation but accurate for rotations up to 360 degrees in any axis. Again, googling for ‘Quaternion Interpolation’ should throw up some relevant sites.

As a test (during my last job), I wrote a character animation blending system (used on a few published console games), and challenged the artists to spot which one was using linear interpolation & which one was quaternion. They could not tell the difference, which just goes to show. Remember that for a game, all you need is ‘perceived quality’ - not rigorous mathematical accuracy.

  • Dom

Thank you ever so much for your answer, Dom. I thought I was never going to recieve a reply :slight_smile:

Isn’t it amazing how problems look completely different given time and a little nudging? :smiley: Your reply was very well though-out, if only I could understand most of it! I’m afraid we haven’t been taught anything about 3D in my Uni course yet. However, your mentioning of simply adding keyframes seems to be the trick.

Having spent 20-30 minutes just fiddling, this does seem to be the best way of achieving what I want. I hacked out the guts of my tweening function and replaced it with a basic array copy of the keyframes, shifting all of their knot values down by a half and then ramming in the new position the ship should be at at the end of the animation. Obviously, this currently looks rough as hell because the alpha values no longer align (setting the tweening anim to loop twice is a proof of concept) but I should be able to rig together a new alpha and then choose an appropriate time to force the alpha to start at, which should make the interpolator splice together the animations for me!

Thank you once again Dom, you’re a star 8)