1 #ifndef GLUREPLACE_H
2 #define GLUREPLACE_H
3 #include <QGLWidget>
4 #include <math.h>
5 ///////////////replaceing glu.h
6 ///
gluLookAt_(GLfloat eyex,GLfloat eyey,GLfloat eyez,GLfloat centerx,GLfloat centery,GLfloat centerz,GLfloat upx,GLfloat upy,GLfloat upz)7 inline void gluLookAt_(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
8 GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
9 GLfloat upz){
10 float forward[3], side[3], up[3];
11 GLfloat m[4][4];
12 forward[0] = centerx - eyex;
13 forward[1] = centery - eyey;
14 forward[2] = centerz - eyez;
15 up[0] = upx;
16 up[1] = upy;
17 up[2] = upz;
18 float nrm=sqrt(forward[0]*forward[0]+forward[1]*forward[1]+forward[2]*forward[2]);
19 forward[0]/=nrm;
20 forward[1]/=nrm;
21 forward[2]/=nrm;
22 //normalize(forward);
23 /* Side = forward x up */
24
25 side[0] = forward[1]*up[2] - up[1]*forward[2];
26 side[1] = forward[2]*up[0] - up[2]*forward[0];
27 side[2] = forward[0]*up[1] - up[0]*forward[1];
28 //cross(forward, up, side);
29 nrm=sqrt(side[0]*side[0]+side[1]*side[1]+side[2]*side[2]);
30 side[0]/=nrm;
31 side[1]/=nrm;
32 side[2]/=nrm;
33 //normalize(side);
34 /* Recompute up as: up = side x forward */
35 up[1] = side[2]*forward[0] - forward[2]*side[0];
36 up[2] = side[0]*forward[1] - forward[0]*side[1];
37 up[0] = side[1]*forward[2] - forward[1]*side[2];
38 //cross(side, forward, up);
39 //__gluMakeIdentityf(&m[0][0]);
40 m[0][0] = side[0];
41 m[1][0] = side[1];
42 m[2][0] = side[2];
43 m[3][0] = 0;
44 m[0][1] = up[0];
45 m[1][1] = up[1];
46 m[2][1] = up[2];
47 m[3][1] = 0;
48 m[0][2] = -forward[0];
49 m[1][2] = -forward[1];
50 m[2][2] = -forward[2];
51 m[3][2] = 0;
52 m[0][3] = 0;
53 m[1][3] = 0;
54 m[2][3] = 0;
55 m[3][3] = 1;
56 glMultMatrixf(&m[0][0]);
57 glTranslatef(-eyex, -eyey, -eyez);
58 }
gluPerspective_(GLdouble fovyInDegrees,GLdouble aspectRatio,GLdouble znear,GLdouble zfar)59 inline void gluPerspective_(GLdouble fovyInDegrees, GLdouble aspectRatio,
60 GLdouble znear, GLdouble zfar){
61 GLdouble ymax, xmax;
62 ymax = znear * tan(fovyInDegrees * M_PI / 360.0);
63 // ymin = -ymax;
64 // xmin = -ymax * aspectRatio;
65 xmax = ymax * aspectRatio;
66 glFrustum(-xmax, xmax, -ymax, ymax, znear, zfar);
67 }
68 ///
69 ////////////////////////////////
70 #endif // GLUREPLACE_H
71