
[ad_1]
Applying the rotation {that a} quaternion represents is completed by way of multiplication. This is admittedly neat, as a result of it really works on vectors, like so:
v2 = q * v1
but in addition on different quaternions:
q2 = q * q1
…which implies that combining rotations is kind of simple. The draw back is that, in comparison with euler angles, it’s kind of harder to instantly translate between your instinct of what a rotation is like and its quaternion illustration (though I discover that quaternion rotations appear far much less arcane if you concentrate on angle-axis rotations, since there’s a very easy conversion between the 2).
For your case, since you understand the Euler illustration of the rotation you need, you may need to simply convert that on to a quaternion and multiply it by the present rotation each body (be aware that the order issues, quaternion multiplication just isn’t commutative).
I’m undecided if glm has a built-in conversion between the 2 fashions, however the reply I linked earlier than has a number of examples of methods to implement one for those who want it. So, after you have the eulerToQuaternion
perform, you are able to do one thing like this:
Quaternion q = eulerToQuaternion(0.01, 0, 0);
void GameLoop::replace(){
pawn.rotation = q * pawn.rotation;
}
Also, as as to if it is a good suggestion to make use of quaternions or not, it form of depends upon what precisely you’re doing, however I feel the overall consensus is that sure, they’re essentially the most handy strategy to work with rotations. The wikipedia web page on the topic says:
Compared to rotation matrices, quaternions are extra compact, environment friendly, and numerically secure. Compared to Euler angles, they’re easier to compose. However, they aren’t as intuitive and simple to grasp and, because of the periodic nature of sine and cosine, rotation angles differing exactly by the pure interval will probably be encoded into similar quaternions and recovered angles in radians will probably be restricted to [ 0 , 2 π ].
Which sums it up fairly properly, I feel.
[ad_2]