From 5283c898f008a54a1f275841281e2b7aa685f02c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 17 Feb 2021 00:23:21 +0000 Subject: Disconnect camera control from shader --- application/main.cpp | 3 ++- gfx/camera_controller.h | 3 +-- gfx/followCameraController.cpp | 4 +--- gfx/followCameraController.h | 3 +-- gfx/manualCameraController.cpp | 3 +-- gfx/manualCameraController.h | 3 +-- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/application/main.cpp b/application/main.cpp index 04ff9c0..72da726 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -98,7 +98,8 @@ public: const auto t_passed = std::chrono::duration_cast(t_end - t_start); world.apply(&WorldObject::tick, t_passed); - world.apply(&CameraController::updateCamera, &camera, &shader); + world.apply(&CameraController::updateCamera, &camera); + shader.setView(camera.GetViewProjection()); windows.apply(&Window::Clear, 0.0F, 0.0F, 0.0F, 1.0F); world.apply(&Renderable::render, shader); windows.apply(&Window::SwapBuffers); diff --git a/gfx/camera_controller.h b/gfx/camera_controller.h index cdc70d2..926c93b 100644 --- a/gfx/camera_controller.h +++ b/gfx/camera_controller.h @@ -4,11 +4,10 @@ #include class Camera; -class Shader; class CameraController : public WorldObject { public: - virtual void updateCamera(Camera *, Shader *) const = 0; + virtual void updateCamera(Camera *) const = 0; }; #endif diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp index 0034c3b..4db77cd 100644 --- a/gfx/followCameraController.cpp +++ b/gfx/followCameraController.cpp @@ -12,7 +12,7 @@ FollowCameraController::FollowCameraController(VehicleWPtr t, Mode m) : target(std::move(t)), mode(m) { } void -FollowCameraController::updateCamera(Camera * camera, Shader * shader) const +FollowCameraController::updateCamera(Camera * camera) const { const auto [pos, rot] = [this]() { const auto t {target.lock()}; @@ -37,6 +37,4 @@ FollowCameraController::updateCamera(Camera * camera, Shader * shader) const camera->up = glm::normalize(up - north - east); break; } - - shader->setView(camera->GetViewProjection()); } diff --git a/gfx/followCameraController.h b/gfx/followCameraController.h index d57b59f..ef2000d 100644 --- a/gfx/followCameraController.h +++ b/gfx/followCameraController.h @@ -6,7 +6,6 @@ #include class Camera; -class Shader; class FollowCameraController : public CameraController { public: @@ -15,7 +14,7 @@ public: void tick(TickDuration) override { } - void updateCamera(Camera * camera, Shader * shader) const override; + void updateCamera(Camera * camera) const override; private: VehicleWPtr target; diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp index 36f3312..f8cdbf8 100644 --- a/gfx/manualCameraController.cpp +++ b/gfx/manualCameraController.cpp @@ -48,7 +48,7 @@ ManualCameraController::handleInput(SDL_Event & e) } void -ManualCameraController::updateCamera(Camera * camera, Shader * shader) const +ManualCameraController::updateCamera(Camera * camera) const { if (motion) { if (ctrl) { @@ -59,7 +59,6 @@ ManualCameraController::updateCamera(Camera * camera, Shader * shader) const camera->MoveRight(motion->xrel); camera->SlideForward(motion->yrel); } - shader->setView(camera->GetViewProjection()); motion.reset(); } } diff --git a/gfx/manualCameraController.h b/gfx/manualCameraController.h index 112ec5c..465f31f 100644 --- a/gfx/manualCameraController.h +++ b/gfx/manualCameraController.h @@ -8,7 +8,6 @@ #include class Camera; -class Shader; class ManualCameraController : public CameraController, public InputHandler { public: @@ -16,7 +15,7 @@ public: void tick(TickDuration) override { } - void updateCamera(Camera * camera, Shader * shader) const override; + void updateCamera(Camera * camera) const override; private: bool ctrl {false}, mrb {false}; -- cgit v1.2.3