share your tricks how you avoid Gimbal lock in Euler rotations, and keep full degree of freedom... Parenting, constraining, quaternions..., you name it!
Julian Mann
[ Admin ]
If you are writing tools, there are a number of ways to represent orientations that are better than Euler Angles.
- Rotation matrix
- Aim and Up
- Quaternions
- Axis-Angle
- more maybe ...
Its useful to gather techniques to convert between all the above and Euler Angles. I find, the most common reasons to manipulate orientations is to simulate the physics of rotating rigid bodies, or to create angular springs.
Try to avoid Euler rotations for this kind of stuff. They can be really annoying, not just because of gimbal lock. Say you want to make an object tumble through space constantly. If you set some keys to make linear animation curves on rx,ry, and rz you will probably not get a smooth linear tumbling motion. It will appear to change direction of rotation and look unnatural. People often try to simulate tumbling objects as particle instances like this and and find it looks weird. I think the main reason 3d apps use Euler rotations is to make manipulators easy to implement. ;)
Rotation matrices are a bit difficult to work with, and generally you don't want to expose them in a UI. They are very useful in conjunction with other transformations though, and also to help convert between other rotation representations.
Aim-Up is effectively an aim constraint. you define where you want one axis of the object to point (X for example), and an up direction (Y for example). The up is orthogonalized and then a cross product calculated to become (Z). Now you have a complete coordinate system and can construct a rotation matrix from the three direction vectors.
Quaternions are not so easy to grasp (not for me anyway). However, they are well suited to simulating angular physics because they easily represent angular momentum and torques. Most quaternion classes have linear and quadratic interpolations, meaning you can find a rotation between 2 other rotations, or on the smooth path defined by three rotations.
Axis-Angle representations I find are the easiest to work with. They are similar to quaternions, only without the imaginary stuff. Euler proved that any orientation can be represented by a rotation about one axis. So (x, y, z, theta) are all thats needed to represent the rotation. You can in fact make the axis to be the length theta, and in that way store the rotation in 3 floats. In the case that the angle is zero, the axis is zero length, but because there is no rotation you don't need the axis anyway. Say you want to create tumbling objects as in the earlier example. The change in orientation (angular velocity) is represented by a vector (R). You just keep adding R*dT every frame (dt is the time-step). You can do much more than this - add torques(springs, drag, spin impulses), all with the same representation. It makes simulating rotations nearly as easy as simulating particle positions. Once you have a final orientation you'll probably need to convert back to Euler angles for the UI.
I'll add some techniques I have found for applying torques and for various conversions in a later edit.
