-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathship_test.cpp
More file actions
99 lines (82 loc) · 2.1 KB
/
ship_test.cpp
File metadata and controls
99 lines (82 loc) · 2.1 KB
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
/*
* ship_test.cpp
*
* Created on: Sep 13, 2017
* Author: Nathan Pankowsky
*/
#include <iostream>
#include <GL/glut.h>
#include "logger.hpp"
#include "pos.hpp"
#include "ship.hpp"
size_t n = 2;
objects::Ship *ship;
int selected_ship = 0;
#define SIZE (1000)
#define SCALE (1)
void display()
{
gluOrtho2D(0, SIZE * SCALE, 0, SIZE * SCALE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
for (int i = 0; n > i; ++i) {
ship[i].display();
PRINT_INFO("Ship [" << i << "] pos: " << ship[i]);
}
glFlush();
}
void time_event(int v)
{
for (int i = 0; n > i; ++i) {
ship[i].update();
}
glutTimerFunc(20, time_event, 0.5); // re-add event to glut's scheduler
glutPostRedisplay(); // schedule calling the display function again
}
void add_waypoint(int button, int state, int x, int y)
{
logic::Pos pos(x, SIZE - y);
ship[selected_ship].enqueue(pos);
PRINT_ERROR("updated ship: " << ship[selected_ship]);
}
void select_ship(unsigned char key, int x, int y)
{
if (n > key - '0' - 1) {
selected_ship = key - '0' - 1;
PRINT_ERROR("selected ship: " << ship[selected_ship]);
} else if (key == '0' && n > 9) {
selected_ship = 9;
}
}
int main(int argc, char **argv)
{
if (1 < argc) {
std::cout << argv[1] << std::endl;
n = atoi(argv[1]);
}
logic::Pos pos[n];
ship = new objects::Ship[n];
for (int i = 0; n > i; ++i) {
/*
for (int j = 0; n > j; ++j) {
pos[j].set_x(rand() & SIZE);
pos[j].set_y(rand() & SIZE);
ship[i].enqueue(pos[j]);
}
*/
ship[i].set_pos(SIZE / n, i * SIZE / n + SIZE / n);
ship[i].set_dpos(10, 1);
ship[i].update();
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(SIZE, SIZE);
glutCreateWindow("Ship Test");
glutDisplayFunc(display);
glutKeyboardFunc(select_ship);
glutMouseFunc(add_waypoint);
glutTimerFunc(200, time_event, 0.5);
glutMainLoop();
return 0;
}