X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2Fcamera.cpp;h=f63785292f5f27505175cec23cdd3dcff8d4c29c;hb=0146c7b7f02ef5d74116546489aee85383bb4969;hp=bc43e04292e233696e0a60b7c5339031f57db912;hpb=dfe661278fe5fd69e821d530d50b78082d19ce54;p=tacos.git diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index bc43e04..f637852 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -5,21 +5,33 @@ namespace tacos { -Camera::Camera(const glm::vec3 &f) -: focus(&f) +Camera::Camera() +: focus(0.0f) , distance(100.0f) -, pitch(1.04719755119659774614f) // π/3 -, yaw(0.0f) { +, orientation(0.52359877559829887307f, 0.0f) { // π/6 } -void Camera::Focus(const glm::vec3 &f) noexcept { - focus = &f; +glm::mat4 Camera::View() const noexcept { + // zero yaw is into the screen, so -Z is the base view direction we're transforming from + // pitch needs to be inverted because we're projecting the distance back + const glm::vec3 position(focus - distance * rotateY(rotateX(glm::vec3(0.0f, 0.0f, -1.0f), -orientation.x), orientation.y)); + return glm::lookAt(position, focus, glm::vec3(0.0f, 1.0f, 0.0f)); } -glm::mat4 Camera::View() const noexcept { - const glm::vec3 position(*focus - distance * rotateY(rotateX(glm::vec3(0.0f, 0.0f, 1.0f), pitch), yaw)); - return glm::lookAt(position, *focus, glm::vec3(0.0f, 1.0f, 0.0f)); +void Camera::Move(const glm::vec3 &delta) noexcept { + focus += rotateY(delta, orientation.y); +} + +void Camera::Rotate(const glm::vec2 &delta) noexcept { + orientation += delta; + orientation.x = glm::clamp(orientation.x, 0.0f, 1.55f); + while (orientation.y > 3.14159265358979323844f) { // π + orientation.y -= 6.28318530717958647688f; // 2π + } + while (orientation.y < -3.14159265358979323844f) { + orientation.y += 6.28318530717958647688f; + } } }