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

[#56] Added work-around to trackball camera

parent c6c021b2
No related branches found
No related tags found
1 merge request!45Resolve "Szene-Repräsentation"
Pipeline #26231 passed
......@@ -14,6 +14,8 @@ namespace vkcv::camera {
float m_cameraSpeed;
float m_scrollSensitivity;
float m_radius;
float m_pitch;
float m_yaw;
/**
* @brief Updates the current radius of @p camera in respect to the @p offset.
......
......@@ -50,12 +50,11 @@ namespace vkcv::camera {
}
// handle yaw rotation
float yaw = camera.getYaw() + static_cast<float>(xOffset);
yaw += 360.0f * (yaw < -180.0f) - 360.0f * (yaw > 180.0f);
float yaw = camera.getYaw() + static_cast<float>(xOffset) * m_cameraSpeed;
camera.setYaw(yaw);
// handle pitch rotation
float pitch = camera.getPitch() - static_cast<float>(yOffset);
float pitch = camera.getPitch() - static_cast<float>(yOffset) * m_cameraSpeed;
pitch = glm::clamp(pitch, -89.0f, 89.0f);
camera.setPitch(pitch);
}
......
......@@ -8,6 +8,8 @@ namespace vkcv::camera {
m_radius = 3.0f;
m_cameraSpeed = 2.5f;
m_scrollSensitivity = 0.2f;
m_pitch = 0.0f;
m_yaw = 0.0f;
}
void TrackballCameraController::setRadius(const float radius) {
......@@ -21,14 +23,10 @@ namespace vkcv::camera {
}
// handle yaw rotation
float yaw = camera.getYaw() + static_cast<float>(xOffset) * m_cameraSpeed;
yaw += 360.0f * (yaw < 0.0f) - 360.0f * (yaw > 360.0f);
camera.setYaw(yaw);
m_yaw = m_yaw + static_cast<float>(xOffset) * m_cameraSpeed;
// handle pitch rotation
float pitch = camera.getPitch() + static_cast<float>(yOffset) * m_cameraSpeed;
pitch += 360.0f * (pitch < 0.0f) - 360.0f * (pitch > 360.0f);
camera.setPitch(pitch);
m_pitch = m_pitch + static_cast<float>(yOffset) * m_cameraSpeed;
}
void TrackballCameraController::updateRadius(double offset, Camera &camera) {
......@@ -44,14 +42,11 @@ namespace vkcv::camera {
}
void TrackballCameraController::updateCamera(double deltaTime, Camera &camera) {
float yaw = camera.getYaw();
float pitch = camera.getPitch();
const glm::vec3 yAxis = glm::vec3(0.0f, 1.0f, 0.0f);
const glm::vec3 xAxis = glm::vec3(1.0f, 0.0f, 0.0f);
const glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), glm::radians(yaw), yAxis);
const glm::mat4 rotationX = glm::rotate(rotationY, -glm::radians(pitch), xAxis);
const glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), glm::radians(m_yaw), yAxis);
const glm::mat4 rotationX = glm::rotate(rotationY, -glm::radians(m_pitch), xAxis);
const glm::vec3 translation = glm::vec3(
rotationX * glm::vec4(0.0f, 0.0f, m_radius, 0.0f)
);
......
......@@ -121,7 +121,7 @@ namespace vkcv::scene {
if (!checkFrustum(aabb)) {
m_drawcalls[i].instanceCount = 2;
continue;
//continue;
}
matrices.push_back(transform);
......
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