Skip to content

Latest commit

 

History

History
127 lines (86 loc) · 4.55 KB

File metadata and controls

127 lines (86 loc) · 4.55 KB

World Matrix

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.

$$ M_W=T\left(p_x, p_y, p_z\right) \times R_y(\psi) \times R_x(\theta) \times R_z(\varphi) \times S\left(s_x, S_y, S_z\right) $$

Euler angles

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)

{width=50%}

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).

Quaternions

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:

$$ a+i b+j c+k d $$

$$ i^2=j^2=k^2=i j k=-1 $$

SUM

$$ \left(a_1+i b_1+j c_1+k d_1\right)+\left(a_2+i b_2+j c_2+k d_2\right)=\left(a_1+a_2\right)+i\left(b_1+b_2\right)+j\left(c_1+c_2\right)+k\left(d_1+d_2\right) $$

PRODUCT with scalare

$$ \alpha(a+i b+j c+k d)=\alpha a+i \times \alpha b+j \times \alpha c+k \times \alpha d $$

PRODUCT between quaternions

$$ \begin{aligned} \left(a_1+i b_1+j c_1+k d_1\right)\left(a_2+i b_2+j c_2+k d_2\right)= & \left(a_1 a_2-b_1 b_2-c_1 c_2-d_1 d_2\right)+ \\ & i\left(a_1 b_2+b_1 a_2+c_1 d_2-d_1 c_2\right)+ \\ & j\left(a_1 c_2+c_1 a_2+d_1 b_2-b_1 d_2\right)+ \\ & k\left(a_1 d_2+d_1 a_2+b_1 c_2-c_1 b_2\right) \end{aligned} $$

NORM (length)

$$ |a+i b+j c+k d|=\sqrt{a^2+b^2+c^2+d^2} $$

A unitary quaternion q has it norm $q = 1$ Unitary quaternions can be used to encode 3D rotations

POWER

$$ (a+i b+j c+k d)^\alpha=|a+i b+j c+k d|^\alpha\left(\cos (\alpha \theta)+\frac{i b+j c+k d}{\sqrt{b^2+c^2+d^2}} \sin (\alpha \theta)\right) $$

Rotations with quaternions

Let us consider a rotation of an angle $\theta$ around an axis oriented along a unitary vector $v = (x,y,z).$ This rotation can be represented by the following quaternion:

$$ q=\cos \frac{\theta}{2}+\sin \frac{\theta}{2}(i x+j y+k z) $$

  • 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 $\Delta q$ rapresents the rotation and $q$ is the vector which rapresents the current facing direction of the object:

  • $q=\Delta q \cdot q$ : performed in world space
  • $q = q \cdot \Delta q$ : performed in local space

INSERIRE CODICE GLM QUATERNIONS QUA