]> git.localhorst.tv Git - tacos.git/blob - src/app/keymap.cpp
controllable camera
[tacos.git] / src / app / keymap.cpp
1 #include "keymap.hpp"
2
3 #include <stdexcept>
4
5
6 namespace tacos {
7
8 Keymap::Keymap()
9 : codemap{ NONE } {
10
11 }
12
13 void Keymap::Map(SDL_Scancode scancode, Action action) {
14         if (scancode > MAX_SCANCODE) {
15                 throw std::runtime_error("cannot map out of bounds scancode");
16         }
17         codemap[scancode] = action;
18 }
19
20 Keymap::Action Keymap::Lookup(SDL_Scancode scancode) const {
21         if (scancode < NUM_SCANCODES) {
22                 return codemap[scancode];
23         } else {
24                 return NONE;
25         }
26 }
27
28 void Keymap::LoadDefault() {
29         Map(SDL_SCANCODE_ESCAPE, EXIT);
30         Map(SDL_SCANCODE_W, CAMERA_FORWARD);
31         Map(SDL_SCANCODE_S, CAMERA_BACK);
32         Map(SDL_SCANCODE_A, CAMERA_LEFT);
33         Map(SDL_SCANCODE_D, CAMERA_RIGHT);
34         Map(SDL_SCANCODE_Q, CAMERA_YAW_CW);
35         Map(SDL_SCANCODE_E, CAMERA_YAW_CCW);
36         Map(SDL_SCANCODE_INSERT, CAMERA_PITCH_CCW);
37         Map(SDL_SCANCODE_DELETE, CAMERA_PITCH_CW);
38         Map(SDL_SCANCODE_HOME, CAMERA_UP);
39         Map(SDL_SCANCODE_END, CAMERA_DOWN);
40         Map(SDL_SCANCODE_PAGEUP, CAMERA_NEARER);
41         Map(SDL_SCANCODE_PAGEDOWN, CAMERA_FARTHER);
42 }
43
44 }