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

[#42][Fix] fix up vector, camera coordinate system, depth

Vulkan uses a left handed coordinate system. Thus, we need to define GLM_FORCE_LEFT_HANDED and adjust left and right movement of the camera.

We also need to define GLM_DEPTH_ZERO_TO_ONE for the depth values which range between 0 and 1 in Vulkan.

Although the up vector is pointing upwards again, it seems that the rendered scene is not flipped along y axis... is this correct?
parent 9fed028f
No related branches found
No related tags found
1 merge request!35Resolve "Kamera - Trackballkamera"
Pipeline #25475 passed
#pragma once
#define GLM_DEPTH_ZERO_TO_ONE
#define GLM_FORCE_LEFT_HANDED
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>
......
......@@ -67,10 +67,10 @@ namespace vkcv{
* @param[in] window The window
* @param[in] width The width of the window
* @param[in] height The height of the window
* @param[in] up The up vector of the camera. Per default: @code{.cpp} up = glm::vec3(0.0f, -1.0f, 0.0f) @endcode
* @param[in] up The up vector of the camera. Per default: @code{.cpp} up = glm::vec3(0.0f, 1.0f, 0.0f) @endcode
* @param[in] position The position of the camera. Per default: @code{.cpp} position = glm::vec3(0.0f,0.0f,0.0f) @endcode
*/
CameraManager(Window &window, float width, float height, glm::vec3 up = glm::vec3(0.0f,-1.0f,0.0f), glm::vec3 position = glm::vec3(0.0f,0.0f,0.0f));
CameraManager(Window &window, float width, float height, glm::vec3 up = glm::vec3(0.0f,1.0f,0.0f), glm::vec3 position = glm::vec3(0.0f,0.0f,0.0f));
/**
* @brief Gets the camera object
......
......@@ -4,7 +4,7 @@
namespace vkcv {
Camera::Camera(){
m_up = glm::vec3(0.0f, -1.0f, 0.0f);
m_up = glm::vec3(0.0f, 1.0f, 0.0f);
m_position = glm::vec3(0.0f, 0.0f, 0.0f);
m_cameraSpeed = 2.f;
......@@ -154,8 +154,8 @@ namespace vkcv {
void Camera::updatePosition(double deltaTime ){
m_position += (m_cameraSpeed * getFront() * static_cast<float> (m_forward) * 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_right) * 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 -= 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);
}
......
......@@ -58,7 +58,6 @@ namespace vkcv{
}
void CameraManager::keyCallback(int key, int scancode, int action, int mods) {
switch (key) {
case GLFW_KEY_W:
m_camera.moveForward(action);
......@@ -85,6 +84,7 @@ namespace vkcv{
break;
}
}
Camera& CameraManager::getCamera(){
return m_camera;
}
......
......@@ -68,8 +68,8 @@ namespace vkcv {
}
void TrackballCamera::updatePosition(double deltaTime) {
glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), glm::radians(m_yaw), glm::vec3(0.0f, -1.0f, 0.0f));
glm::mat4 rotationX = glm::rotate(rotationY, -glm::radians(m_pitch), glm::vec3(1.0f, 0.0f, 0.0f));
glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), glm::radians(m_yaw), glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 rotationX = glm::rotate(rotationY, glm::radians(m_pitch), glm::vec3(1.0f, 0.0f, 0.0f));
glm::vec3 translate = glm::vec3(0.0f,0.0f,m_radius);
translate = glm::vec3(rotationX * glm::vec4(translate, 0.0f));
m_position = m_center + translate;
......
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