-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controls.cpp
134 lines (131 loc) · 3.13 KB
/
Controls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "stdafx.h"
#include "Models.h"
#include "Controls.h"
#include "myCamera.h"
extern int switchCam;
extern Model *car ;
extern vec4 carPosition;
extern vec4 carForward ; // the minimum step of the car's move
extern float carTurn; // the minimum angle of car's turn
extern float carRotation ; // store the car's rotation
extern myCamera camera; // initialize the camera
extern bool switcher;
void funcKey( int key, int x, int y ) {
if( switchCam != 0 ) {
switch( key ) {
case GLUT_KEY_UP: // move forward
carPosition += carForward;
car->setTraslate(carPosition);
break;
case GLUT_KEY_DOWN: // move backward
carPosition -= carForward;
car->setTraslate(carPosition);
break;
case GLUT_KEY_LEFT:
carRotation += carTurn;
camera.yawLeft( carTurn );
carForward = Angel::vec4(-sin(carRotation/180*PI), 0, -cos(carRotation/180*PI), 0);
car->setRotate(vec3(-90.0, -180.0 + carRotation, 0.0));
break;
case GLUT_KEY_RIGHT:
carRotation -= carTurn;
camera.yawRight( carTurn );
carForward = Angel::vec4(-sin(carRotation/180*PI), 0, -cos(carRotation/180*PI), 0);
car->setRotate(vec3(-90.0, -180.0 + carRotation, 0.0));
break;
}
}else {
switch( key ) {
default:
break;
}
}
glutPostRedisplay();
}
void keyBoard( unsigned char key, int x, int y ) {
if ( switchCam == 0 ) { //fly Cam
switch(key) {
case 'w': // MOVE Forward
camera.moveForward();
break;
case 's': // MOVE Backward
camera.moveBackward();
break;
case 'a': // MOVE Left
camera.moveLeft();
break;
case 'd': // MOVE Right
camera.moveRight();
break;
case 'q': // Turn Left
camera.yawLeft();
break;
case 'e': // Turn Right
camera.yawRight();
break;
case 'x': // pitch up
camera.pitchUp();
break;
case 'X': // pitch down
camera.pitchDown();
break;
case 'c': // yaw counter-clockwise in the un plane
camera.rollRight();
break;
case 'C': // yaw clockwise in the un plane
camera.rollLeft();
break;
case 't':
if(switcher == false)
switcher = true;
else
switcher = false;
break;
case 033: // Escape key
exit( EXIT_SUCCESS );
default:
break;
}
} else {
switch(key) {
case 'w': // move forward
carPosition += carForward;
car->setTraslate(carPosition);
break;
case 's': // move backward
carPosition -= carForward;
car->setTraslate(carPosition);
break;
case 'a':
carRotation += carTurn;
camera.yawLeft( carTurn );
carForward = Angel::vec4(-sin(carRotation/180*PI), 0, -cos(carRotation/180*PI), 0);
car->setRotate(vec3(-90.0, -180.0 + carRotation, 0.0));
break;
case 'd':
carRotation -= carTurn;
camera.yawRight( carTurn );
carForward = Angel::vec4(-sin(carRotation/180*PI), 0, -cos(carRotation/180*PI), 0);
car->setRotate(vec3(-90.0, -180.0 + carRotation, 0.0));
break;
case 'v': // switch cam
case 'V': // inCar/followCar
if ( switchCam == 1)
switchCam = 2;
else
switchCam = 1;
break;
case 'f':
case 'F':
if ( switchCam == 0)
switchCam = 2;
else
switchCam = 0;
break;
case 033: // Escape key
case 'q': case 'Q':
exit( EXIT_SUCCESS );
}
}
glutPostRedisplay();
}