Graphics Conversion Matrix

List of pages tagged with matrix:

application of matrix calculation

web2.0calconline matrix calculator

the order of multiply

the more left part is more close to the vertices.

(1)
\begin{equation} v'=v*V*M*P \end{equation}

V=View matrix(translation of z axis)
M=Model Matrix(glLookAt)
P=Projection matrix

code

const char gSimpleVertexShader[] = 
    "attribute vec4 Position;      \n"
    "uniform mat4 Projection;      \n"
    "uniform mat4 Modelview;       \n"
    "void main() {\n"
        "   gl_Position = Projection * Modelview * Position; \n"
    "}\n";

Viewport Conversion

Projection Conversion

glFrustum(l,r,b,t,n,f)

(2)
\begin{align} \left[ \begin{array}{cc} \frac{2n}{r-l} & 0 & \frac{r+l}{r-l} & 0 \\ 0 & \frac{2n}{t-b} & \frac{t+b}{t-b} & 0 \\ 0 & 0 & \frac{-(f+n)}{f-n} & \frac{-2fn}{f-n} \\ 0 & 0 & -1 & 0\\ \end{array} \right] \end{align}

gluPerspective

(3)
\begin{align} \left[ \begin{array}{cc} \frac{\alpha}{aspect} & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & \frac{f+n}{n-f} & \frac{2fn}{n-f} \\ 0 & 0 & -1 & 0\\ \end{array} \right] \alpha=cot(fovy/2) cot=\frac{1}{tan(\frac{fovy}{2})} \end{align}

ModelView Conversion

Translation

glTranslatef(x,y,z);

(4)
\begin{align} \left[ \begin{array}{cc} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

Scaling

glScalef(x,y,z)

(5)
\begin{align} \left[ \begin{array}{cc} x & 0 & 0 & 0 \\ 0 & y & 0 & 0 \\ 0 & 0 & z & 0 \\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

Rotation

glRotatef(a,1,0,0);

(6)
\begin{align} \left[ \begin{array}{cc} 1 & 0 & 0 & 0 \\ 0 & cosa & -sina & 0 \\ 0 & sina & cosa & 0 \\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

glRotatef(a,0,1,0);

(7)
\begin{align} \left[ \begin{array}{cc} cosa & 0 & sina & 0 \\ 0 & 1 & 0 & 0 \\ -sina & 0 & cosa & 0 \\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

glRotatef(a,0,0,1);

(8)
\begin{align} \left[ \begin{array}{cc} cosa & -sina & 0 & 0 \\ sina & cosa & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

en.gif en
ja.gif ja


edit
サポートサイト Wikidot.com