-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
530 lines (456 loc) · 12.5 KB
/
main.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#include <cstdlib>
#include <iostream>
using namespace std;
#include <GL/openglut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "flags.h"
#include "mainflags.h"
#include "collisions.h"
#include "field.h"
#include "keys.h"
#include "menu.h"
#include "mouse.h"
//#include "gjoycontrol.h"
#include "gautils.h"
#include "utility.h"
#include "gatimer.h"
//#define TOTAL_DEBUG
#define DEBUG_WORLD false
//#define CAMERACAR
#define GA_RADAR_WINDOW true
//#define FULLSCREEN
/****************************************** GOLEM RADAR *************************************/
#include "grobjects.h"
void reshape2(int, int);
void reshape(int, int);
void DrawBattery();
void DrawGas();
void DrawEngines();
bool GRPAUSE = false;
bool TIME_TO_REDRAW = true;
bool TIME_TO_REDRAW2 = true;
float RadarRadius = GRRADAR_RADIUS;
/******************* GLPRINTF **********************/
float x = 0.2; //(GLfloat)glutGet(GLUT_WINDOW_WIDTH);
float y = 0.075; //(GLfloat)glutGet(GLUT_WINDOW_HEIGHT);
int behave_x = 220;
int behave_dx = 90;
int behave_y = 38;
int status_y = 23;
int task_y = 8;
/***************************************************/
/* messaggio STATUS */
float BatteryValue = 0.0; /* valoree reala in Volts */
float BatteryCharge = 0.0; /* compresa fra 0.0 e 1.0 */
bool EnginesOn = false;
float GasValue = 0.0; /* valoree reala in Volts */
float GasPercentage = 0.0; /* compresa fra 0.0 e 1.0 */
/* messaggio Q */
bool NewQ = false;
GBehaviour_Type Behaviour;
Task_Type Task;
Status_Type Status;
/***************************************************/
int mainwin_radar, subwin_radar;
gaTimer *T_radar = NULL;
GA_Point center(0.0, 0.0);
GRBackGround BG(RadarRadius);
void init_radar(void)
{
T_radar = new gaTimer();
}
void initGL_radar()
{
GLfloat a = 100.0, aw = 8000.0,
d0 = 600.0, d0w = 1000.0,
p0x = 5000.0, p0y = 0.0, p0z = 1000.0, p0w = 1000.0;
glClearColor(0.1, 0.1, 0.1, 0.0);
glEnable(GL_LIGHTING);
if (USE_DEPTH_TEST)
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_FLAT);
glEnable(GL_NORMALIZE);
GLfloat amb0[] = {a, a, a, aw};
glLightfv(GL_LIGHT0, GL_AMBIENT, amb0);
GLfloat dif0[] = {d0, d0, d0, d0w};
glLightfv(GL_LIGHT0, GL_DIFFUSE, dif0);
GLfloat pos0[] = {p0x, p0y, p0z, p0w};
glLightfv(GL_LIGHT0, GL_POSITION, pos0);
}
void display3(void)
{
static int lastdrawtime;
int ddt;
if (FORCE_REDRAW_PERIOD)
{
/*aggiorno la finestra solo se sono passati almeno
MILLI_PERIOD millisecondi dall'aggiornamento precedente */
ddt = glutGet(GLUT_ELAPSED_TIME) - lastdrawtime;
TIME_TO_REDRAW = ddt >= MILLI_PERIOD ? true : false;
}
if (GRPAUSE == false && TIME_TO_REDRAW)
{
lastdrawtime = glutGet(GLUT_ELAPSED_TIME);
if (USE_DEPTH_TEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
else
glClear(GL_COLOR_BUFFER_BIT);
if (USE_DEPTH_TEST)
{
/* scrivo informazioni utili sulla finestra */
static int ilasttime;
int dt = glutGet(GLUT_ELAPSED_TIME) - ilasttime;
ilasttime = glutGet(GLUT_ELAPSED_TIME);
float fps = FPS(dt);
glColor3f(1.0, 1.0, 1.0);
glPrintf(10, 10, 0, 10, "fps %f\n", fps);
glPrintf(glutGet(GLUT_WINDOW_WIDTH) - 100, 10, 0, 10,
"time %d:%d\n", (T_radar->ReadTimer() / 60), T_radar->ReadTimer() % 60);
}
/* disegno */
glPushMatrix();
BG.Draw(center);
float robot_orientation = 0.0;
Team *T = NULL;
bool THERESATEAM = false;
if (team_active == TEAMA)
{
if (TEAMA_PRESENT)
{
T = TeamA;
THERESATEAM = true;
}
}
else
{
if (TEAMB_PRESENT)
{
T = TeamB;
THERESATEAM = true;
}
}
if (THERESATEAM)
robot_orientation = T->RV[r_man]->GetP().h;
if (T->RV[r_man]->GetSide() == Gblue)
robot_orientation -= 180.0;
glRotatef(90.0 - robot_orientation, 0.0, 0.0, 1.0);
if (THERESATEAM)
{
T->RV[r_man]->myParser->DrawBall();
T->RV[r_man]->myParser->DrawVector();
T->RV[r_man]->myParser->DrawTarget();
T->RV[r_man]->myParser->DrawObjects();
T->RV[r_man]->myParser->DrawMG();
T->RV[r_man]->myParser->DrawOG();
T->RV[r_man]->myParser->DrawFWall();
T->RV[r_man]->myParser->DrawBWall();
T->RV[r_man]->myParser->DrawLWall();
T->RV[r_man]->myParser->DrawRWall();
}
glPopMatrix();
glutSwapBuffers();
TIME_TO_REDRAW = false;
}
glutPostRedisplay();
// reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
}
void reshape3(int w, int h)
{
glViewport(0, 0, w, h - 50);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(455.0, (GLfloat)w / (GLfloat)(h - 50), 1000.0, RadarRadius + 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, RadarRadius, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
TIME_TO_REDRAW = true;
}
void display4(void)
{
if (GRPAUSE == false && TIME_TO_REDRAW2)
{
Team *T = NULL;
bool THERESATEAM = false;
if (team_active == TEAMA)
{
if (TEAMA_PRESENT)
{
T = TeamA;
THERESATEAM = true;
}
}
else
{
if (TEAMB_PRESENT)
{
T = TeamB;
THERESATEAM = true;
}
}
if (THERESATEAM)
{
BatteryValue = T->RV[r_man]->myParser->BatteryCharge();
BatteryCharge = (BatteryValue - BATTERY_CHARGE_MIN) / BATTERY_CHARGE_RANGE;
// printf("\ndisplay2: BVal=%f, BCarge=%f ",BatteryValue, BatteryCharge);
if (BatteryCharge < 0.0)
BatteryCharge = 0.0;
if (BatteryCharge > 1.0)
BatteryCharge = 1.0;
EnginesOn = T->RV[r_man]->myParser->EnginesOn();
GasValue = T->RV[r_man]->myParser->GasCharge();
GasPercentage = (GasValue - GAS_CHARGE_MIN) / GAS_CHARGE_RANGE;
// printf("\ndisplay2: GasVal=%f, GPer=%f ",GasValue, GasPercentage);
if (GasPercentage < 0.0)
GasPercentage = 0.0;
if (GasPercentage > 1.0)
GasPercentage = 1.0;
NewQ = T->RV[r_man]->myParser->NewQ();
// printf("\ndisplay2: NewQ=%f ", NewQ);
Behaviour = T->RV[r_man]->myParser->Behaviour();
Task = T->RV[r_man]->myParser->Task();
Status = T->RV[r_man]->myParser->Status();
}
glClearColor(0.7, 0.7, 0.7, 0.0);
if (USE_DEPTH_TEST)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
else
glClear(GL_COLOR_BUFFER_BIT);
/* disegno */
DrawBattery();
DrawGas();
DrawEngines();
glColor3f(1.0, 1.0, 1.0);
glPrintf(5, 17, 0, 10, "Battery\n");
glPrintf(5, 5, 0, 10, "%.1f", BatteryValue);
glPrintf(80, 17, 0, 10, "Gas\n");
glPrintf(80, 5, 0, 10, "%.1f", GasValue);
glPrintf(145, 17, 0, 10, "Engines\n");
if (EnginesOn)
glPrintf(178, 33, 0, 10, "ON\n");
else
glPrintf(178, 33, 0, 10, "OFF\n");
glPrintf(behave_x, behave_y, 0, 10, "Behaviour\n");
if (NewQ)
{
switch (Behaviour)
{
case SearchBall:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "SRC\n");
break;
case GoToBall:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "GTB\n");
break;
case CarryBall:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "CAR\n");
break;
case NearWall:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "NEW\n");
break;
case CatchBall:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "CAT\n");
break;
case Defend:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "DEF\n");
break;
case Wingman:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "WIN\n");
break;
case AllBack:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "ALB\n");
break;
case Stopper:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "STP\n");
break;
case Goalie:
glPrintf(behave_x + behave_dx, behave_y, 0, 10, "GOA\n");
break;
}
}
glPrintf(behave_x, task_y, 0, 10, "Task\n");
if (NewQ)
{
switch (Task)
{
case RoleG:
glPrintf(behave_x + behave_dx, task_y, 0, 10, "RG\n");
break;
case Role1:
glPrintf(behave_x + behave_dx, task_y, 0, 10, "R1\n");
break;
case Role2:
glPrintf(behave_x + behave_dx, task_y, 0, 10, "R2\n");
break;
case Role3:
glPrintf(behave_x + behave_dx, task_y, 0, 10, "R3\n");
break;
}
}
glPrintf(behave_x, status_y, 0, 10, "Status\n");
if (NewQ)
{
switch (Status)
{
case PlayerStopped:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "PST\n");
break;
case EnemyHasBall:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "EHB\n");
break;
case FreeBall:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "FRB\n");
break;
case BallMine:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "BMN\n");
break;
case Danger:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "DNG\n");
break;
case Quiet:
glPrintf(behave_x + behave_dx, status_y, 0, 10, "QIET\n");
break;
}
}
glutSwapBuffers();
glutPostRedisplay();
TIME_TO_REDRAW2 = false;
}
}
/*************************************** Battery **********************************************/
void DrawBattery()
{
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glTranslatef(-SUBWIN_X / 2.0, SUBWIN_Y / 2.0, 0.0);
glPushMatrix();
glTranslatef(0.0, 0.0, GRZ_UP / 1000.0);
glBegin(GL_POLYGON);
if (BatteryCharge > 0.66667)
glColor3f(0.0, 0.0, 1.0);
else
{
if (BatteryCharge > 0.33333)
glColor3f(1.0, 1.0, 0.0);
else
glColor3f(1.0, 0.0, 0.0);
}
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, -y, 0.0);
glVertex3f(x * BatteryCharge, -y, 0.0);
glVertex3f(x * BatteryCharge, 0.0, 0.0);
glEnd();
glPushMatrix();
glTranslatef(0.0, 0.0, GRZ_UP / 1000.0);
glBegin(GL_LINE_STRIP);
glColor3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, -y, 0.0);
glVertex3f(x, -y, 0.0);
glVertex3f(x, -y * 3.0 / 4.0, 0.0);
glVertex3f(x + y / 4.0, -y * 3.0 / 4.0, 0.0);
glVertex3f(x + y / 4.0, -y / 4.0, 0.0);
glVertex3f(x, -y / 4.0, 0.0);
glVertex3f(x, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
/***************************************** Gas **********************************************/
void DrawGas()
{
glPushMatrix();
glTranslatef(-SUBWIN_X / 2.0 + x + x / 4.0, SUBWIN_Y / 2.0, GRZ_UP / 1000.0);
glColor3f(0.5, 0.9, 0.8);
glBegin(GL_POLYGON);
glVertex3f(GasPercentage * x, 0.0, 0.0);
glVertex3f(GasPercentage * x, -y, 0.0);
glVertex3f(0.0, -y, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glEnd();
glPushMatrix();
glTranslatef(0.0, 0.0, GRZ_UP / 1000.0);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(x, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, -y, 0.0);
glVertex3f(x, -y, 0.0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(GasPercentage * x, 0.0, 0.0);
glVertex3f(GasPercentage * x, -y, 0.0);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(GasPercentage * x, -y / 2.0, 0.0);
glVertex3f((GasPercentage * x + x / 4.0), -y / 2.0, 0.0);
glEnd();
glPopMatrix();
glPopMatrix();
}
/************************************************* Engines **********************************************/
void DrawEngines()
{
glPushMatrix();
float dx = x / 5.0;
float lato = x / 10.0;
glTranslatef(-dx, y * 0.6, GRZ_UP / 1000.0);
glPushMatrix();
GRCircle C(lato);
GColor enginescolor = Gblack;
if (EnginesOn == true)
enginescolor = Gred;
C.Draw(GA_Point(0.0, 0.0), 10, enginescolor, 1);
glPushMatrix();
glTranslatef(0.0, 0.0, GRZ_UP / 1000.0);
C.Draw(GA_Point(0.0, 0.0), 10, Gblack, 0);
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
void reshape4(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(1.0, (GLfloat)w / (GLfloat)h, 0.1, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
TIME_TO_REDRAW2 = true;
}
void key_press_callback_radar(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
case 'Q':
case 'q':
exit(1);
break;
/* case '1':
P.ListenToRobot(1);
glutSetWindowTitle("Golem Radar ERONE");
break;
case '2':
P.ListenToRobot(2);
glutSetWindowTitle("Golem Radar ARCHIMEDE");
break;
case '3':
P.ListenToRobot(3);
glutSetWindowTitle("Golem Radar EUCLIDE");
break;
case '4':
P.ListenToRobot(4);
glutSetWindowTitle("Golem Radar EULERO");
break;
*/
case '-':
if (RadarRadius < 20000.0)
{
RadarRadius += 1000.0;
BG = GRBackGroundehave_dx = 90;