summary refs log tree commit diff stats
path: root/libs/cocos2d/Platforms/iOS/glu.c
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/Platforms/iOS/glu.c
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/Platforms/iOS/glu.c')
-rwxr-xr-xlibs/cocos2d/Platforms/iOS/glu.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/libs/cocos2d/Platforms/iOS/glu.c b/libs/cocos2d/Platforms/iOS/glu.c new file mode 100755 index 0000000..2e00d5f --- /dev/null +++ b/libs/cocos2d/Platforms/iOS/glu.c
@@ -0,0 +1,113 @@
1//
2// cocos2d (incomplete) GLU implementation
3//
4// gluLookAt and gluPerspective from:
5// http://jet.ro/creations (San Angeles Observation)
6//
7//
8
9// Only compile this code on iOS. These files should NOT be included on your Mac project.
10// But in case they are included, it won't be compiled.
11#import <Availability.h>
12#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
13
14#import <OpenGLES/ES1/gl.h>
15#import <math.h>
16#import "../../Support/OpenGL_Internal.h"
17#include "glu.h"
18
19void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
20{
21 GLfloat xmin, xmax, ymin, ymax;
22
23 ymax = zNear * (GLfloat)tanf(fovy * (float)M_PI / 360);
24 ymin = -ymax;
25 xmin = ymin * aspect;
26 xmax = ymax * aspect;
27
28 glFrustumf(xmin, xmax,
29 ymin, ymax,
30 zNear, zFar);
31}
32
33void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
34 GLfloat centerx, GLfloat centery, GLfloat centerz,
35 GLfloat upx, GLfloat upy, GLfloat upz)
36{
37 GLfloat m[16];
38 GLfloat x[3], y[3], z[3];
39 GLfloat mag;
40
41 /* Make rotation matrix */
42
43 /* Z vector */
44 z[0] = eyex - centerx;
45 z[1] = eyey - centery;
46 z[2] = eyez - centerz;
47 mag = (float)sqrtf(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
48 if (mag) {
49 z[0] /= mag;
50 z[1] /= mag;
51 z[2] /= mag;
52 }
53
54 /* Y vector */
55 y[0] = upx;
56 y[1] = upy;
57 y[2] = upz;
58
59 /* X vector = Y cross Z */
60 x[0] = y[1] * z[2] - y[2] * z[1];
61 x[1] = -y[0] * z[2] + y[2] * z[0];
62 x[2] = y[0] * z[1] - y[1] * z[0];
63
64 /* Recompute Y = Z cross X */
65 y[0] = z[1] * x[2] - z[2] * x[1];
66 y[1] = -z[0] * x[2] + z[2] * x[0];
67 y[2] = z[0] * x[1] - z[1] * x[0];
68
69 /* cross product gives area of parallelogram, which is < 1.0 for
70 * non-perpendicular unit-length vectors; so normalize x, y here
71 */
72
73 mag = (float)sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
74 if (mag) {
75 x[0] /= mag;
76 x[1] /= mag;
77 x[2] /= mag;
78 }
79
80 mag = (float)sqrtf(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
81 if (mag) {
82 y[0] /= mag;
83 y[1] /= mag;
84 y[2] /= mag;
85 }
86
87#define M(row,col) m[col*4+row]
88 M(0, 0) = x[0];
89 M(0, 1) = x[1];
90 M(0, 2) = x[2];
91 M(0, 3) = 0.0f;
92 M(1, 0) = y[0];
93 M(1, 1) = y[1];
94 M(1, 2) = y[2];
95 M(1, 3) = 0.0f;
96 M(2, 0) = z[0];
97 M(2, 1) = z[1];
98 M(2, 2) = z[2];
99 M(2, 3) = 0.0f;
100 M(3, 0) = 0.0f;
101 M(3, 1) = 0.0f;
102 M(3, 2) = 0.0f;
103 M(3, 3) = 1.0f;
104#undef M
105
106 glMultMatrixf(m);
107
108
109 /* Translate Eye to Origin */
110 glTranslatef(-eyex, -eyey, -eyez);
111}
112
113#endif // __IPHONE_OS_VERSION_MAX_ALLOWED