add guOrtho()

This commit is contained in:
Josh Holtrop 2011-05-09 17:11:07 -04:00
parent e06395ff5d
commit cf31a302f2
2 changed files with 30 additions and 0 deletions

View File

@ -142,3 +142,29 @@ void guPerspective(guMatrix4x4 *m, GLfloat fovy, GLfloat aspect,
mult[3][2] = -1.0;
guMatrixMult(m, m, &mult);
}
void guOrtho(guMatrix4x4 *m,
GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat near, GLfloat far)
{
int i, j;
guMatrix4x4 mult;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
mult[i][j] = 0.0;
}
}
GLfloat rl = right - left;
GLfloat tb = top - bottom;
GLfloat fn = far - near;
mult[0][0] = 2 / rl;
mult[0][3] = - (right + left) / rl;
mult[1][1] = 2 / tb;
mult[1][3] = - (top + bottom) / tb;
mult[2][2] = -2 / fn;
mult[2][3] = - (far + near) / fn;
mult[3][3] = 1.0;
}

View File

@ -26,6 +26,10 @@ void guMatrixFrustum(guMatrix4x4 *m,
GLfloat near, GLfloat far);
void guPerspective(guMatrix4x4 *m, GLfloat fovy, GLfloat aspect,
GLfloat near, GLfloat far);
void guOrtho(guMatrix4x4 *m,
GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat near, GLfloat far);
#ifdef __cplusplus
}