]> git.lizzy.rs Git - dragonblocks3d.git/blob - src/input_handler.cpp
New structure
[dragonblocks3d.git] / src / input_handler.cpp
1 #include "camera.hpp" 
2 #include "input_handler.hpp" 
3 #include "window.hpp" 
4
5 using namespace std;
6 using namespace glm;
7 using namespace dragonblocks;
8
9 void InputHandler::processInput(double dtime)
10 {
11         cursor_delta = vec2(mouse_sensitivity * dtime) * (vec2)window->getCursorDelta();
12         was_down.clear();
13         for (auto it = is_down.begin(); it != is_down.end(); it++) {
14                 int key = *it;
15                 if (! window->isKeyDown(key)) {
16                         was_down.insert(key);
17                 }
18         }
19         is_down.clear();
20         for (auto it = listened_keys.begin(); it != listened_keys.end(); it++) {
21                 int key = *it;
22                 if (window->isKeyDown(key)) {
23                         is_down.insert(key);
24                 }
25         }
26 }
27
28 void InputHandler::listenFor(int key)
29 {
30         listened_keys.insert(key);
31 }
32
33 void InputHandler::dontListenFor(int key)
34 {
35         listened_keys.erase(key);
36 }
37
38 bool InputHandler::isKeyDown(int key)
39 {
40         return is_down.find(key) != is_down.end();
41 }
42
43 bool InputHandler::wasKeyDown(int key)
44 {
45         return was_down.find(key) != was_down.end();
46 }
47
48 vec2 InputHandler::getCursorDelta()
49 {
50         return cursor_delta;
51 }
52
53 void InputHandler::setWindow(Window *w)
54 {
55         if (! window) {
56                 window = w;
57         }
58 }