-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
194 lines (155 loc) · 3.83 KB
/
Game.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// Game.cpp
// VirtualMarbleGame
//
// Created by Maximilian Weber
//
// TODO: release resources
#include <iostream>
#include "Graphics.h"
#include "Marble.h"
#include "Labyrinth.h"
#include "VideoManager.h"
#include "Pose.h"
#include "Physics.h"
using namespace std;
Marble* marble;
Graphics* graphics;
Labyrinth* labyrinth;
VideoManager* videoManager;
TrackingManager* trackingManager;
Pose* pose;
Pose* gravity;
Physics* physics;
void display();
void resize( int, int );
void idle();
static void trackingTimer(int value);
static void ballTimer(int value);
static void physicsTimer(int value);
void hitkey( unsigned char key, int x, int y );
void checkFinish( int value);
int windowId;
int t = 30;
bool debug = false;
int cameraNumber = true;
void hitkey( unsigned char key, int x, int y )
{
switch ( key )
{
case 27: // Escape key
glutDestroyWindow ( windowId );
exit (0);
break;
case 108: // l key
labyrinth->createMaze();
break;
case 'n': // n key
marble->reset();
break;
case 'c': // c key
graphics->switchCalibrate();
trackingManager->switchCalibrate();
physics->switchCalibrate();
break;
case 'r':
physics->switch90();
graphics->switch90();
break;
}
//glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
}
void display()
{
graphics->display();
}
void resize(int w, int h)
{
graphics->resize(w,h);
}
void idle()
{
graphics->idle();
}
void checkFinish( int value)
{
if(marble->m_x>Labyrinth_size-1 && marble->m_y>Labyrinth_size-1)
{
//TODO: Play some Sounds..
labyrinth->createMaze();
marble->reset();
}
glutTimerFunc (t, checkFinish, value);
}
double yStart = 5.0;
double speed = 0.0;
double y = yStart;
double d = t / 1000.0;
float a = -9.81;
static void ballTimer(int value)
{
/* Do timer processing */
/* maybe glutPostRedisplay(), if necessary */
//TODO:
//PHYSICS
// x += 0.1;
// x = fmod(x, M_PI);
// m->setY(3 * abs(sin(x)));
speed += a * d;
y += speed * d;
if ( y < 0 && speed <0 ) speed *= -1;
marble->setY(y);
glutPostRedisplay();
/* call back again after elapsedUSecs have passed */
glutTimerFunc (t, ballTimer, value);
}
static void trackingTimer(int value)
{
trackingManager->process();
glutPostRedisplay();
glutTimerFunc (t, trackingTimer, value);
}
static void physicsTimer(int value)
{
physics -> process();
glutTimerFunc (t, physicsTimer, value);
}
int main(int argc, char* argv[])
{
cout << "Starting: " << argv[0] << "\n";
if(argc > 1 && *argv[1] == '1')
{
debug =true;
cout << "Debug mode.\n";
}
if(argc > 2)
{
cameraNumber = atoi(argv[2]);
cout << "Using camera: " << argv[2] << ".\n";
}
glutInit( &argc, argv);
videoManager = new VideoManager(cameraNumber);
pose = new Pose();
gravity = new Pose();
trackingManager = new TrackingManager(debug, videoManager, pose, gravity);
marble = new Marble(0, 0, -3, 0.4, 1);
labyrinth = new Labyrinth();
graphics = new Graphics(debug, marble, labyrinth, videoManager, pose, gravity);
physics = new Physics(labyrinth, marble, pose, gravity);
windowId = graphics->init();
// make functions known to GLUT
glutDisplayFunc( display );
glutReshapeFunc( resize );
//glutIdleFunc( idle );
glutKeyboardFunc( hitkey );
glutTimerFunc(t, trackingTimer, 1);
glutTimerFunc(t, physicsTimer, 1);
glutTimerFunc(t, checkFinish, 1);
//glutMouseFunc(mouse);
// start the action
glutMainLoop();
return 0;
}