diff --git a/glslUtil/glslUtil.c b/glslUtil/glslUtil.c index 74bc47d..c1ab190 100644 --- a/glslUtil/glslUtil.c +++ b/glslUtil/glslUtil.c @@ -35,3 +35,26 @@ void guMatrixTranslate(guMatrix4x4 *m, float x, float y, float z) m[i][3] += m[i][0] * x + m[i][1] * y + m[i][2] * z; } } + +void guMatrixFrustum(guMatrix4x4 *m, + float left, float right, + float bottom, float top, + float near, float far) +{ + guMatrix4x4 mult; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + mult[i][j] = 0.0; + } + } + mult[0][0] = 2 * near / (right - left); + mult[0][2] = (right + left) / (right - left); + mult[1][1] = 2 * near / (top - bottom); + mult[1][2] = (top + bottom) / (top - bottom); + mult[2][2] = - (far + near) / (far - near); + mult[2][3] = - 2 * far * near / (far - near); + mult[3][2] = -1.0; + guMatrixMult(m, &mult); +} diff --git a/glslUtil/glslUtil.h b/glslUtil/glslUtil.h index 3a29c7d..d976f16 100644 --- a/glslUtil/glslUtil.h +++ b/glslUtil/glslUtil.h @@ -17,6 +17,10 @@ extern "C" { void guMatrixLoadIdentity(guMatrix4x4 *m); void guMatrixMult(guMatrix4x4 *m, guMatrix4x4 *a, guMatrix4x4 *b); void guMatrixTranslate(guMatrix4x4 *m, float x, float y, float z); +void guMatrixFrustum(guMatrix4x4 *m, + float left, float right, + float bottom, float top, + float near, float far); #ifdef __cplusplus }