X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2Fshapes%2Fglmatrix.c;h=485e324d8a2f4841b0a90762676063e28fee7a93;hb=8e61d8288d0da4bb834cf6de33ac24320321693f;hp=961bf7c9668f8c791104ba2716afae6077601a4d;hpb=8c9773ab36947fcaad5826eb9962d203d914c86d;p=freeglut diff --git a/progs/demos/shapes/glmatrix.c b/progs/demos/shapes/glmatrix.c index 961bf7c..485e324 100644 --- a/progs/demos/shapes/glmatrix.c +++ b/progs/demos/shapes/glmatrix.c @@ -3,6 +3,10 @@ #include #include "glmatrix.h" +#ifndef M_PI +#define M_PI 3.141592653589793 +#endif + #define MMODE_IDX(x) ((x) - GL_MODELVIEW) #define MAT_STACK_SIZE 32 #define MAT_IDENT {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1} @@ -114,17 +118,17 @@ void gl_scalef(float x, float y, float z) gl_mult_matrixf(mat); } -void gl_ortho(float left, float right, float bottom, float top, float near, float far) +void gl_ortho(float left, float right, float bottom, float top, float znear, float zfar) { float mat[] = MAT_IDENT; float dx = right - left; float dy = top - bottom; - float dz = far - near; + float dz = zfar - znear; float tx = -(right + left) / dx; float ty = -(top + bottom) / dy; - float tz = -(far + near) / dz; + float tz = -(zfar + znear) / dz; float sx = 2.f / dx; float sy = 2.f / dy; @@ -140,35 +144,36 @@ void gl_ortho(float left, float right, float bottom, float top, float near, floa gl_mult_matrixf(mat); } -void gl_frustum(float left, float right, float bottom, float top, float near, float far) +void gl_frustum(float left, float right, float bottom, float top, float znear, float zfar) { float mat[] = MAT_IDENT; float dx = right - left; float dy = top - bottom; - float dz = far - near; + float dz = zfar - znear; float a = (right + left) / dx; float b = (top + bottom) / dy; - float c = -(far + near) / dz; - float d = -2.f * far * near / dz; + float c = -(zfar + znear) / dz; + float d = -2.f * zfar * znear / dz; - mat[0] = 2.f * near / dx; - mat[5] = 2.f * near / dy; + mat[0] = 2.f * znear / dx; + mat[5] = 2.f * znear / dy; mat[8] = a; mat[9] = b; mat[10] = c; mat[11] = -1.f; mat[14] = d; + mat[15] = 0; gl_mult_matrixf(mat); } -void glu_perspective(float vfov, float aspect, float near, float far) +void glu_perspective(float vfov, float aspect, float znear, float zfar) { float vfov_rad = (float)M_PI * vfov / 180.f; - float x = near * (float)tan(vfov_rad / 2.f); - gl_frustum(-aspect * x, aspect * x, -x, x, near, far); + float x = znear * (float)tan(vfov_rad / 2.f); + gl_frustum(-aspect * x, aspect * x, -x, x, znear, zfar); } /* return the matrix (16 elements, 4x4 matrix, row-major order */