summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index ff706e7..5ae5fb0 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -1,4 +1,5 @@
#include "camera.h"
+#include <glm/gtx/intersect.hpp> // IWYU pragma: keep
#include <glm/gtx/transform.hpp> // IWYU pragma: keep
#include <maths.h>
#include <ray.hpp>
@@ -35,6 +36,14 @@ Camera::upFromForward(const glm::vec3 & forward)
std::array<glm::vec3, 4>
Camera::extentsAtDist(const float dist) const
{
+ const auto adjustToSeafloor = [this](glm::vec3 & target) {
+ const auto vec = glm::normalize(target - position);
+ constexpr glm::vec3 seafloor {0, 0, -1.5};
+ float outdist;
+ if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) {
+ target = vec * outdist + position;
+ }
+ };
const auto depth = -(2.f * (dist - near) * far) / (dist * (near - far)) - 1.f;
static constexpr const std::array extents {-1.F, 1.F};
std::array<glm::vec3, 4> out {};
@@ -44,7 +53,11 @@ Camera::extentsAtDist(const float dist) const
const glm::vec4 in {x, y, depth, 1.f};
const auto out = inverseViewProjection * in;
- *outitr++ = out / out.w;
+ *outitr = out / out.w;
+ if (outitr->z < -1.5f) {
+ adjustToSeafloor(*outitr);
+ }
+ outitr++;
}
}
return out;