-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreEvent.cpp
More file actions
145 lines (131 loc) · 2.98 KB
/
Copy pathCoreEvent.cpp
File metadata and controls
145 lines (131 loc) · 2.98 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
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
#include "core.h"
void Core::handleEvents() {
ALLEGRO_EVENT ev;
int screen_w = al_get_display_width(display)/2.0f;
int screen_h = al_get_display_height(display)/2.0f;
while(al_get_next_event(event_queue, &ev)) {
switch (ev.type) {
case ALLEGRO_EVENT_KEY_UP: {
if (ev.keyboard.keycode < 255) {
keyStates[ev.keyboard.keycode] = false;
}
onKeyUp(ev);
break;
}
case ALLEGRO_EVENT_KEY_DOWN: {
if (ev.keyboard.keycode < 255) {
keyStates[ev.keyboard.keycode] = true;
}
onKeyDown(ev);
break;
}
case ALLEGRO_EVENT_MOUSE_AXES: {
//printf("(%d, %d) == (%d, %d) == %d, %d\n", ev.mouse.x, ev.mouse.y, screen_w, screen_h, al_get_display_width(display), al_get_display_height(display));
mouse_dx = ev.mouse.x - screen_w;//-8);
mouse_dy = ev.mouse.y - screen_h;//-30);
onMouseMove(mouse_dx, mouse_dy);
break;
}
case ALLEGRO_EVENT_TIMER: {
update();
break;
}
}
}
al_set_mouse_xy(display, screen_w, screen_h);
}
void Core::update() {
if (dev_console->visible) {
return;
}
if (keyStates[ALLEGRO_KEY_W]) {
camera.moveTo(Vector3f(0, 0, 0.01f));
}
if (keyStates[ALLEGRO_KEY_S]) {
camera.moveTo(Vector3f(0, 0, -0.01f));
}
if (keyStates[ALLEGRO_KEY_A]) {
camera.moveTo(Vector3f(0.01f, 0, 0));
}
if (keyStates[ALLEGRO_KEY_D]) {
camera.moveTo(Vector3f(-0.01f, 0, 0));
}
if (keyStates[ALLEGRO_KEY_Q]) {
camera.moveY(0.01f);
}
if (keyStates[ALLEGRO_KEY_E]) {
camera.moveY(-0.01f);
}
}
void Core::onMouseMove(float dx, float dy) {
if (dx != 0) {
camera.applyRotation(dx*(0.0005f), Vector3f(0, 1, 0));
}
if (dy != 0) {
//printf("%f\n", dy);
camera.changePitch(dy*(0.0005f));
}
}
void Core::onKeyUp(ALLEGRO_EVENT ev) {
switch(ev.keyboard.keycode) {
case ALLEGRO_KEY_ESCAPE: {
//if (dev_console->visible) {
// dev_console->visible = false;
//} else {
running = false;
//}
return;
break;
}
case ALLEGRO_KEY_TAB: {
dev_console->visible = !dev_console->visible;
return;
break;
}
case ALLEGRO_KEY_ENTER: {
if (dev_console->visible) { //Move to dev_console's input
dev_console->executeCommand();
}
return;
break;
}
}
if (dev_console->visible) {
dev_console->input(ev.keyboard.keycode, keyStates[ALLEGRO_KEY_LSHIFT]);
}
}
void Core::onKeyDown(ALLEGRO_EVENT ev) {
/*switch(ev.keyboard.keycode) {
case ALLEGRO_KEY_W: {
//rot += 1.0f;
///camera.camera_z -= 0.1f;
camera.moveTo(Vector3f(0, 0, 0.08f));
break;
}
case ALLEGRO_KEY_S: {
//camera.camera_z += 0.1f;
camera.moveTo(Vector3f(0, 0, -0.08f));
break;
}
case ALLEGRO_KEY_A: {
//roty -= 1.0f;
//camera.applyRotation(-0.1, Vector3f(0, 1, 0));
camera.moveTo(Vector3f(0.8f, 0, 0));
break;
}
case ALLEGRO_KEY_D: {
//roty += 1.0f;
//camera.applyRotation(0.1, Vector3f(0, 1, 0));
camera.moveTo(Vector3f(-0.8f, 0, 0));
break;
}
case ALLEGRO_KEY_Q: {
camera.moveY(0.01f);
break;
}
case ALLEGRO_KEY_E: {
camera.moveY(-0.01f);
break;
}
}*/
}