diff options
Diffstat (limited to 'gfx/gl')
-rw-r--r-- | gfx/gl/camera.cpp | 13 | ||||
-rw-r--r-- | gfx/gl/camera.h | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 82b11a6..f03e85b 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -5,7 +5,7 @@ #include <ray.h> Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNear, GlobalDistance zFar) : - position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, + position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, view {}, projection { glm::perspective(fov, aspect, static_cast<RelativeDistance>(zNear), static_cast<RelativeDistance>(zFar))}, viewProjection {}, inverseViewProjection {} @@ -16,15 +16,18 @@ Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNe Ray<GlobalPosition3D> Camera::unProject(const ScreenRelCoord & mouse) const { - static constexpr const glm::vec4 screen {0, 0, 1, 1}; - const auto mouseProjection = glm::lookAt({}, forward, up); - return {position, glm::normalize(glm::unProject(mouse || 1.F, mouseProjection, projection, screen))}; + static constexpr const glm::vec4 SCREEN {0, 0, 1, 1}; + return { + .start = position, + .direction = glm::normalize(glm::unProject(mouse || 1.F, view, projection, SCREEN)), + }; } void Camera::updateView() { - viewProjection = projection * glm::lookAt({}, forward, up); + view = glm::lookAt({}, forward, up); + viewProjection = projection * view; inverseViewProjection = glm::inverse(viewProjection); } diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 8d53261..5c37744 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -82,6 +82,6 @@ private: Direction3D up; GlobalDistance near, far; - glm::mat4 projection; + glm::mat4 view, projection; glm::mat4 viewProjection, inverseViewProjection; }; |