From fe82c60f5ec2b6f3e5483432d912a42aa4515b15 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Fri, 6 Jan 2012 00:49:59 +0100 Subject: linmath.h -- added code for ortho projection matrix, fixed some copynpaste typos in frustum --- linmath.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/linmath.h b/linmath.h index 9220940..e7d308f 100644 --- a/linmath.h +++ b/linmath.h @@ -262,22 +262,35 @@ static inline void mat4x4_invert(mat4x4 R, mat4x4 const M) } static inline void mat4x4_frustum(mat4x4 M, float l, float r, float b, float t, float n, float f) { - M[0][0] = 2*n/(r-l); + M[0][0] = 2.*n/(r-l); M[0][1] = M[0][2] = M[0][3] = 0.; - M[1][1] = 2*n/(t-b); - M[1][0] = M[0][2] = M[0][3] = 0.; + M[1][1] = 2.*n/(t-b); + M[1][0] = M[1][2] = M[1][3] = 0.; M[2][0] = (r+l)/(r-l); M[2][1] = (t+b)/(t-b); M[2][2] = -(f+n)/(f-n); M[2][3] = -1; - M[3][2] = -2*f*n/(f-n); - M[3][0] = M[0][1] = M[0][3] = 0.; + M[3][2] = -2.*f*n/(f-n); + M[3][0] = M[3][1] = M[3][3] = 0.; } static inline void mat4x4_ortho(mat4x4 M, float l, float r, float b, float t, float n, float f) { + M[0][0] = 2./(r-l); + M[0][1] = M[0][2] = M[0][3] = 0.; + + M[1][1] = 2./(t-b); + M[1][0] = M[1][2] = M[1][3] = 0.; + + M[2][2] = -2./(f-n); + M[2][0] = M[2][1] = M[0][3] = 0.; + + M[3][0] = (r+l)/(r-l); + M[3][1] = (t+b)/(t-b); + M[3][2] = (f+n)/(f-n); + M[3][3] = 1.; } typedef float quat[4]; -- cgit v1.2.3