Why do game programmers use quaternions to rotate a vector?

Started by
33 comments, last by dawidjoubert 18 years ago
[Edited by - Kambiz on March 29, 2006 8:36:21 AM]
Advertisement
Do game programers do so? Yes, but very seldom. In fact the matrix vector product is much better suited to rotate a vector.

However, quaternions are good for operations occuring _before_ rotating a vector, namely in intra-/extrapolating rotations, in concatenating rotations, and a bit also in storing rotations (if the memory footprint plays a remarkable role).

But, hey, formula 4) seems me a look worth ;) That is an axis/angle pair rotation, right?
Because sometimes, rotating a vector is not the goal, it's part of the process you must follow, in order to achieve the goal.

And quaternions -sometimes- make it easier to achieve some goals, than just rotate a vector.
Quote:Original post by haegarr
But, hey, formula 4) seems me a look worth ;) That is an axis/angle pair rotation, right?

Yes

Quaternion rotations are easy to combine, that is a good reason to use them, but I think many programmers use quaternions just because they do not know formula 4 or think that quaternions are cool!

Quote:Original post by someusername
And quaternions -sometimes- make it easier to achieve some goals, than just rotate a vector.


Give me an example.

Orientation interpolation at constant angular speed
I saw an engine once that serialized rotations as a quaternion using 3 8-bit values. It used w = 1-sqrt(x^2+y^2+z^2) (or something like that) when it loaded them from disk, then converted that to a 3x3 matrix. So basically it compressed the 3x3 matrix down to 24-bits.

Not sure I'd do that, but it seemed to work okay.

Quote:Original post by someusername
Orientation interpolation at constant angular speed


Why do you need a quaternion? In classical mechanics people use just a vector and it works well.

Quote:Original post by Anonymous Poster
I saw an engine once that serialized rotations as a quaternion using 3 8-bit values. It used w = 1-sqrt(x^2+y^2+z^2)...
Not sure I'd do that, but it seemed to work okay.


The same way you can use a vector to represent the rotation... as you see you just need 3 values x,y,z and w is useless.

You're talking about the angular velocity vector which describes the instantaneous rate of change of an object's axes.
I'm talking about arbitrarily setting the object's axes to any two orientations, and interpolating smoothly from one to the other.

If you just want to rotate a vector, there must be a million ways. You could even change to spherical coordinates, offset the angles and reproject to cartesian.
Have you seen anyone using that? It's all a matter of what you want to achieve in the first place.

And I said "quaternions sometimes make it easier", not that they can do something when there is no other way.
Anyway, I don't feel like arguing about this. Anyone who has ever used them can decide for themselves whether they are worth the fuss.

This topic is closed to new replies.

Advertisement