add guPerspective()

This commit is contained in:
Josh Holtrop 2011-05-09 17:05:23 -04:00
parent 2d7bafe23b
commit e05c62725c
2 changed files with 23 additions and 0 deletions

View File

@ -117,3 +117,24 @@ void guMatrixFrustum(guMatrix4x4 *m,
mult[3][2] = -1.0; mult[3][2] = -1.0;
guMatrixMult(m, m, &mult); guMatrixMult(m, m, &mult);
} }
void guPerspective(guMatrix4x4 *m, GLfloat fovy, GLfloat aspect,
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 f = 1.0 / tan(fovy / 2.0);
mult[0][0] = f / aspect;
mult[1][1] = f;
mult[2][2] = (far + near) / (near - far);
mult[2][3] = (2 * far * near) / (near - far);
mult[3][2] = -1.0;
guMatrixMult(m, m, &mult);
}

View File

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