super cool video to see better:
https://www.youtube.com/watch?v=wiYTxjJjfxs&t=170s
As seen in past chapters, any object can be positioned in the space using nine parameters: three positions, three Euler angles, and three scaling factors.
Rotation matrices for objects can be computed in different ways, with the goal of simplifying parameter specification. The Euler Angles are three parameters that define the orientation of an object in a 3D space, and they are usually addressed as:
- Roll
- Pitch
- Yaw
After defined a facing axis (which can be for example where the object has its front view):
- roll: identifies the rotation of the object along its facing axis
- pitch: the elevation of the object and corresponds to a rotation around its y-axis
- yaw: y defines the direction of the object, and corresponds to a rotation along the z-axis (the vertical axis)
It's easy to remember these definitions thinking with an airplane. For different conventions, the axes must always be rotated in the roll, pitch, yaw order (RPW).
Euler angles have a known problem: they can lead to Gimbal Lock: a particular state where the roll and yaw become superposed and a degree of freedom is lost. In this situation some movements are no longer possible in a natural way, since to "unlock" the object has to make innatural rotations. For complex animations such as with arms/fingers or flight simulators, quaternions are necessary to avoid Gimbal Lock. Quaternions are an extension of complex numbers that have three imaginary components:
SUM
PRODUCT with scalare
PRODUCT between quaternions
NORM (length)
A unitary quaternion q has it norm
POWER
Rotations with quaternions
Let us consider a rotation of an angle
-
Two unitary quaternions,
$q1$ and$q2$ , represent different rotations and their product gives the composed transform. -
The quaternion product is non-commutative, and order matters to encode the correct rotation.
-
Quaternions can be directly converted to rotation transform matrices: $$ \begin{aligned} q & =a+i b+j c+k d \ R(q) & =\left|\begin{array}{cccc} 1-2 c^2-2 d^2 & 2 b c+2 a d & 2 b d-2 a c & 0 \ 2 b c-2 a d & 1-2 b^2-2 d^2 & 2 c d+2 a b & 0 \ 2 b d+2 a c & 2 c d-2 a b & 1-2 b^2-2 c^2 & 0 \ 0 & 0 & 0 & 1 \end{array}\right| \end{aligned} $$
-
Euler angles can be extracted from both rotation matrices and quaternions.
-
To avoid gimbal locks and compute the world matrix efficiently, we use quaternions to store orientation in complex rotation scenarios. This quaternion is then converted into a rotation matrix, which is multiplied by both the translation and scaling components of the world matrix.
-
3D applications always performs the rotations using quaternion operations: all relative changes in the direction of an object are encoded with a quaternion
$\Delta q$ that expresses the direction and the entity of the rotation. {width=50%} -
Global rotation has axes oriented with global axis
-
Local rotation has axes following current object rotation
If quaternion
-
$q=\Delta q \cdot q$ : performed in world space -
$q = q \cdot \Delta q$ : performed in local space
INSERIRE CODICE GLM QUATERNIONS QUA