summaryrefslogtreecommitdiff
path: root/gfx/gl/camera.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 13:51:33 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-26 14:14:13 +0000
commit7fba471728f2216d7e3b7900297fc3b3531e286c (patch)
tree5caef3b2efc23aefccb215ec9005cd8e7d2e91b8 /gfx/gl/camera.cpp
parentFix todo for handling a terrain walk from outside the mesh (diff)
parentModel positions as integers (diff)
downloadilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.bz2
ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.xz
ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.zip
Merge branch 'ints' into terrain
Conflicts fix, compiles, some test failures remain. Trees not added, possibility of OM invalid handle assertion failures, normals broken due to integer overflow in Newell's method.
Diffstat (limited to 'gfx/gl/camera.cpp')
-rw-r--r--gfx/gl/camera.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index c4c9544..15f76c4 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -2,19 +2,19 @@
#include <collections.h>
#include <glm/gtx/intersect.hpp> // IWYU pragma: keep
#include <glm/gtx/transform.hpp> // IWYU pragma: keep
+#include <math.h>
#include <maths.h>
#include <ray.h>
-Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) :
+Camera::Camera(Position3D pos, Angle fov, Angle aspect, Distance zNear, Distance zFar) :
position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar},
- projection {glm::perspective(fov, aspect, zNear, zFar)},
- viewProjection {projection * glm::lookAt(position, position + forward, up)},
- inverseViewProjection {glm::inverse(viewProjection)}
+ projection {glm::perspective(fov, aspect, zNear, zFar)}, viewProjection {}, inverseViewProjection {}
{
+ updateView();
}
Ray
-Camera::unProject(const glm::vec2 & mouse) const
+Camera::unProject(const ScreenRelCoord & mouse) const
{
static constexpr const glm::vec4 screen {0, 0, 1, 1};
const auto mouseProjection = glm::lookAt(::origin, forward, up);
@@ -24,12 +24,12 @@ Camera::unProject(const glm::vec2 & mouse) const
void
Camera::updateView()
{
- viewProjection = projection * glm::lookAt(position, position + forward, up);
- inverseViewProjection = glm::inverse(viewProjection);
+ viewProjection = projection * glm::lookAt(origin, forward, up);
+ inverseViewProjection = glm::inverse(projection * glm::lookAt(position, position + forward, up));
}
-glm::vec3
-Camera::upFromForward(const glm::vec3 & forward)
+Direction3D
+Camera::upFromForward(const Direction3D & forward)
{
const auto right = glm::cross(forward, ::down);
return glm::cross(forward, right);
@@ -38,11 +38,11 @@ Camera::upFromForward(const glm::vec3 & forward)
std::array<glm::vec4, 4>
Camera::extentsAtDist(const float dist) const
{
- const auto clampToSeaFloor = [this, dist](const glm::vec3 & target) {
+ const auto clampToSeaFloor = [this, dist](const Position3D & target) {
if (target.z < -1.5F) {
const auto vec = glm::normalize(target - position);
- constexpr glm::vec3 seafloor {0, 0, -1.5F};
- float outdist;
+ constexpr Position3D seafloor {0, 0, -1.5F};
+ float outdist {};
if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) {
return (vec * outdist + position) ^ outdist;
}