Skip to content
Snippets Groups Projects
Verified Commit 51df6be9 authored by Josch Morgenstern's avatar Josch Morgenstern
Browse files

[#60] add normalized panView when using controller

parent 702efda2
No related branches found
No related tags found
1 merge request!65Resolve "Kamera - Steuerung mittels Controller"
Pipeline #25963 passed
...@@ -65,7 +65,7 @@ namespace vkcv::camera { ...@@ -65,7 +65,7 @@ namespace vkcv::camera {
* @param gamepadIndex The gamepad index. * @param gamepadIndex The gamepad index.
* @param camera The camera object. * @param camera The camera object.
*/ */
virtual void gamepadCallback(int gamepadIndex, Camera &camera) = 0; virtual void gamepadCallback(int gamepadIndex, Camera &camera, double frametime) = 0;
}; };
} }
\ No newline at end of file
...@@ -44,6 +44,7 @@ namespace vkcv::camera { ...@@ -44,6 +44,7 @@ namespace vkcv::camera {
double m_lastY; double m_lastY;
double m_inputDelayTimer; double m_inputDelayTimer;
double m_frameTime;
/** /**
* @brief Binds the camera object to the window event handles. * @brief Binds the camera object to the window event handles.
......
...@@ -143,7 +143,7 @@ namespace vkcv::camera { ...@@ -143,7 +143,7 @@ namespace vkcv::camera {
* @param gamepadIndex The gamepad index. * @param gamepadIndex The gamepad index.
* @param camera The camera object. * @param camera The camera object.
*/ */
void gamepadCallback(int gamepadIndex, Camera &camera); void gamepadCallback(int gamepadIndex, Camera &camera, double frametime);
}; };
} }
\ No newline at end of file
...@@ -100,7 +100,7 @@ namespace vkcv::camera { ...@@ -100,7 +100,7 @@ namespace vkcv::camera {
* @param gamepadIndex The gamepad index. * @param gamepadIndex The gamepad index.
* @param camera The camera object. * @param camera The camera object.
*/ */
void gamepadCallback(int gamepadIndex, Camera &camera); void gamepadCallback(int gamepadIndex, Camera &camera, double frametime);
}; };
} }
\ No newline at end of file
...@@ -105,7 +105,7 @@ namespace vkcv::camera { ...@@ -105,7 +105,7 @@ namespace vkcv::camera {
m_inputDelayTimer = (1-triggered)*m_inputDelayTimer + triggered * time; // Only reset timer, if dpad was pressed - is this cheaper than if-clause? m_inputDelayTimer = (1-triggered)*m_inputDelayTimer + triggered * time; // Only reset timer, if dpad was pressed - is this cheaper than if-clause?
} }
getActiveController().gamepadCallback(gamepadIndex, getActiveCamera()); // handle camera rotation, translation getActiveController().gamepadCallback(gamepadIndex, getActiveCamera(), m_frameTime); // handle camera rotation, translation
} }
CameraController& CameraManager::getActiveController() { CameraController& CameraManager::getActiveController() {
...@@ -184,6 +184,7 @@ namespace vkcv::camera { ...@@ -184,6 +184,7 @@ namespace vkcv::camera {
} }
void CameraManager::update(double deltaTime) { void CameraManager::update(double deltaTime) {
m_frameTime = deltaTime;
if (glfwGetWindowAttrib(m_window.getWindow(), GLFW_FOCUSED) == GLFW_TRUE) { if (glfwGetWindowAttrib(m_window.getWindow(), GLFW_FOCUSED) == GLFW_TRUE) {
getActiveController().updateCamera(deltaTime, getActiveCamera()); getActiveController().updateCamera(deltaTime, getActiveCamera());
} }
......
...@@ -130,11 +130,11 @@ namespace vkcv::camera { ...@@ -130,11 +130,11 @@ namespace vkcv::camera {
} }
} }
void PilotCameraController::gamepadCallback(int gamepadIndex, Camera &camera) { void PilotCameraController::gamepadCallback(int gamepadIndex, Camera &camera, double frametime) {
GLFWgamepadstate gamepadState; GLFWgamepadstate gamepadState;
glfwGetGamepadState(gamepadIndex, &gamepadState); glfwGetGamepadState(gamepadIndex, &gamepadState);
float sensitivity = 0.05f; float sensitivity = 100.0f;
double threshold = 0.1; // todo: needs further investigation! double threshold = 0.1; // todo: needs further investigation!
// handle rotations // handle rotations
...@@ -142,9 +142,9 @@ namespace vkcv::camera { ...@@ -142,9 +142,9 @@ namespace vkcv::camera {
double stickRightY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]); double stickRightY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]);
double rightXVal = glm::clamp(std::abs(stickRightX) - threshold, 0.0, 1.0) double rightXVal = glm::clamp(std::abs(stickRightX) - threshold, 0.0, 1.0)
* copysign(1.0, stickRightX) * sensitivity; * copysign(1.0, stickRightX) * sensitivity * frametime;
double rightYVal = glm::clamp(std::abs(stickRightY) - threshold, 0.0, 1.0) double rightYVal = glm::clamp(std::abs(stickRightY) - threshold, 0.0, 1.0)
* copysign(1.0, stickRightY) * sensitivity; * copysign(1.0, stickRightY) * sensitivity * frametime;
panView(rightXVal, rightYVal, camera); panView(rightXVal, rightYVal, camera);
// handle zooming // handle zooming
......
...@@ -98,11 +98,11 @@ namespace vkcv::camera { ...@@ -98,11 +98,11 @@ namespace vkcv::camera {
} }
} }
void TrackballCameraController::gamepadCallback(int gamepadIndex, Camera &camera) { void TrackballCameraController::gamepadCallback(int gamepadIndex, Camera &camera, double frametime) {
GLFWgamepadstate gamepadState; GLFWgamepadstate gamepadState;
glfwGetGamepadState(gamepadIndex, &gamepadState); glfwGetGamepadState(gamepadIndex, &gamepadState);
float sensitivity = 0.025f; float sensitivity = 100.0f;
double threshold = 0.1; // todo: needs further investigation! double threshold = 0.1; // todo: needs further investigation!
// handle rotations // handle rotations
...@@ -111,7 +111,7 @@ namespace vkcv::camera { ...@@ -111,7 +111,7 @@ namespace vkcv::camera {
double rightXVal = glm::clamp((abs(stickRightX)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightX); double rightXVal = glm::clamp((abs(stickRightX)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightX);
double rightYVal = glm::clamp((abs(stickRightY)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightY); double rightYVal = glm::clamp((abs(stickRightY)-threshold), 0.0, 1.0) * std::copysign(1.0, stickRightY);
panView(rightXVal * sensitivity, rightYVal * sensitivity, camera); panView(rightXVal * sensitivity, rightYVal * sensitivity * frametime, camera);
// handle translation // handle translation
double stickLeftY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]); double stickLeftY = static_cast<double>(gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]);
......
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