Repository navigation
Expand file tree
/
Copy pathBaseApp.cpp
More file actions
151 lines (121 loc) · 3.03 KB
/
Copy pathBaseApp.cpp
File metadata and controls
151 lines (121 loc) · 3.03 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
146
147
148
149
// +------------------------------------------------------------+
// | University Racer |
// | Projekt do PGR a GMU, FIT VUT v Brne, 2011 |
// +------------------------------------------------------------+
// | Autori: Tomáš Kimer, xkimer00@stud.fit.vutbr.cz |
// | Tomáš Sychra, xsychr03@stud.fit.vutbr.cz |
// | David Šabata, xsabat01@stud.fit.vutbr.cz |
// +------------------------------------------------------------+
#include "BaseApp.h"
#ifdef _DEBUG
#define new MYDEBUG_NEW
#endif
using namespace std;
BaseApp::BaseApp()
{
/*
mouseRX = 0.0f;
mouseRY = 0.0f;
mouseWheel = 1.0f;
pz = -100.0f;
*/
windowWidth = 0;
windowHeight = 0;
}
BaseApp::~BaseApp()
{
}
Camera* const BaseApp::getCamera()
{
return &camera;
}
// Call proper event handlers
void BaseApp::handleEvent(SDL_Event event)
{
switch(event.type)
{
case SDL_KEYDOWN :
onKeyDown(event.key.keysym.sym, event.key.keysym.mod);
break;
case SDL_KEYUP :
onKeyUp(event.key.keysym.sym, event.key.keysym.mod);
break;
case SDL_MOUSEMOTION :
onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, event.motion.state);
break;
case SDL_MOUSEBUTTONDOWN :
onMouseDown(event.button.button, event.button.x, event.button.y);
break;
case SDL_MOUSEBUTTONUP :
onMouseUp(event.button.button, event.button.x, event.button.y);
break;
case SDL_VIDEORESIZE:
onWindowResized(event.resize.w, event.resize.h);
break;
/*case SDL_VIDEOEXPOSE:
onWindowRedraw();
break;*/
default :
break;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Default event handlers
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void BaseApp::onWindowResized(int w, int h)
{
glViewport(0, 0, w, h);
windowWidth = w;
windowHeight = h;
}
void BaseApp::onKeyDown(SDLKey key, Uint16 /*mod*/)
{
activeKeys.remove(key); // chceme mit kazdou klavesu jen jednou
activeKeys.push_back(key);
switch(key) {
case SDLK_ESCAPE : quit(); return;
default : return;
}
}
void BaseApp::onKeyUp(SDLKey key, Uint16 /*mod*/)
{
activeKeys.remove(key);
}
void BaseApp::onMouseMove(unsigned /*x*/, unsigned /*y*/, int xrel, int yrel, Uint8 buttons)
{
/*
if(buttons & SDL_BUTTON_LMASK)
{
mouseRX += xrel;
mouseRY += yrel;
redraw();
}
if(buttons & SDL_BUTTON_RMASK)
{
pz += yrel;
redraw();
}
*/
}
void BaseApp::onMouseDown(Uint8 button, unsigned /*x*/, unsigned /*y*/)
{
/*
switch(button) {
case SDL_BUTTON_WHEELUP : mouseWheel += 1; break;
case SDL_BUTTON_WHEELDOWN : mouseWheel -= 1; break;
default : return;
};
redraw();
*/
}
void BaseApp::onMouseUp(Uint8 /*button*/, unsigned /*x*/, unsigned /*y*/)
{
}
void BaseApp::onWindowRedraw(const GameTime & gameTime)
{
}
void BaseApp::onInit()
{
}