From 8c6a1d7834bfdca8e970944127d8836773250d12 Mon Sep 17 00:00:00 2001 From: karl Date: Tue, 7 Jan 2020 22:13:47 +0100 Subject: [PATCH] Cleanup: Moving things where they belong --- ECS/Components/MouseLook.h | 4 ++++ ECS/Systems/KeyboardMovementSystem.h | 1 - ECS/Systems/MouseLookSystem.h | 19 ++++++++----------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ECS/Components/MouseLook.h b/ECS/Components/MouseLook.h index a60ed5c..ff9f27e 100644 --- a/ECS/Components/MouseLook.h +++ b/ECS/Components/MouseLook.h @@ -9,6 +9,10 @@ struct MouseLook { explicit MouseLook(float sensitivity) : sensitivity(sensitivity) {} float sensitivity; + + double yaw = 0.0; + + double pitch = 0.0; }; #endif //ECSGAME_MOUSELOOK_H diff --git a/ECS/Systems/KeyboardMovementSystem.h b/ECS/Systems/KeyboardMovementSystem.h index 90a0917..729201d 100644 --- a/ECS/Systems/KeyboardMovementSystem.h +++ b/ECS/Systems/KeyboardMovementSystem.h @@ -58,7 +58,6 @@ class KeyboardMovementSystem : public EntitySystem, public EventSubscribersensitivity; - pitch += yOffset * mouse->sensitivity; + mouse->yaw += xOffset * mouse->sensitivity; + mouse->pitch += yOffset * mouse->sensitivity; }); } void tick(World *pWorld, float deltaTime) override { pWorld->each([&](Entity *ent, ComponentHandle transform, ComponentHandle mouse, ComponentHandle camera) { - if(pitch > 89.0f) - pitch = 89.0f; - if(pitch < -89.0f) - pitch = -89.0f; + if(mouse->pitch > 89.0f) + mouse->pitch = 89.0f; + if(mouse->pitch < -89.0f) + mouse->pitch = -89.0f; glm::mat4x4 newTransform = glm::mat4x4(1.0); - newTransform = glm::rotate(newTransform, glm::radians((float)pitch), transform->right()); - newTransform = glm::rotate(newTransform, glm::radians((float)yaw), glm::vec3(0.0, 1.0, 0.0)); + newTransform = glm::rotate(newTransform, glm::radians((float)mouse->pitch), transform->right()); + newTransform = glm::rotate(newTransform, glm::radians((float)mouse->yaw), glm::vec3(0.0, 1.0, 0.0)); newTransform[3] = transform->matrix[3]; @@ -61,9 +61,6 @@ private: double lastX; double lastY; - double pitch = 0.0; - double yaw = 0.0; - World *myWorld; };