vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
keyboardController.cpp
Go to the documentation of this file.
1#include <cmath>
2
4
5void ven::KeyboardController::moveInPlaneXZ(GLFWwindow* window, float dt, Object& object) const
6{
7 glm::vec3 rotate{0};
8 if (glfwGetKey(window, m_keys.lookLeft) == GLFW_PRESS) { rotate.y -= 1.F; }
9 if (glfwGetKey(window, m_keys.lookRight) == GLFW_PRESS) { rotate.y += 1.F; }
10 if (glfwGetKey(window, m_keys.lookUp) == GLFW_PRESS) { rotate.x += 1.F; }
11 if (glfwGetKey(window, m_keys.lookDown) == GLFW_PRESS) { rotate.x -= 1.F; }
12
13 if (dot(rotate, rotate) > std::numeric_limits<float>::epsilon()) {
14 object.transform3D.rotation += m_lookSpeed * dt * normalize(rotate);
15 }
16
17 object.transform3D.rotation.x = glm::clamp(object.transform3D.rotation.x, -1.5F, 1.5F);
18 object.transform3D.rotation.y = glm::mod(object.transform3D.rotation.y, glm::two_pi<float>());
19
20 float yaw = object.transform3D.rotation.y;
21 const glm::vec3 forwardDir{std::sin(yaw), 0.F, std::cos(yaw)};
22 const glm::vec3 rightDir{forwardDir.z, 0.F, -forwardDir.x};
23 constexpr glm::vec3 upDir{0.F, -1.F, 0.F};
24
25 glm::vec3 moveDir{0.F};
26 if (glfwGetKey(window, m_keys.moveForward) == GLFW_PRESS) {moveDir += forwardDir;}
27 if (glfwGetKey(window, m_keys.moveBackward) == GLFW_PRESS) {moveDir -= forwardDir;}
28 if (glfwGetKey(window, m_keys.moveRight) == GLFW_PRESS) {moveDir += rightDir;}
29 if (glfwGetKey(window, m_keys.moveLeft) == GLFW_PRESS) {moveDir -= rightDir;}
30 if (glfwGetKey(window, m_keys.moveUp) == GLFW_PRESS) {moveDir += upDir;}
31 if (glfwGetKey(window, m_keys.moveDown) == GLFW_PRESS) {moveDir -= upDir;}
32
33 if (dot(moveDir, moveDir) > std::numeric_limits<float>::epsilon()) {
34 object.transform3D.translation += m_moveSpeed * dt * normalize(moveDir);
35 }
36}
void moveInPlaneXZ(GLFWwindow *window, float dt, Object &object) const