diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/inputHandler.h | 13 | ||||
-rw-r--r-- | application/main.cpp | 16 | ||||
-rw-r--r-- | application/manualCameraController.cpp | 65 | ||||
-rw-r--r-- | application/manualCameraController.h | 25 |
4 files changed, 8 insertions, 111 deletions
diff --git a/application/inputHandler.h b/application/inputHandler.h deleted file mode 100644 index bcb900b..0000000 --- a/application/inputHandler.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef INPUT_HANDLER_H -#define INPUT_HANDLER_H - -union SDL_Event; - -class InputHandler { -public: - virtual ~InputHandler() = default; - - virtual bool handleInput(SDL_Event &) = 0; -}; - -#endif diff --git a/application/main.cpp b/application/main.cpp index b2c2a5e..94a3b0f 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,16 +1,16 @@ -#include "game/terrain.h" -#include "gfx/window.h" -#include "inputHandler.h" -#include "manualCameraController.h" #include <SDL2/SDL.h> #include <chrono> #include <collection.hpp> +#include <game/terrain.h> #include <game/world.h> #include <game/worldobject.h> #include <gfx/camera_controller.h> #include <gfx/gl/camera.h> #include <gfx/gl/shader.h> +#include <gfx/inputHandler.h> +#include <gfx/manualCameraController.h> #include <gfx/renderable.h> +#include <gfx/window.h> #include <memory> #include <special_members.hpp> #include <vector> @@ -53,7 +53,7 @@ public: return false; } - void + int run() { Collection<Window> windows; @@ -92,6 +92,8 @@ public: } t_start = t_end; } + + return 0; } private: @@ -111,7 +113,5 @@ private: int main(int, char **) { - std::make_shared<SDL_Application>()->run(); - - return 0; + return std::make_shared<SDL_Application>()->run(); } diff --git a/application/manualCameraController.cpp b/application/manualCameraController.cpp deleted file mode 100644 index 36f3312..0000000 --- a/application/manualCameraController.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "manualCameraController.h" -#include <gfx/gl/camera.h> -#include <gfx/gl/shader.h> - -bool -ManualCameraController::handleInput(SDL_Event & e) -{ - switch (e.type) { - case SDL_KEYDOWN: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = true; - return true; - } - break; - case SDL_KEYUP: - switch (e.key.keysym.sym) { - case SDLK_LCTRL: - case SDLK_RCTRL: - ctrl = false; - return true; - } - break; - case SDL_MOUSEBUTTONDOWN: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_TRUE); - mrb = true; - return true; - } - break; - case SDL_MOUSEBUTTONUP: - switch (e.button.button) { - case SDL_BUTTON_RIGHT: - SDL_SetRelativeMouseMode(SDL_FALSE); - mrb = false; - return true; - } - break; - case SDL_MOUSEMOTION: - if (mrb) { - motion = e.motion; - } - return true; - } - return false; -} - -void -ManualCameraController::updateCamera(Camera * camera, Shader * shader) const -{ - if (motion) { - if (ctrl) { - camera->RotateY(-0.01F * motion->xrel); - camera->Pitch(-0.01F * motion->yrel); - } - else { - camera->MoveRight(motion->xrel); - camera->SlideForward(motion->yrel); - } - shader->setView(camera->GetViewProjection()); - motion.reset(); - } -} diff --git a/application/manualCameraController.h b/application/manualCameraController.h deleted file mode 100644 index 112ec5c..0000000 --- a/application/manualCameraController.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MANUAL_CAMERA_CONTROLLER_H -#define MANUAL_CAMERA_CONTROLLER_H - -#include "game/worldobject.h" -#include "inputHandler.h" -#include <SDL2/SDL.h> -#include <gfx/camera_controller.h> -#include <optional> - -class Camera; -class Shader; - -class ManualCameraController : public CameraController, public InputHandler { -public: - bool handleInput(SDL_Event & e) override; - - void tick(TickDuration) override { } - - void updateCamera(Camera * camera, Shader * shader) const override; - -private: - bool ctrl {false}, mrb {false}; - mutable std::optional<SDL_MouseMotionEvent> motion; -}; -#endif |