diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-26 21:13:41 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-01-26 21:14:16 +0000 |
commit | ce60561dfdb3d3cb583bcc38cbcb93b9cd1b13a6 (patch) | |
tree | c923445bf3f3452384af00d0b67df2ae2f100f07 /application/main.cpp | |
parent | Better default camera pos (diff) | |
download | ilt-ce60561dfdb3d3cb583bcc38cbcb93b9cd1b13a6.tar.bz2 ilt-ce60561dfdb3d3cb583bcc38cbcb93b9cd1b13a6.tar.xz ilt-ce60561dfdb3d3cb583bcc38cbcb93b9cd1b13a6.zip |
Basic mouse navigation
Diffstat (limited to 'application/main.cpp')
-rw-r--r-- | application/main.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/application/main.cpp b/application/main.cpp index fe81b88..912fa4f 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -82,6 +82,7 @@ public: auto t_start = std::chrono::high_resolution_clock::now(); const auto framelen = std::chrono::milliseconds {1000} / 120; + bool mrb {false}, ctrl {false}; while (isRunning) { while (SDL_PollEvent(&e)) { switch (e.type) { @@ -108,9 +109,50 @@ public: case SDLK_KP_9: camera.RotateY(-0.04); break; + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrl = true; + break; } shader.setView(camera.GetViewProjection()); break; + case SDL_KEYUP: + switch (e.key.keysym.sym) { + case SDLK_LCTRL: + case SDLK_RCTRL: + ctrl = false; + break; + } + break; + case SDL_MOUSEBUTTONDOWN: + switch (e.button.button) { + case SDL_BUTTON_RIGHT: + SDL_SetRelativeMouseMode(SDL_TRUE); + mrb = true; + break; + } + break; + case SDL_MOUSEBUTTONUP: + switch (e.button.button) { + case SDL_BUTTON_RIGHT: + SDL_SetRelativeMouseMode(SDL_FALSE); + mrb = false; + break; + } + break; + case SDL_MOUSEMOTION: + if (mrb) { + if (ctrl) { + camera.RotateY(-0.01F * e.motion.xrel); + camera.Pitch(-0.01F * e.motion.yrel); + } + else { + camera.MoveRight(e.motion.xrel); + camera.SlideForward(e.motion.yrel); + } + shader.setView(camera.GetViewProjection()); + } + break; } } |