What are quaternion used for in game development?
I've been studying up on quaternion because I'm curious as to what they are used for in game development these days.
What I understand from what I've been reading is that a quaternion are used as a vector or scalar and works in 4th dimensional space.
For the most part, it has been superseded by the matrix in most applications.
So what would you use quaternions on that can't be done in any other way?
Quaternions represent rotations, and are used quite a bit. Game programmers typically use both representations, converting between them as needed; some things are easier to do in one vs the other.
Of course, since both rotation matrices and equivalence classes of unit quaternions (under the equivalence relation q~-q) represent the same thing, there's nothing that you can't do with one representation that you can do with the other. Though the whole distinction is a bit silly, IMHO... It's like arguing about whether Cartesian or spherical coordinates are "better..."
For an example, though, here are some things that are easier to do with quaternions:
1 - Making sure that, despite rounding errors, your "rotation" representations really represent pure rotations (without any scaling/shear). Quaternions simply cannot represent shear, and to eliminate scaling all you need to do is divide a quaternion by its length.
2 - Traveling along geodesics on the manifold of rotations; when represented as quaternions this becomes SLERP, which is pretty easy.
3 - Along with #2... Calculating the geodesic distance between rotations is very easy with quaternions (a "dot product"); with matrices it involves an inverse and an eigendecomposition.
Of course, since both rotation matrices and equivalence classes of unit quaternions (under the equivalence relation q~-q) represent the same thing, there's nothing that you can't do with one representation that you can do with the other. Though the whole distinction is a bit silly, IMHO... It's like arguing about whether Cartesian or spherical coordinates are "better..."
For an example, though, here are some things that are easier to do with quaternions:
1 - Making sure that, despite rounding errors, your "rotation" representations really represent pure rotations (without any scaling/shear). Quaternions simply cannot represent shear, and to eliminate scaling all you need to do is divide a quaternion by its length.
2 - Traveling along geodesics on the manifold of rotations; when represented as quaternions this becomes SLERP, which is pretty easy.
3 - Along with #2... Calculating the geodesic distance between rotations is very easy with quaternions (a "dot product"); with matrices it involves an inverse and an eigendecomposition.
Thanks for the info. I was thinking they had a special use and I can see now they can simplify certain tasks.
For what it's worth, I'm an animation programmer and almost every peice of animation code i've seen in various engines (including unreal) use quaternions for the rotation portion of bone data.
They work well because they dont have a problem with gimmbel lock and they slerp real easily (:
They work well because they dont have a problem with gimmbel lock and they slerp real easily (:
Quote: They work well because they dont have a problem with gimmbel lock...Just FYI, quaternions have no special properties with respect to gimbal lock (you can encounter gimbal lock just as easily when using quaternions as when using matrices).
Quote: Original post by jykMy understanding is that joint animation based on "zero joint rotation" is less prone to gimbal lock. That's all I've heard that makes any impact in relation to gimbal lock.
...you can encounter gimbal lock just as easily when using quaternions as when using matrices.
I've never used quaternions. My only experience is with matrices. I assume you would have one quaternion to hold a rotation and another one to hold a translation and you would multiply the two to get a third quaternion to use to transform a mesh in 3d space.
Quote: Original post by jykAre you saying quaternions keeps shear from creeping in on it's own because it's a possible byproduct of using matrices or is it just as you say, it can't be added so it can't be introduced by mistake.
Quaternions simply cannot represent shear...
Quote: Original post by jykI have no idea what you just said. I'm going to do some more research.
Traveling along geodesics on the manifold of rotations; when represented as quaternions this becomes SLERP, which is pretty easy.
Quote: Original post by jykditto
Along with #2... Calculating the geodesic distance between rotations is very easy with quaternions (a "dot product"); with matrices it involves an inverse and an eigendecomposition.
Unit quaternions only represent rotations. You can't represent a general 3d transformation, for example translations or shears, using unit them.
Quote: Original post by howie_007Nope, unit quaternions *only* represent rotation.
I assume you would have one quaternion to hold a rotation and another one to hold a translation and you would multiply the two to get a third quaternion to use to transform a mesh in 3d space.
In the past, I have stored transformations as a quaternion, vector pair (i.e. rotation, translation), and converted these to a single matrix when I need to pass this to the underlying graphics API.
This representation has a couple of advantages: quaternion + vector is less than half the storage space of a 4x4 matrix, and it is much cheaper to translate and rotate in isolation - although you then lose some of this advantage, as the conversion to matrix form is not free.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Quote: Original post by jykQuote: They work well because they dont have a problem with gimmbel lock...Just FYI, quaternions have no special properties with respect to gimbal lock (you can encounter gimbal lock just as easily when using quaternions as when using matrices).
Well thats true, they are better than storying yaw pitch roll though. Much less likely to hit it w/ quats and matrices
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement