summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-28 15:42:50 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-28 15:42:50 +0000
commitde9909df038d1b6bb47bcc82fea5f8dc9dec2491 (patch)
treeb1f1337603c1bda68760d3f5f5147bc345e3e77f /gfx
parentComponent position mouse click check should only match mouse button events (diff)
downloadilt-de9909df038d1b6bb47bcc82fea5f8dc9dec2491.tar.bz2
ilt-de9909df038d1b6bb47bcc82fea5f8dc9dec2491.tar.xz
ilt-de9909df038d1b6bb47bcc82fea5f8dc9dec2491.zip
Initial implementation for being able to click in the main window to select something
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.cpp7
-rw-r--r--gfx/gl/camera.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 5a90d84..905f78e 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -12,3 +12,10 @@ Camera::GetViewProjection() const
{
return projection * glm::lookAt(pos, pos + forward, up);
}
+
+glm::vec3
+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));
+}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 72f699d..1d3f5b3 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -8,6 +8,7 @@ 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;
glm::vec3 pos;
glm::vec3 forward;