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

[#60] avoid if branching for speed up

parent 93fc0e71
No related branches found
No related tags found
1 merge request!65Resolve "Kamera - Steuerung mittels Controller"
...@@ -39,24 +39,19 @@ namespace vkcv::camera { ...@@ -39,24 +39,19 @@ namespace vkcv::camera {
} }
void PilotCameraController::panView(double xOffset, double yOffset, Camera &camera) { void PilotCameraController::panView(double xOffset, double yOffset, Camera &camera) {
// handle yaw rotation // update only if there is (valid) input
float yaw = camera.getYaw() + xOffset; if (xOffset == 0.0 && yOffset == 0.0) {
if (yaw < -180.0f) { return;
yaw += 360.0f;
}
else if (yaw > 180.0f) {
yaw -= 360.0f;
} }
// 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); camera.setYaw(yaw);
// handle pitch rotation // handle pitch rotation
float pitch = camera.getPitch() - yOffset; float pitch = camera.getPitch() - static_cast<float>(yOffset);
if (pitch > 89.0f) { pitch = glm::clamp(pitch, -89.0f, 89.0f);
pitch = 89.0f;
}
if (pitch < -89.0f) {
pitch = -89.0f;
}
camera.setPitch(pitch); camera.setPitch(pitch);
} }
......
...@@ -12,33 +12,23 @@ namespace vkcv::camera { ...@@ -12,33 +12,23 @@ namespace vkcv::camera {
} }
void TrackballCameraController::setRadius(const float radius) { void TrackballCameraController::setRadius(const float radius) {
if (radius < 0.1f) { m_radius = 0.1f * (radius < 0.1f) + radius * (1 - (radius < 0.1f));
m_radius = 0.1f;
}
else {
m_radius = radius;
}
} }
void TrackballCameraController::panView(double xOffset, double yOffset, Camera &camera) { void TrackballCameraController::panView(double xOffset, double yOffset, Camera &camera) {
// handle yaw rotation // update only if there is (valid) input
float yaw = camera.getYaw() + xOffset * m_cameraSpeed; if (xOffset == 0.0 && yOffset == 0.0) {
if (yaw < 0.0f) { return;
yaw += 360.0f;
}
else if (yaw > 360.0f) {
yaw -= 360.0f;
} }
// 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); camera.setYaw(yaw);
// handle pitch rotation // handle pitch rotation
float pitch = camera.getPitch() + yOffset * m_cameraSpeed; float pitch = camera.getPitch() + static_cast<float>(yOffset) * m_cameraSpeed;
if (pitch < 0.0f) { pitch += 360.0f * (pitch < 0.0f) - 360.0f * (pitch > 360.0f);
pitch += 360.0f;
}
else if (pitch > 360.0f) {
pitch -= 360.0f;
}
camera.setPitch(pitch); camera.setPitch(pitch);
} }
......
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