int floorSize = 200;
/* Current camera x, y, z coords */
-GLfloat camx = 0.0, camy = 0.0, camz = 0.0, rot = 0.0;
+GLfloat camx = 0.0, camy = 0.0, camz = 0.0, keyrot = 0.0;
+GLfloat factor = 1.0;
/* Length of axis lines */
GLfloat lineLength = 5;
GLfloat emission0[] = {0.0, 0.3, 0.3, 1.0};
GLfloat direction0[] = {0.0, 0.0, 0.0};
-GLfloat light0_pos[] ={1.0, 1.0, 0,0, 0.5};
GLfloat shine = 100.0;
GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
/* Zoom and rotate tracking */
-GLfloat zoomFactor = 0.0, rotateFactor = 0.0;
+GLfloat zoom = 0.0, rotate = 0.0;
+GLfloat zoomFactor = 0.5, rotateFactor = 0.5;
/* Beginning width, height */
int width = 500, height = 500;
\ No newline at end of file
extern int floorSize;
/* Current camera position */
-extern GLfloat camx, camy, camz, rot;
+extern GLfloat camx, camy, camz, keyrot;
+extern GLfloat factor;
/* Length of axis lines */
extern GLfloat lineLength;
extern int width, height;
/* Zoom and rotate tracking */
-GLfloat zoomFactor, rotateFactor;
+extern GLfloat zoom, rotate;
+extern GLfloat zoomFactor, rotateFactor;
#endif /* GLOBALS_H */
\ No newline at end of file
void keyboard(unsigned char key, int x, int y) {\r
switch(key) {\r
case 'w':\r
- camz = camz - 1;\r
+ case 'W':\r
+ camz -= factor;\r
break;\r
case 'a':\r
- camx = camx - 1;\r
+ case 'A':\r
+ camx -= factor;\r
break;\r
case 's':\r
- camz = camz + 1;\r
+ case 'S':\r
+ camz -= factor;\r
break;\r
case 'd':\r
- camx = camx + 1;\r
+ case 'D':\r
+ camx += factor;\r
break;\r
case 'q':\r
- camy = camy + 1;\r
+ case 'Q':\r
+ camy += factor;\r
break;\r
case 'e':\r
- camy = camy - 1;\r
+ case 'E':\r
+ camy -= factor;\r
break;\r
case 'z':\r
- rot = rot + 1;\r
+ case 'Z':\r
+ keyrot += factor;\r
break;\r
case 'x':\r
- rot = rot - 1;\r
+ case 'X':\r
+ keyrot += factor;\r
break;\r
+ case '=':\r
+ case '+':\r
+ factor += 0.1;\r
+ printf("Factor of change is now %f\n", factor);\r
+ break;\r
+ case '-':\r
+ case '_':\r
+ factor -= 0.1;\r
+ printf("Factor of change is now %f\n", factor);\r
+ break;\r
+\r
}\r
- printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, rot);\r
+ printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, keyrot);\r
glutPostRedisplay();\r
}\r
\r
*/\r
void motion(int x, int y) {\r
if (moving) {\r
- zoomFactor += (y - starty);\r
- rotateFactor += (x - startx);\r
+ zoom += (y - starty);\r
+ rotate += (x - startx);\r
startx = x;\r
starty = y;\r
glutPostRedisplay();\r
glMatrixMode(GL_MODELVIEW);\r
glLoadIdentity();\r
\r
- GLfloat zcoord = 5.0 + (zoomFactor*0.2);\r
- if ( zcoord < 0.0 ) {\r
- printf("zf: %f", zoomFactor);\r
- zcoord = 0.0;\r
- zoomFactor = 0.0;\r
- }\r
-\r
gluLookAt(\r
- 0.0, 0.0, zcoord, /* eye is at (x,y,z) */\r
+ 0.0, 0.0, 5.0 + (zoom*zoomFactor), /* eye is at (x,y,z) */\r
0.0, 0.0, 0.0, /* center is at (x,y,z) */\r
0.0, 1.0, 0.0 /* up is in postivie Y direction */\r
);\r
lightPosition[2] = 12*sin(lightAngle);\r
lightPosition[3] = 0.0;\r
\r
-\r
- //glRotatef(angle, 0.0, 1.0, 0.0);\r
- // glRotatef(angle2, 1.0, 0.0, 0.0);\r
-\r
glPushMatrix();\r
\r
/* Perform scene rotations based on user mouse/keyboard input. */\r
- glRotatef(rotateFactor*0.5, 0.0, 1.0, 0.0);\r
- //glTranslatef(camx, camy, camz);\r
- //glRotatef(rot, 1.0, 0.0, 0.0);\r
+ glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0);\r
+ glTranslatef(camx, camy, camz);\r
+ glRotatef(keyrot, 1.0, 0.0, 0.0);\r
\r
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
\r
* init function; sets initial OpenGL state\r
*/\r
void init() {\r
- glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);\r
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r