summaryrefslogtreecommitdiff
path: root/gfx/gl/camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/camera.cpp')
-rw-r--r--gfx/gl/camera.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 15f76c4..a0d76ab 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -1,14 +1,14 @@
#include "camera.h"
#include <collections.h>
-#include <glm/gtx/intersect.hpp> // IWYU pragma: keep
-#include <glm/gtx/transform.hpp> // IWYU pragma: keep
-#include <math.h>
+#include <glm/gtx/transform.hpp>
#include <maths.h>
#include <ray.h>
-Camera::Camera(Position3D pos, Angle fov, Angle aspect, Distance zNear, Distance zFar) :
+Camera::Camera(GlobalPosition3D pos, Angle fov, Angle aspect, GlobalDistance zNear, GlobalDistance zFar) :
position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar},
- projection {glm::perspective(fov, aspect, zNear, zFar)}, viewProjection {}, inverseViewProjection {}
+ projection {
+ glm::perspective(fov, aspect, static_cast<RelativeDistance>(zNear), static_cast<RelativeDistance>(zFar))},
+ viewProjection {}, inverseViewProjection {}
{
updateView();
}
@@ -25,7 +25,7 @@ void
Camera::updateView()
{
viewProjection = projection * glm::lookAt(origin, forward, up);
- inverseViewProjection = glm::inverse(projection * glm::lookAt(position, position + forward, up));
+ inverseViewProjection = glm::inverse(viewProjection);
}
Direction3D
@@ -35,21 +35,21 @@ Camera::upFromForward(const Direction3D & forward)
return glm::cross(forward, right);
}
-std::array<glm::vec4, 4>
-Camera::extentsAtDist(const float dist) const
+std::array<GlobalPosition4D, 4>
+Camera::extentsAtDist(const GlobalDistance dist) const
{
- const auto clampToSeaFloor = [this, dist](const Position3D & target) {
- if (target.z < -1.5F) {
- const auto vec = glm::normalize(target - position);
- constexpr Position3D seafloor {0, 0, -1.5F};
- float outdist {};
- if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) {
- return (vec * outdist + position) ^ outdist;
- }
+ const auto clampToSeaFloor = [this, dist](GlobalPosition3D target) -> GlobalPosition4D {
+ target += position;
+ if (target.z < -1500) {
+ const auto diff = (target - position);
+ const auto something = (-1500 - position.z) / diff.z;
+ return {position + diff * something, dist};
}
- return target ^ dist;
+ return {target, dist};
};
- const auto depth = -(2.F * (dist - near) * far) / (dist * (near - far)) - 1.F;
+ const auto depth = -(2.F * (static_cast<float>(dist - near)) * static_cast<float>(far))
+ / (static_cast<float>(dist) * (static_cast<float>(near - far)))
+ - 1.F;
static constexpr const std::array extents {-1.F, 1.F};
static constexpr const auto cartesianExtents = extents * extents;
return cartesianExtents * [&depth, this, &clampToSeaFloor](const auto & extent) {