-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cpp
More file actions
40 lines (35 loc) · 966 Bytes
/
InputHandler.cpp
File metadata and controls
40 lines (35 loc) · 966 Bytes
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
#include "InputHandler.h"
#include <iostream> // TODO: remove
InputHandler::InputHandler(bool *_running, Renderer *_renderer)
{
running = _running;
renderer = _renderer;
}
void InputHandler::handleInput()
{
mouseState = SDL_GetMouseState(&mouseX, &mouseY);
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
*running = false;
break;
case SDL_KEYDOWN:
keysPressed[event.key.keysym.sym] = true;
break;
case SDL_KEYUP:
keysPressed[event.key.keysym.sym] = false;
break;
default:
break;
}
}
// DEBUG: Adjust the camera according to input
int rel_x = keysPressed[SDLK_RIGHT] - keysPressed[SDLK_LEFT];
int rel_y = keysPressed[SDLK_DOWN] - keysPressed[SDLK_UP];
double rel_zoom = 1 + 0.001 * keysPressed[SDLK_RIGHTBRACKET] - 0.001 * keysPressed[SDLK_LEFTBRACKET];
if (keysPressed[SDLK_z])
rel_zoom = -1;
renderer->adjustCamera(rel_x, rel_y, rel_zoom);
}