Skip to content
Snippets Groups Projects
Verified Commit 48081157 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[#42] Fixed glfw include, some warnings and corrected Y axis

parent 2a6cdc00
Branches
Tags
1 merge request!35Resolve "Kamera - Trackballkamera"
Pipeline #25674 passed
...@@ -92,7 +92,7 @@ namespace vkcv { ...@@ -92,7 +92,7 @@ namespace vkcv {
* @brief Gets the current field of view of the camera in radians * @brief Gets the current field of view of the camera in radians
* @return[in] The current field of view in radians * @return[in] The current field of view in radians
*/ */
const float getFov() const; float getFov() const;
/** /**
* @brief Sets the field of view of the camera to @p fov in radians * @brief Sets the field of view of the camera to @p fov in radians
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "Camera.hpp" #include "Camera.hpp"
#include "vkcv/Window.hpp" #include "vkcv/Window.hpp"
#include <glfw/glfw3.h>
namespace vkcv { namespace vkcv {
......
...@@ -9,17 +9,17 @@ namespace vkcv { ...@@ -9,17 +9,17 @@ namespace vkcv {
m_center = glm::vec3(0.0f, 0.0f, 0.0f); m_center = glm::vec3(0.0f, 0.0f, 0.0f);
lookAt(m_position, m_center, m_up); lookAt(m_position, m_center, m_up);
glm::vec3 front = glm::normalize(m_center - m_position); glm::vec3 front = glm::normalize(m_center - m_position);
m_pitch = atan2(front.y, sqrt(front.x * front.x + front.z * front.z)); m_pitch = std::atan2(front.y, std::sqrt(front.x * front.x + front.z * front.z));
m_yaw = atan2(front.x, front.z); m_yaw = std::atan2(front.x, front.z);
} }
Camera::~Camera() = default; Camera::~Camera() = default;
void Camera::lookAt(glm::vec3 position, glm::vec3 center, glm::vec3 up){ void Camera::lookAt(glm::vec3 position, glm::vec3 center, glm::vec3 up){
m_view = glm::lookAt(position, center, up); m_position = position;
m_position = position; m_center = center;
m_up = up; m_up = up;
m_center = center; m_view = glm::lookAt(m_position, m_center, m_up);
} }
void Camera::getNearFar( float &near, float &far) const { void Camera::getNearFar( float &near, float &far) const {
...@@ -43,13 +43,12 @@ namespace vkcv { ...@@ -43,13 +43,12 @@ namespace vkcv {
return m_projection * m_view; return m_projection * m_view;
} }
const float Camera::getFov() const { float Camera::getFov() const {
return m_fov; return m_fov;
} }
void Camera::setFov( float fov){ void Camera::setFov( float fov){
m_fov = fov; setPerspective(fov, m_ratio, m_near, m_far);
setPerspective( m_fov, m_ratio, m_near, m_far);
} }
float Camera::getRatio() const { float Camera::getRatio() const {
...@@ -57,29 +56,33 @@ namespace vkcv { ...@@ -57,29 +56,33 @@ namespace vkcv {
} }
void Camera::setRatio(float ratio){ void Camera::setRatio(float ratio){
m_ratio = ratio; setPerspective( m_fov, ratio, m_near, m_far);
setPerspective( m_fov, m_ratio, m_near, m_far);
} }
void Camera::setNearFar( float near, float far){ void Camera::setNearFar(float near, float far){
m_near = near; setPerspective(m_fov, m_ratio, near, far);
m_far = far;
setPerspective(m_fov, m_ratio, m_near, m_far);
} }
void Camera::setPerspective(float fov, float ratio, float near, float far){ void Camera::setPerspective(float fov, float ratio, float near, float far) {
const glm::mat4 y_correction (
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
m_fov = fov; m_fov = fov;
m_ratio = ratio; m_ratio = ratio;
m_near = near; m_near = near;
m_far = far; m_far = far;
m_projection = glm::perspective( m_fov, ratio, m_near, m_far); m_projection = y_correction * glm::perspective(m_fov, m_ratio, m_near, m_far);
} }
glm::vec3 Camera::getFront() const { glm::vec3 Camera::getFront() const {
glm::vec3 direction; glm::vec3 direction;
direction.x = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch)); direction.x = std::sin(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
direction.y = sin(glm::radians(m_pitch)); direction.y = std::sin(glm::radians(m_pitch));
direction.z = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch)); direction.z = std::cos(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
return glm::normalize(direction); return glm::normalize(direction);
} }
......
#include "vkcv/camera/PilotCameraController.hpp" #include "vkcv/camera/PilotCameraController.hpp"
#include <iostream> #include <iostream>
#include <GLFW/glfw3.h>
namespace vkcv { namespace vkcv {
...@@ -26,7 +28,7 @@ namespace vkcv { ...@@ -26,7 +28,7 @@ namespace vkcv {
void PilotCameraController::changeFov(double offset){ void PilotCameraController::changeFov(double offset){
float fov = m_camera->getFov(); float fov = m_camera->getFov();
float fov_range = m_fov_max - m_fov_min; float fov_range = m_fov_max - m_fov_min;
float fov_stepsize = glm::radians(fov_range)/m_fov_nsteps; float fov_stepsize = glm::radians(fov_range) / static_cast<float>(m_fov_nsteps);
fov -= (float) offset*fov_stepsize; fov -= (float) offset*fov_stepsize;
if (fov < glm::radians(m_fov_min)) { if (fov < glm::radians(m_fov_min)) {
fov = glm::radians(m_fov_min); fov = glm::radians(m_fov_min);
...@@ -121,8 +123,9 @@ namespace vkcv { ...@@ -121,8 +123,9 @@ namespace vkcv {
} }
void PilotCameraController::mouseMoveCallback(double x, double y) { void PilotCameraController::mouseMoveCallback(double x, double y) {
float xoffset = x - m_lastX; auto xoffset = static_cast<float>(x - m_lastX);
float yoffset = m_lastY - y; auto yoffset = static_cast<float>(y - m_lastY);
m_lastX = x; m_lastX = x;
m_lastY = y; m_lastY = y;
......
#include "vkcv/camera/TrackballCameraController.hpp" #include "vkcv/camera/TrackballCameraController.hpp"
#include <GLFW/glfw3.h>
namespace vkcv { namespace vkcv {
TrackballCameraController::TrackballCameraController() { TrackballCameraController::TrackballCameraController() {
...@@ -82,8 +84,9 @@ namespace vkcv { ...@@ -82,8 +84,9 @@ namespace vkcv {
} }
void TrackballCameraController::mouseMoveCallback(double x, double y) { void TrackballCameraController::mouseMoveCallback(double x, double y) {
float xoffset = x - m_lastX; auto xoffset = static_cast<float>(x - m_lastX);
float yoffset = m_lastY - y; auto yoffset = static_cast<float>(y - m_lastY);
m_lastX = x; m_lastX = x;
m_lastY = y; m_lastY = y;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment