Skip to content
Snippets Groups Projects
Commit 9300e837 authored by Vanessa Karolek's avatar Vanessa Karolek
Browse files

[#42] add vertical movement via E and Q keys to Camera

Before, the camera object was just able to move along the xz plane. For vertical movement, you have to pan view and then use forward or backward movement to move up or down. This might be not so handy for the user.
Now, you can use E to move up and use Q to move down (both along default world up vector).
parent dab6bc9f
No related branches found
No related tags found
1 merge request!35Resolve "Kamera - Trackballkamera"
Pipeline #25357 passed
...@@ -36,6 +36,8 @@ namespace vkcv { ...@@ -36,6 +36,8 @@ namespace vkcv {
bool m_backward; bool m_backward;
bool m_left; bool m_left;
bool m_right; bool m_right;
bool m_top;
bool m_bottom;
public: public:
...@@ -229,6 +231,18 @@ namespace vkcv { ...@@ -229,6 +231,18 @@ namespace vkcv {
*/ */
void moveRight(int action); void moveRight(int action);
/**
* @brief Indicates top movement of the camera depending on the performed @p action
* @param[in] action The performed action
*/
void moveTop(int action);
/**
* @brief Indicates bottom movement of the camera depending on the performed @p action
* @param[in] action The performed action
*/
void moveBottom(int action);
}; };
} }
...@@ -30,7 +30,7 @@ namespace vkcv{ ...@@ -30,7 +30,7 @@ namespace vkcv{
void bindCamera(); void bindCamera();
/** /**
* @brief A callback function for key events. Currently, camera movement via W, A, S, D and window closure via Escape are supported * @brief A callback function for key events. Currently, 3D camera movement via W, A, S, D, E, Q and window closure via Escape are supported
* @param[in] key The keyboard key * @param[in] key The keyboard key
* @param[in] scancode The platform-specific scancode * @param[in] scancode The platform-specific scancode
* @param[in] action The key action * @param[in] action The key action
......
...@@ -19,6 +19,8 @@ namespace vkcv { ...@@ -19,6 +19,8 @@ namespace vkcv {
m_backward = false; m_backward = false;
m_left = false; m_left = false;
m_right = false; m_right = false;
m_top = false;
m_bottom = false;
} }
Camera::~Camera() = default; Camera::~Camera() = default;
...@@ -163,6 +165,8 @@ namespace vkcv { ...@@ -163,6 +165,8 @@ namespace vkcv {
m_position -= (m_cameraSpeed * getFront() * static_cast<float> (m_backward) * static_cast<float>(deltaTime)); m_position -= (m_cameraSpeed * getFront() * static_cast<float> (m_backward) * static_cast<float>(deltaTime));
m_position -= (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_left) * static_cast<float>(deltaTime)); m_position -= (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_left) * static_cast<float>(deltaTime));
m_position += (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_right) * static_cast<float>(deltaTime)); m_position += (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_right) * static_cast<float>(deltaTime));
m_position -= m_up * m_cameraSpeed * static_cast<float> (m_top) * static_cast<float>(deltaTime);
m_position += m_up * m_cameraSpeed * static_cast<float> (m_bottom) * static_cast<float>(deltaTime);
} }
void Camera::moveForward(int action){ void Camera::moveForward(int action){
...@@ -180,4 +184,12 @@ namespace vkcv { ...@@ -180,4 +184,12 @@ namespace vkcv {
void Camera::moveRight(int action){ void Camera::moveRight(int action){
m_right = static_cast<bool>(action); m_right = static_cast<bool>(action);
} }
void Camera::moveTop(int action){
m_top = static_cast<bool>(action);
}
void Camera::moveBottom(int action){
m_bottom = static_cast<bool>(action);
}
} }
\ No newline at end of file
...@@ -72,6 +72,12 @@ namespace vkcv{ ...@@ -72,6 +72,12 @@ namespace vkcv{
case GLFW_KEY_D: case GLFW_KEY_D:
m_camera.moveRight(action); m_camera.moveRight(action);
break; break;
case GLFW_KEY_E:
m_camera.moveTop(action);
break;
case GLFW_KEY_Q:
m_camera.moveBottom(action);
break;
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(m_window.getWindow(), 1); glfwSetWindowShouldClose(m_window.getWindow(), 1);
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment