moved static variables and functions that should not have stuck behind in fg_joystick...
[freeglut] / progs / demos / shapes / glmatrix.c
index 961bf7c..485e324 100644 (file)
@@ -3,6 +3,10 @@
 #include <math.h>\r
 #include "glmatrix.h"\r
 \r
+#ifndef M_PI\r
+#define M_PI   3.141592653589793\r
+#endif\r
+\r
 #define MMODE_IDX(x)   ((x) - GL_MODELVIEW)\r
 #define MAT_STACK_SIZE 32\r
 #define MAT_IDENT      {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}\r
@@ -114,17 +118,17 @@ void gl_scalef(float x, float y, float z)
     gl_mult_matrixf(mat);\r
 }\r
 \r
-void gl_ortho(float left, float right, float bottom, float top, float near, float far)\r
+void gl_ortho(float left, float right, float bottom, float top, float znear, float zfar)\r
 {\r
     float mat[] = MAT_IDENT;\r
 \r
     float dx = right - left;\r
     float dy = top - bottom;\r
-    float dz = far - near;\r
+    float dz = zfar - znear;\r
 \r
     float tx = -(right + left) / dx;\r
     float ty = -(top + bottom) / dy;\r
-    float tz = -(far + near) / dz;\r
+    float tz = -(zfar + znear) / dz;\r
 \r
     float sx = 2.f / dx;\r
     float sy = 2.f / dy;\r
@@ -140,35 +144,36 @@ void gl_ortho(float left, float right, float bottom, float top, float near, floa
     gl_mult_matrixf(mat);\r
 }\r
 \r
-void gl_frustum(float left, float right, float bottom, float top, float near, float far)\r
+void gl_frustum(float left, float right, float bottom, float top, float znear, float zfar)\r
 {\r
     float mat[] = MAT_IDENT;\r
 \r
     float dx = right - left;\r
     float dy = top - bottom;\r
-    float dz = far - near;\r
+    float dz = zfar - znear;\r
 \r
     float a = (right + left) / dx;\r
     float b = (top + bottom) / dy;\r
-    float c = -(far + near) / dz;\r
-    float d = -2.f * far * near / dz;\r
+    float c = -(zfar + znear) / dz;\r
+    float d = -2.f * zfar * znear / dz;\r
 \r
-    mat[0] = 2.f * near / dx;\r
-    mat[5] = 2.f * near / dy;\r
+    mat[0] = 2.f * znear / dx;\r
+    mat[5] = 2.f * znear / dy;\r
     mat[8] = a;\r
     mat[9] = b;\r
     mat[10] = c;\r
     mat[11] = -1.f;\r
     mat[14] = d;\r
+    mat[15] = 0;\r
 \r
     gl_mult_matrixf(mat);\r
 }\r
 \r
-void glu_perspective(float vfov, float aspect, float near, float far)\r
+void glu_perspective(float vfov, float aspect, float znear, float zfar)\r
 {\r
     float vfov_rad = (float)M_PI * vfov / 180.f;\r
-    float x = near * (float)tan(vfov_rad / 2.f);\r
-    gl_frustum(-aspect * x, aspect * x, -x, x, near, far);\r
+    float x = znear * (float)tan(vfov_rad / 2.f);\r
+    gl_frustum(-aspect * x, aspect * x, -x, x, znear, zfar);\r
 }\r
 \r
 /* return the matrix (16 elements, 4x4 matrix, row-major order */\r