缩放
[ S x 0 0 0 0 S y 0 0 0 0 S z 0 0 0 0 1 ] \left[ \begin{matrix} Sx& 0 & 0 & 0 \\ 0 & Sy & 0 & 0 \\ 0 & 0 & Sz & 0 \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] ⎣⎢⎢⎡Sx0000Sy0000Sz00001⎦⎥⎥⎤
旋转
绕x轴逆时针旋转
θ
\theta
θ
[
1
0
0
0
0
cos
θ
−
sin
θ
0
0
sin
θ
cos
θ
0
0
0
0
1
]
\left[ \begin{matrix} 1& 0 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta & 0 \\ 0 & \sin\theta & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
⎣⎢⎢⎡10000cosθsinθ00−sinθcosθ00001⎦⎥⎥⎤
绕y轴逆时针旋转
θ
\theta
θ
[
cos
θ
0
sin
θ
0
0
1
0
0
−
sin
θ
0
cos
θ
0
0
0
0
1
]
\left[ \begin{matrix} \cos\theta& 0 & \sin\theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin\theta&0 & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
⎣⎢⎢⎡cosθ0−sinθ00100sinθ0cosθ00001⎦⎥⎥⎤
绕z轴逆时针旋转
θ
\theta
θ
[
cos
θ
−
sin
θ
0
0
sin
θ
cos
θ
0
0
0
0
1
0
0
0
0
1
]
\left[ \begin{matrix} \cos\theta& -\sin\theta & 0 & 0 \\ \sin\theta& \cos\theta & 0 & 0 \\ 0 &0 &1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
⎣⎢⎢⎡cosθsinθ00−sinθcosθ0000100001⎦⎥⎥⎤
平移
[ 1 0 0 T x 0 1 0 T y 0 0 1 T z 0 0 0 1 ] \left[ \begin{matrix} 1&0 & 0 & Tx \\ 0& 1 & 0 & Ty \\ 0 &0 &1 & Tz \\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] ⎣⎢⎢⎡100001000010TxTyTz1⎦⎥⎥⎤
正交投影
r l :左右平面
t b:上下平面
n f:近远平面
M
o
r
t
h
o
=
[
2
r
−
l
0
0
0
0
2
t
−
b
0
0
0
0
2
n
−
f
0
0
0
0
1
]
[
1
0
0
−
r
+
l
2
0
1
0
−
t
+
b
2
0
0
1
−
n
+
f
2
0
0
0
1
]
Mortho = \left[ \begin{matrix} \frac{2}{r-l}&0 & 0 & 0\\ 0&\frac{2}{t-b} & 0 & 0\\ 0 &0 &\frac{2}{n-f} & 0\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] \left[ \begin{matrix} 1&0 & 0 & -\frac{r+l}{2} \\ 0& 1 & 0 & -\frac{t+b}{2} \\ 0 &0 &1 & -\frac{n+f}{2}\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
Mortho=⎣⎢⎢⎡r−l20000t−b20000n−f200001⎦⎥⎥⎤⎣⎢⎢⎡100001000010−2r+l−2t+b−2n+f1⎦⎥⎥⎤
透视投影
M p e r s p = [ n 0 0 0 0 n 0 0 0 0 n + f − n f 0 0 0 1 ] ∗ M o r t h o Mpersp = \left[ \begin{matrix} n&0 & 0 & 0\\ 0&n & 0 & 0\\ 0 &0 &n+f & -nf\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] *Mortho Mpersp=⎣⎢⎢⎡n0000n0000n+f000−nf1⎦⎥⎥⎤∗Mortho
从Model矩阵中分解出平移、旋转、缩放矩阵
M = [ m 00 m 10 m 20 m 30 m 01 m 11 m 21 m 31 m 02 m 12 m 22 m 32 0 0 0 1 ] M = \left[ \begin{matrix} m00&m10 & m20 & m30\\ m01&m11 & m21 & m31\\ m02 &m12 &m22 & m32\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right] M=⎣⎢⎢⎡m00m01m020m10m11m120m20m21m220m30m31m321⎦⎥⎥⎤
平移:
T
=
[
1
0
0
m
30
0
1
0
m
31
0
0
1
m
32
0
0
0
1
]
T = \left[ \begin{matrix} 1&0 & 0 & m30\\ 0&1 & 0 & m31\\ 0 &0 &1 & m32\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
T=⎣⎢⎢⎡100001000010m30m31m321⎦⎥⎥⎤
旋转:l0 l1 l2分别为列向量长度
R
=
[
m
00
l
0
m
10
l
1
m
20
l
2
0
m
01
l
0
m
11
l
1
m
21
l
2
0
m
02
l
0
m
12
l
1
m
22
l
2
0
0
0
0
1
]
R = \left[ \begin{matrix} \frac{m00}{l0}&\frac{m10}{l1} & \frac{m20}{l2} & 0\\ \frac{m01}{l0}&\frac{m11}{l1} &\frac{m21}{l2} & 0\\ \frac{m02}{l0}&\frac{m12}{l1} &\frac{m22}{l2} & 0\\ 0& 0 & 0 & 1 \\ \end{matrix} \right]
R=⎣⎢⎢⎡l0m00l0m01l0m020l1m10l1m11l1m120l2m20l2m21l2m2200001⎦⎥⎥⎤
缩放:
S
=
[
l
0
0
0
0
0
l
1
0
0
0
0
l
2
0
0
0
0
1
]
S = \left[ \begin{matrix} l0&0 & 0 & 0\\ 0&l1 & 0 & 0\\ 0 &0 &l2 & 0\\ 0 & 0 & 0 & 1 \\ \end{matrix} \right]
S=⎣⎢⎢⎡l00000l10000l200001⎦⎥⎥⎤
先缩放、再旋转、再平移