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

[#106] Refactored some of the Camera code

parent 898a2709
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
Pipeline #26742 passed
......@@ -29,42 +29,6 @@ namespace vkcv::camera {
float m_fov_min;
float m_fov_max;
/**
* @brief Indicates forward movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveForward(int action);
/**
* @brief Indicates backward movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveBackward(int action);
/**
* @brief Indicates left movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveLeft(int action);
/**
* @brief Indicates right movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveRight(int action);
/**
* @brief Indicates upward movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveUpward(int action);
/**
* @brief Indicates downward movement of the camera depending on the performed @p action.
* @param[in] action The performed action.
*/
void moveDownward(int action);
public:
/**
......
......@@ -52,8 +52,8 @@ namespace vkcv::camera {
}
void CameraManager::mouseMoveCallback(double x, double y){
auto xoffset = static_cast<float>(x - m_lastX);
auto yoffset = static_cast<float>(y - m_lastY);
auto xoffset = static_cast<float>(x - m_lastX) / m_window.getWidth();
auto yoffset = static_cast<float>(y - m_lastY) / m_window.getHeight();
m_lastX = x;
m_lastY = y;
getActiveController().mouseMoveCallback(xoffset, yoffset, getActiveCamera());
......
......@@ -50,11 +50,11 @@ namespace vkcv::camera {
}
// handle yaw rotation
float yaw = camera.getYaw() + static_cast<float>(xOffset) * m_cameraSpeed;
float yaw = camera.getYaw() + static_cast<float>(xOffset) * 90.0f * m_cameraSpeed;
camera.setYaw(yaw);
// handle pitch rotation
float pitch = camera.getPitch() - static_cast<float>(yOffset) * m_cameraSpeed;
float pitch = camera.getPitch() - static_cast<float>(yOffset) * 90.0f * m_cameraSpeed;
pitch = glm::clamp(pitch, -89.0f, 89.0f);
camera.setPitch(pitch);
}
......@@ -82,22 +82,22 @@ namespace vkcv::camera {
void PilotCameraController::keyCallback(int key, int scancode, int action, int mods, Camera &camera) {
switch (key) {
case GLFW_KEY_W:
moveForward(action);
m_forward = static_cast<bool>(action);
break;
case GLFW_KEY_S:
moveBackward(action);
m_backward = static_cast<bool>(action);
break;
case GLFW_KEY_A:
moveLeft(action);
m_left = static_cast<bool>(action);
break;
case GLFW_KEY_D:
moveRight(action);
m_right = static_cast<bool>(action);
break;
case GLFW_KEY_E:
moveUpward(action);
m_upward = static_cast<bool>(action);
break;
case GLFW_KEY_Q:
moveDownward(action);
m_downward = static_cast<bool>(action);
break;
default:
break;
......@@ -109,24 +109,18 @@ namespace vkcv::camera {
}
void PilotCameraController::mouseMoveCallback(double xoffset, double yoffset, Camera &camera) {
if(!m_rotationActive){
return;
}
float sensitivity = 0.05f;
xoffset *= sensitivity;
yoffset *= sensitivity;
xoffset *= static_cast<float>(m_rotationActive);
yoffset *= static_cast<float>(m_rotationActive);
panView(xoffset , yoffset, camera);
}
void PilotCameraController::mouseButtonCallback(int button, int action, int mods, Camera &camera) {
if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == false && action == GLFW_PRESS){
m_rotationActive = true;
}
else if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == true && action == GLFW_RELEASE){
m_rotationActive = false;
}
if (button == GLFW_MOUSE_BUTTON_2) {
if (m_rotationActive != (action == GLFW_PRESS)) {
m_rotationActive = (action == GLFW_PRESS);
}
}
}
void PilotCameraController::gamepadCallback(int gamepadIndex, Camera &camera, double frametime) {
......@@ -162,29 +156,4 @@ namespace vkcv::camera {
* -copysign(1.0, stickLeftX);
}
void PilotCameraController::moveForward(int action){
m_forward = static_cast<bool>(action);
}
void PilotCameraController::moveBackward(int action){
m_backward = static_cast<bool>(action);
}
void PilotCameraController::moveLeft(int action){
m_left = static_cast<bool>(action);
}
void PilotCameraController::moveRight(int action){
m_right = static_cast<bool>(action);
}
void PilotCameraController::moveUpward(int action){
m_upward = static_cast<bool>(action);
}
void PilotCameraController::moveDownward(int action){
m_downward = static_cast<bool>(action);
}
}
\ No newline at end of file
......@@ -23,10 +23,10 @@ namespace vkcv::camera {
}
// handle yaw rotation
m_yaw = m_yaw + static_cast<float>(xOffset) * m_cameraSpeed;
m_yaw = m_yaw + static_cast<float>(xOffset) * 90.0f * m_cameraSpeed;
// handle pitch rotation
m_pitch = m_pitch + static_cast<float>(yOffset) * m_cameraSpeed;
m_pitch = m_pitch + static_cast<float>(yOffset) * 90.0f * m_cameraSpeed;
}
void TrackballCameraController::updateRadius(double offset, Camera &camera) {
......@@ -67,15 +67,10 @@ namespace vkcv::camera {
}
void TrackballCameraController::mouseMoveCallback(double xoffset, double yoffset, Camera &camera) {
if(!m_rotationActive){
return;
}
float sensitivity = 0.025f;
xoffset *= sensitivity;
yoffset *= sensitivity;
xoffset *= static_cast<float>(m_rotationActive);
yoffset *= static_cast<float>(m_rotationActive);
panView(xoffset , yoffset, camera);
panView(xoffset, yoffset, camera);
}
void TrackballCameraController::mouseButtonCallback(int button, int action, int mods, Camera &camera) {
......
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