From e05c62725c8c36f017064cf391d4b7bdb2b28785 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 9 May 2011 17:05:23 -0400 Subject: [PATCH] add guPerspective() --- glslUtil/glslUtil.c | 21 +++++++++++++++++++++ glslUtil/glslUtil.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/glslUtil/glslUtil.c b/glslUtil/glslUtil.c index f681c15..6c3757a 100644 --- a/glslUtil/glslUtil.c +++ b/glslUtil/glslUtil.c @@ -117,3 +117,24 @@ void guMatrixFrustum(guMatrix4x4 *m, mult[3][2] = -1.0; 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); +} diff --git a/glslUtil/glslUtil.h b/glslUtil/glslUtil.h index ec03737..ffc4a4f 100644 --- a/glslUtil/glslUtil.h +++ b/glslUtil/glslUtil.h @@ -24,6 +24,8 @@ void guMatrixFrustum(guMatrix4x4 *m, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); +void guPerspective(guMatrix4x4 *m, GLfloat fovy, GLfloat aspect, + GLfloat near, GLfloat far); #ifdef __cplusplus }