summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.cpp5
-rw-r--r--gfx/gl/camera.h3
2 files changed, 5 insertions, 3 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 905f78e..c751ba8 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -1,6 +1,7 @@
#include "camera.h"
#include <glm/gtx/transform.hpp> // IWYU pragma: keep
#include <maths.h>
+#include <ray.hpp>
Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) :
pos {pos}, forward {::north}, up {::up}, projection {glm::perspective(fov, aspect, zNear, zFar)}
@@ -13,9 +14,9 @@ Camera::GetViewProjection() const
return projection * glm::lookAt(pos, pos + forward, up);
}
-glm::vec3
+Ray
Camera::unProject(const glm::vec2 & mouse) const
{
static constexpr const glm::vec4 screen {0, 0, 1, 1};
- return glm::normalize(glm::unProject(mouse ^ 1, glm::lookAt(::origin, forward, up), projection, screen));
+ return {pos, glm::normalize(glm::unProject(mouse ^ 1, glm::lookAt(::origin, forward, up), projection, screen))};
}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 9fbb0a1..b4dd0d5 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -1,13 +1,14 @@
#pragma once
#include <glm/glm.hpp>
+#include <ray.hpp>
class Camera {
public:
Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar);
[[nodiscard]] glm::mat4 GetViewProjection() const;
- [[nodiscard]] glm::vec3 unProject(const glm::vec2 &) const;
+ [[nodiscard]] Ray unProject(const glm::vec2 &) const;
glm::vec3 pos;
glm::vec3 forward;