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

[#42] remove window and camera from PilotCameraController

parent 0e7d48c8
No related branches found
No related tags found
1 merge request!35Resolve "Kamera - Trackballkamera"
...@@ -31,14 +31,14 @@ namespace vkcv { ...@@ -31,14 +31,14 @@ namespace vkcv {
* @param[in] deltaTime The time that has passed since last update. * @param[in] deltaTime The time that has passed since last update.
* @return The updated camera position. * @return The updated camera position.
*/ */
glm::vec3 updatePosition(double deltaTime); glm::vec3 updatePosition(double deltaTime, Camera &camera);
/** /**
* @brief Updates the view matrix of the camera with respect to @p deltaTime. * @brief Updates the view matrix of the camera with respect to @p deltaTime.
* @param deltaTime The time that has passed since last update. * @param deltaTime The time that has passed since last update.
* @return The updated view matrix of the camera. * @return The updated view matrix of the camera.
*/ */
glm::mat4 updateView(double deltaTime); glm::mat4 updateView(double deltaTime, Camera &camera);
/** /**
* @brief Indicates forward movement of the camera depending on the performed @p action. * @brief Indicates forward movement of the camera depending on the performed @p action.
...@@ -92,7 +92,7 @@ namespace vkcv { ...@@ -92,7 +92,7 @@ namespace vkcv {
* @brief Changes the field of view of the camera with an @p offset in degrees. * @brief Changes the field of view of the camera with an @p offset in degrees.
* @param[in] offset The offset in degrees. * @param[in] offset The offset in degrees.
*/ */
void changeFov(double offset); void changeFov(double offset, Camera &camera);
/** /**
* @brief Pans the view of the camera according to the pitch and yaw values and additional offsets @p xOffset * @brief Pans the view of the camera according to the pitch and yaw values and additional offsets @p xOffset
...@@ -100,19 +100,13 @@ namespace vkcv { ...@@ -100,19 +100,13 @@ namespace vkcv {
* @param[in] xOffset The offset added to the yaw value. * @param[in] xOffset The offset added to the yaw value.
* @param[in] yOffset The offset added to the pitch value. * @param[in] yOffset The offset added to the pitch value.
*/ */
void panView(double xOffset, double yOffset); void panView(double xOffset, double yOffset, Camera &camera);
/**
* @brief Sets @p camera as the new camera object.
* @param camera The new camera object.
*/
virtual void setCamera(Camera &camera);
/** /**
* @brief Updates the camera object in respect to @p deltaTime. * @brief Updates the camera object in respect to @p deltaTime.
* @param deltaTime The time that has passed since last update. * @param deltaTime The time that has passed since last update.
*/ */
void updateCamera(double deltaTime); void updateCamera(double deltaTime, Camera &camera);
/** /**
* @brief A callback function for key events. Currently, 3D camera movement via W, A, S, D, E, Q are supported. * @brief A callback function for key events. Currently, 3D camera movement via W, A, S, D, E, Q are supported.
...@@ -121,7 +115,7 @@ namespace vkcv { ...@@ -121,7 +115,7 @@ namespace vkcv {
* @param[in] action The key action. * @param[in] action The key action.
* @param[in] mods The modifier bits. * @param[in] mods The modifier bits.
*/ */
void keyCallback(int key, int scancode, int action, int mods); void keyCallback(int key, int scancode, int action, int mods, Camera &camera);
/** /**
* @brief A callback function for mouse scrolling events. Currently, this leads to changes in the field of view * @brief A callback function for mouse scrolling events. Currently, this leads to changes in the field of view
...@@ -129,7 +123,7 @@ namespace vkcv { ...@@ -129,7 +123,7 @@ namespace vkcv {
* @param[in] offsetX The offset in horizontal direction. * @param[in] offsetX The offset in horizontal direction.
* @param[in] offsetY The offset in vertical direction. * @param[in] offsetY The offset in vertical direction.
*/ */
void scrollCallback( double offsetX, double offsetY); void scrollCallback(double offsetX, double offsetY, Camera &camera);
/** /**
* @brief A callback function for mouse movement events. Currently, this leads to panning the view of the camera, * @brief A callback function for mouse movement events. Currently, this leads to panning the view of the camera,
...@@ -137,7 +131,7 @@ namespace vkcv { ...@@ -137,7 +131,7 @@ namespace vkcv {
* @param[in] x The horizontal mouse position * @param[in] x The horizontal mouse position
* @param[in] y The vertical mouse position * @param[in] y The vertical mouse position
*/ */
void mouseMoveCallback(double x, double y); void mouseMoveCallback(double x, double y, Camera &camera);
/** /**
* @brief A callback function for mouse button events. Currently, the right mouse button enables panning the * @brief A callback function for mouse button events. Currently, the right mouse button enables panning the
...@@ -146,7 +140,7 @@ namespace vkcv { ...@@ -146,7 +140,7 @@ namespace vkcv {
* @param[in] action The button action * @param[in] action The button action
* @param[in] mods The modifier bits * @param[in] mods The modifier bits
*/ */
void mouseButtonCallback(int button, int action, int mods); void mouseButtonCallback(int button, int action, int mods, Camera &camera);
}; };
} }
\ No newline at end of file
...@@ -20,13 +20,10 @@ namespace vkcv { ...@@ -20,13 +20,10 @@ namespace vkcv {
m_fov_nsteps = 100; m_fov_nsteps = 100;
m_fov_min = 10; m_fov_min = 10;
m_fov_max = 120; m_fov_max = 120;
m_lastX = 0.0;
m_lastY = 0.0;
} }
void PilotCameraController::changeFov(double offset){ void PilotCameraController::changeFov(double offset, Camera &camera){
float fov = m_camera->getFov(); float fov = camera.getFov();
float fov_range = m_fov_max - m_fov_min; float fov_range = m_fov_max - m_fov_min;
float fov_stepsize = glm::radians(fov_range) / static_cast<float>(m_fov_nsteps); float fov_stepsize = glm::radians(fov_range) / static_cast<float>(m_fov_nsteps);
fov -= (float) offset*fov_stepsize; fov -= (float) offset*fov_stepsize;
...@@ -36,64 +33,59 @@ namespace vkcv { ...@@ -36,64 +33,59 @@ namespace vkcv {
if (fov > glm::radians(m_fov_max)) { if (fov > glm::radians(m_fov_max)) {
fov = glm::radians(m_fov_max); fov = glm::radians(m_fov_max);
} }
m_camera->setFov(fov); camera.setFov(fov);
} }
void PilotCameraController::panView(double xOffset, double yOffset) { void PilotCameraController::panView(double xOffset, double yOffset, Camera &camera) {
// handle yaw rotation // handle yaw rotation
float yaw = m_camera->getYaw() + xOffset; float yaw = camera.getYaw() + xOffset;
if (yaw < -180.0f) { if (yaw < -180.0f) {
yaw += 360.0f; yaw += 360.0f;
} }
else if (yaw > 180.0f) { else if (yaw > 180.0f) {
yaw -= 360.0f; yaw -= 360.0f;
} }
m_camera->setYaw(yaw); camera.setYaw(yaw);
// handle pitch rotation // handle pitch rotation
float pitch = m_camera->getPitch() - yOffset; float pitch = camera.getPitch() - yOffset;
if (pitch > 89.0f) { if (pitch > 89.0f) {
pitch = 89.0f; pitch = 89.0f;
} }
if (pitch < -89.0f) { if (pitch < -89.0f) {
pitch = -89.0f; pitch = -89.0f;
} }
m_camera->setPitch(pitch); camera.setPitch(pitch);
} }
glm::mat4 PilotCameraController::updateView(double deltaTime){ glm::mat4 PilotCameraController::updateView(double deltaTime, Camera &camera){
updatePosition(deltaTime); updatePosition(deltaTime, camera);
glm::vec3 position = m_camera->getPosition(); glm::vec3 position = camera.getPosition();
glm::vec3 front = m_camera->getFront(); glm::vec3 front = camera.getFront();
glm::vec3 up = m_camera->getUp(); glm::vec3 up = camera.getUp();
m_camera->lookAt(position, position + front, up); camera.lookAt(position, position + front, up);
return m_camera->getView(); return camera.getView();
} }
glm::vec3 PilotCameraController::updatePosition(double deltaTime ){ glm::vec3 PilotCameraController::updatePosition(double deltaTime, Camera &camera){
glm::vec3 position = m_camera->getPosition(); glm::vec3 position = camera.getPosition();
glm::vec3 front = m_camera->getFront(); glm::vec3 front = camera.getFront();
glm::vec3 up = m_camera->getUp(); glm::vec3 up = camera.getUp();
position += (m_cameraSpeed * front * static_cast<float> (m_forward) * static_cast<float>(deltaTime)); position += (m_cameraSpeed * front * static_cast<float> (m_forward) * static_cast<float>(deltaTime));
position -= (m_cameraSpeed * front * static_cast<float> (m_backward) * static_cast<float>(deltaTime)); position -= (m_cameraSpeed * front * static_cast<float> (m_backward) * static_cast<float>(deltaTime));
position += (glm::normalize(glm::cross(front, up)) * m_cameraSpeed * static_cast<float> (m_left) * static_cast<float>(deltaTime)); position += (glm::normalize(glm::cross(front, up)) * m_cameraSpeed * static_cast<float> (m_left) * static_cast<float>(deltaTime));
position -= (glm::normalize(glm::cross(front, up)) * m_cameraSpeed * static_cast<float> (m_right) * static_cast<float>(deltaTime)); position -= (glm::normalize(glm::cross(front, up)) * m_cameraSpeed * static_cast<float> (m_right) * static_cast<float>(deltaTime));
position -= up * m_cameraSpeed * static_cast<float> (m_upward) * static_cast<float>(deltaTime); position -= up * m_cameraSpeed * static_cast<float> (m_upward) * static_cast<float>(deltaTime);
position += up * m_cameraSpeed * static_cast<float> (m_downward) * static_cast<float>(deltaTime); position += up * m_cameraSpeed * static_cast<float> (m_downward) * static_cast<float>(deltaTime);
m_camera->setPosition(position); camera.setPosition(position);
return position; return position;
} }
void PilotCameraController::setCamera(Camera &camera) { void PilotCameraController::updateCamera(double deltaTime, Camera &camera) {
m_camera = &camera; updateView(deltaTime, camera);
m_camera->setYaw(180.0f);
}
void PilotCameraController::updateCamera(double deltaTime) {
updateView(deltaTime);
} }
void PilotCameraController::keyCallback(int key, int scancode, int action, int mods) { void PilotCameraController::keyCallback(int key, int scancode, int action, int mods, Camera &camera) {
switch (key) { switch (key) {
case GLFW_KEY_W: case GLFW_KEY_W:
moveForward(action); moveForward(action);
...@@ -118,17 +110,11 @@ namespace vkcv { ...@@ -118,17 +110,11 @@ namespace vkcv {
} }
} }
void PilotCameraController::scrollCallback(double offsetX, double offsetY) { void PilotCameraController::scrollCallback(double offsetX, double offsetY, Camera &camera) {
changeFov(offsetY); changeFov(offsetY, camera);
} }
void PilotCameraController::mouseMoveCallback(double x, double y) { void PilotCameraController::mouseMoveCallback(double xoffset, double yoffset, Camera &camera) {
auto xoffset = static_cast<float>(x - m_lastX);
auto yoffset = static_cast<float>(y - m_lastY);
m_lastX = x;
m_lastY = y;
if(!m_rotationActive){ if(!m_rotationActive){
return; return;
} }
...@@ -137,16 +123,14 @@ namespace vkcv { ...@@ -137,16 +123,14 @@ namespace vkcv {
xoffset *= sensitivity; xoffset *= sensitivity;
yoffset *= sensitivity; yoffset *= sensitivity;
panView(xoffset , yoffset); panView(xoffset , yoffset, camera);
} }
void PilotCameraController::mouseButtonCallback(int button, int action, int mods) { void PilotCameraController::mouseButtonCallback(int button, int action, int mods, Camera &camera) {
if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == false && action == GLFW_PRESS){ if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == false && action == GLFW_PRESS){
glfwSetInputMode(m_window->getWindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
m_rotationActive = true; m_rotationActive = true;
} }
else if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == true && action == GLFW_RELEASE){ else if(button == GLFW_MOUSE_BUTTON_2 && m_rotationActive == true && action == GLFW_RELEASE){
glfwSetInputMode(m_window->getWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
m_rotationActive = false; m_rotationActive = false;
} }
} }
......
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