diff --git a/modules/camera/src/vkcv/camera/PilotCameraController.cpp b/modules/camera/src/vkcv/camera/PilotCameraController.cpp index 8f3e65b69776c2a18f937a35fbbebace4e44e93b..faea9c1917ea909eea4ca3303e5ec843b1738f44 100644 --- a/modules/camera/src/vkcv/camera/PilotCameraController.cpp +++ b/modules/camera/src/vkcv/camera/PilotCameraController.cpp @@ -39,24 +39,19 @@ namespace vkcv::camera { } void PilotCameraController::panView(double xOffset, double yOffset, Camera &camera) { - // handle yaw rotation - float yaw = camera.getYaw() + xOffset; - if (yaw < -180.0f) { - yaw += 360.0f; - } - else if (yaw > 180.0f) { - yaw -= 360.0f; + // update only if there is (valid) input + if (xOffset == 0.0 && yOffset == 0.0) { + return; } + + // handle yaw rotation + float yaw = camera.getYaw() + static_cast<float>(xOffset); + yaw += 360.0f * (yaw < -180.0f) - 360.0f * (yaw > 180.0f); camera.setYaw(yaw); // handle pitch rotation - float pitch = camera.getPitch() - yOffset; - if (pitch > 89.0f) { - pitch = 89.0f; - } - if (pitch < -89.0f) { - pitch = -89.0f; - } + float pitch = camera.getPitch() - static_cast<float>(yOffset); + pitch = glm::clamp(pitch, -89.0f, 89.0f); camera.setPitch(pitch); } diff --git a/modules/camera/src/vkcv/camera/TrackballCameraController.cpp b/modules/camera/src/vkcv/camera/TrackballCameraController.cpp index 81a7e1d65309af2a7965914708e5e3aaf3fc973d..5d6a3859ee3c428ac01161064fb6f7d0a98b94d3 100644 --- a/modules/camera/src/vkcv/camera/TrackballCameraController.cpp +++ b/modules/camera/src/vkcv/camera/TrackballCameraController.cpp @@ -12,33 +12,23 @@ namespace vkcv::camera { } void TrackballCameraController::setRadius(const float radius) { - if (radius < 0.1f) { - m_radius = 0.1f; - } - else { - m_radius = radius; - } + m_radius = 0.1f * (radius < 0.1f) + radius * (1 - (radius < 0.1f)); } void TrackballCameraController::panView(double xOffset, double yOffset, Camera &camera) { - // handle yaw rotation - float yaw = camera.getYaw() + xOffset * m_cameraSpeed; - if (yaw < 0.0f) { - yaw += 360.0f; - } - else if (yaw > 360.0f) { - yaw -= 360.0f; + // update only if there is (valid) input + if (xOffset == 0.0 && yOffset == 0.0) { + return; } + + // 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); // handle pitch rotation - float pitch = camera.getPitch() + yOffset * m_cameraSpeed; - if (pitch < 0.0f) { - pitch += 360.0f; - } - else if (pitch > 360.0f) { - pitch -= 360.0f; - } + float pitch = camera.getPitch() + static_cast<float>(yOffset) * m_cameraSpeed; + pitch += 360.0f * (pitch < 0.0f) - 360.0f * (pitch > 360.0f); camera.setPitch(pitch); }