gluPerspective ============== .. note:: 列ベクトル方式で説明 OpenGLの透視投影の指定は http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml (glFrustum)で行う。 :: glFrustum(left, right, bottom, top, near, far) もうひとつこれの簡易版として http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml (gluPersepective)があって :: gluPerspective(fovy, aspect, near, far) となっている。 fovyは「Field Of View in the Y direction.」くらいの意味。Field of viewは視野角なので縦方向の視野角を意味する。単位は度。 glFrustumの行列は、 .. math:: \left( \begin{array}{cccc} \frac{2 \cdot near}{right - left} & 0 & A & 0 \\ 0 & \frac{2 \cdot near}{top - bottom} & B & 0 \\ 0 & 0 & C & D \\ 0 & 0 & -1 & 0 \end{array} \right) \\ .. math:: A = \frac{right + left}{right - left} .. math:: B = \frac{top + bottom}{top - bottom} .. math:: C = - \frac{far + near}{far - near} .. math:: D = - \frac{2 \cdot far \cdot near}{far - near} のように定義される。 このうちAとBはgluPersepectiveでは常に0になる。 左右対称(left+right=0)かつ上下対称(top+bottom=0)だからです。 これを代入すると .. math:: \left( \begin{array}{cccc} \frac{2 \cdot near}{right - left} & 0 & 0 & 0 \\ 0 & \frac{2 \cdot near}{top - bottom} & 0 & 0 \\ 0 & 0 & - \frac{far + near}{far - near} & - \frac{2 \cdot far \cdot near}{far - near} \\ 0 & 0 & -1 & 0 \end{array} \right) となる。 一方、gluPersepectiveの行列は、 .. math:: \left( \begin{array}{cccc} \frac{f}{aspect} & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & \frac{far + near}{near - far} & \frac{2 \cdot far \cdot near}{near - far} \\ 0 & 0 & -1 & 0 \end{array} \right) \\ f = \cot \left( \frac{fovy}{2} \right) と定義される。 gluPersepectiveのfに対応するglFrustumの .. math:: \frac{2 \cdot near}{top - bottom} \\ \frac{near}{ height/2 } = \frac{\cos}{\sin} とするとcotangentの定義そのまま。 もう1つのf/aspectの方もそういうことで2式は等価になった。 gluPersepectiveはglFrustumの上下対称左右対称限定版で、 引数の取り方をちょっと変更したものと言える。 参考 ^^^^ 三角関数 http://ja.wikipedia.org/wiki/%E4%B8%89%E8%A7%92%E9%96%A2%E6%95%B0