gltf深入浅出——cameras
导言
gltf中的摄像机也是分为两种,一种是正交摄像机,一种是透视摄像机。
案例
{
"cameras": [
{
"name": "Finite perspective camera",
"type": "perspective",
"perspective": {
"aspectRatio": 1.5,
"yfov": 0.660593,
"zfar": 100,
"znear": 0.01
}
},
{
"name": "Infinite perspective camera",
"type": "perspective",
"perspective": {
"aspectRatio": 1.5,
"yfov": 0.660593,
"znear": 0.01
}
},
{
"name": "Orthographic camera",
"type": "orthographic",
"perspective": {
"xmag": 1.0,
"ymag": 1.0,
"znear": 0.01,
"zfar": 100.0,
}
}
]
}
上述一共有三种摄像机,分别为有限视野的透视摄像机、无限视野的透视摄像机、正交摄像机。这其中只有一个属性是必要的就是摄像机的类型(type
)。下面分别介绍这三种摄像机的投影矩阵如下:
R = { 1 a ∗ t a n ( 0.5 ∗ y ) 0 0 0 0 1 t a n ( 0.5 ∗ y ) 0 0 0 0 − 1 − 2 n 0 0 − 1 0 } R=\begin{Bmatrix} \frac{1}{a*tan(0.5*y)} & 0 & 0 & 0\\ 0 & \frac{1}{tan(0.5*y)} & 0 & 0\\ 0 & 0 & -1 & -2n\\ 0 & 0 & -1 & 0\\ \end{Bmatrix} R=⎩⎪⎪⎨⎪⎪⎧