Transform
#行列 #回転 #CG #数学
Translate
code:latex
\bf T = \begin{bmatrix}
1 & 0 & 0 & t_x \\
0 & 1 & 0 & t_y \\
0 & 0 & 1 & t_z \\
0 & 0 & 0 & 1
\end{bmatrix}
Rotation
いろいろあるので省略
See: mat3FromQuaternion
See: eulerFromMat3の導出
$ \bf R
Scale
code:latex
\bf S = \begin{bmatrix}
s_x & 0 & 0 & 0 \\
0 & s_y & 0 & 0 \\
0 & 0 & s_z & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}
TRS
$ \bf M = \bf T \bf R \bf S
Compose
上のを掛け算しただけ
$ \bf Rはあらかじめmat3FromQuaternionなどで導出
code:latex
\bf M = \begin{bmatrix}
{\bf R}_{11} s_x & {\bf R}_{12} s_y & {\bf R}_{13} s_z & t_x \\
{\bf R}_{21} s_x & {\bf R}_{22} s_y & {\bf R}_{23} s_z & t_y \\
{\bf R}_{31} s_x & {\bf R}_{32} s_y & {\bf R}_{33} s_z & t_z \\
0 & 0 & 0 & 1
\end{bmatrix}
https://threejs.org/docs/#api/en/math/Matrix4.compose
http://docs.unity3d.com/ja/2023.2/ScriptReference/Matrix4x4.TRS.html
Decompose
上のComposeを見たら自明
code:latex
s = \begin{pmatrix}
\| ({\bf M}_{11}, {\bf M}_{21}, {\bf M}_{31}) \| \\
\| ({\bf M}_{12}, {\bf M}_{22}, {\bf M}_{32}) \| \\
\| ({\bf M}_{13}, {\bf M}_{23}, {\bf M}_{33}) \|
\end{pmatrix}
code:latex
{\bf R} = \begin{bmatrix}
\frac{{\bf M}_{11}}{s_x} & \frac{{\bf M}_{12}}{s_y} & \frac{{\bf M}_{13}}{s_z} \\
\frac{{\bf M}_{21}}{s_x} & \frac{{\bf M}_{22}}{s_y} & \frac{{\bf M}_{23}}{s_z} \\
\frac{{\bf M}_{31}}{s_x} & \frac{{\bf M}_{32}}{s_y} & \frac{{\bf M}_{33}}{s_z}
\end{bmatrix}
code:latex
t = \begin{pmatrix}
{\bf M}_{14} \\
{\bf M}_{24} \\
{\bf M}_{34}
\end{pmatrix}
https://threejs.org/docs/#api/en/math/Matrix4.decompose
GLSL・glm・glam等においては、行列がColumn-majorで定義されているため、4つ目のvec4のxyzを取れば簡単に$ tが取り出せる
code:glsl
matrix3.xyz
code:glsl
vec3 cameraPos = -viewMatrix3.xyz;
Normal Matrix
→ Normal Matrix