summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/followCameraController.cpp12
-rw-r--r--gfx/gl/camera.cpp7
-rw-r--r--gfx/gl/camera.h38
3 files changed, 44 insertions, 13 deletions
diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp
index 42d1666..d15ecda 100644
--- a/gfx/followCameraController.cpp
+++ b/gfx/followCameraController.cpp
@@ -20,20 +20,16 @@ FollowCameraController::updateCamera(Camera * camera) const
switch (mode) {
case Mode::Pan:
- camera->forward = glm::normalize(pos - camera->pos);
- camera->up = up;
+ camera->lookAt(pos);
break;
case Mode::Ride:
- camera->pos = pos + (up * 4.8F);
- camera->forward = !-sincosf(rot.y);
- camera->up = up;
+ camera->setView(pos + (up * 4.8F), !-sincosf(rot.y));
break;
case Mode::ISO:
- camera->pos = pos + ((up + north + east) * 40.F);
- camera->forward = glm::normalize(down + south + west);
- camera->up = glm::normalize(up - north - east);
+ camera->setView(pos + ((up + north + east) * 40.F), glm::normalize(down + south + west),
+ glm::normalize(up - north - east));
break;
}
}
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 7438739..0e81282 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -4,19 +4,20 @@
#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)}
+ position {pos}, forward {::north}, up {::up}, projection {glm::perspective(fov, aspect, zNear, zFar)}
{
}
glm::mat4
Camera::getViewProjection() const
{
- return projection * glm::lookAt(pos, pos + forward, up);
+ return projection * glm::lookAt(position, position + forward, up);
}
Ray
Camera::unProject(const glm::vec2 & mouse) const
{
static constexpr const glm::vec4 screen {0, 0, 1, 1};
- return {pos, glm::normalize(glm::unProject(mouse ^ 1, glm::lookAt(::origin, forward, up), projection, screen))};
+ return {position,
+ 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 e22d23f..d82802f 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -1,6 +1,7 @@
#pragma once
#include <glm/glm.hpp>
+#include <maths.h>
#include <ray.hpp>
class Camera {
@@ -10,10 +11,43 @@ public:
[[nodiscard]] glm::mat4 getViewProjection() const;
[[nodiscard]] Ray unProject(const glm::vec2 &) const;
- glm::vec3 pos;
+ void
+ setPosition(const glm::vec3 & p)
+ {
+ position = p;
+ }
+ void
+ setForward(const glm::vec3 & f)
+ {
+ forward = f;
+ }
+ void
+ setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u = ::up)
+ {
+ position = p;
+ forward = f;
+ up = u;
+ }
+ void
+ lookAt(const glm::vec3 & target)
+ {
+ setForward(glm::normalize(target - position));
+ }
+ [[nodiscard]] auto
+ getForward() const
+ {
+ return forward;
+ }
+ [[nodiscard]] auto
+ getPosition() const
+ {
+ return position;
+ }
+
+private:
+ glm::vec3 position;
glm::vec3 forward;
glm::vec3 up;
-private:
glm::mat4 projection;
};