camera accelerating like in unity and faster/slower with modifier keys

feature/softbody-runtime-control
Benjamin Kraft 3 months ago
parent 0d847d6694
commit 006cfa2893
  1. 2
      include/camera.hpp
  2. 19
      src/camera.cpp

@ -9,6 +9,8 @@ class Camera : private MouseListener {
private: private:
glm::vec3 position {0, 0, 5}; glm::vec3 position {0, 0, 5};
float velocityMultiplier = 0;
float phi = 0; float phi = 0;
float theta = 0; float theta = 0;

@ -14,13 +14,26 @@ const std::map<int, glm::vec3> moveDirections {
}; };
void Camera::update(float dt) { void Camera::update(float dt) {
glm::vec3 add {}; glm::vec3 velocity {};
for (const auto &[key, dir] : moveDirections) for (const auto &[key, dir] : moveDirections)
if (Input::KeyIsDown[key]) if (Input::KeyIsDown[key])
add += dir; velocity += dir;
position += localToWorld(add) * dt; if (velocity == glm::vec3(0))
velocityMultiplier = 0;
const float baseModifier = 3;
float modifier = 1;
if (Input::KeyIsDown[GLFW_KEY_LEFT_SHIFT])
modifier *= baseModifier;
if (Input::KeyIsDown[GLFW_KEY_LEFT_CONTROL])
modifier /= baseModifier;
velocityMultiplier += modifier * dt;
velocity *= (1 + velocityMultiplier) * modifier;
position += localToWorld(velocity) * dt;
} }
glm::mat4 Camera::view() const { glm::mat4 Camera::view() const {

Loading…
Cancel
Save