From cf31a302f2dfdd422a0017485cdf562f063961d5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 9 May 2011 17:11:07 -0400 Subject: [PATCH] add guOrtho() --- glslUtil/glslUtil.c | 26 ++++++++++++++++++++++++++ glslUtil/glslUtil.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/glslUtil/glslUtil.c b/glslUtil/glslUtil.c index 9341264..1a586f1 100644 --- a/glslUtil/glslUtil.c +++ b/glslUtil/glslUtil.c @@ -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; +} diff --git a/glslUtil/glslUtil.h b/glslUtil/glslUtil.h index ffc4a4f..040c977 100644 --- a/glslUtil/glslUtil.h +++ b/glslUtil/glslUtil.h @@ -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 }