From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- gfx/gl/camera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index c4c9544..80feab4 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -5,7 +5,7 @@ #include #include -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)}, @@ -14,7 +14,7 @@ Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) } 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); -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- gfx/gl/camera.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 80feab4..6a0359c 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -2,6 +2,7 @@ #include #include // IWYU pragma: keep #include // IWYU pragma: keep +#include #include #include @@ -28,8 +29,8 @@ Camera::updateView() inverseViewProjection = glm::inverse(viewProjection); } -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 +39,11 @@ Camera::upFromForward(const glm::vec3 & forward) std::array 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; } -- cgit v1.2.3 From 356e874050e5ad5af87b04a2bb01ce34a86640bb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 13 Nov 2023 00:17:11 +0000 Subject: Send position and rotation matrix to GPU separately --- gfx/gl/camera.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 6a0359c..15f76c4 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -8,10 +8,9 @@ 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 @@ -25,8 +24,8 @@ Camera::unProject(const ScreenRelCoord & 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)); } Direction3D -- cgit v1.2.3 From daed922f23daa8a8e2659d8aea7864cccd5e08c7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 11 Dec 2023 20:11:23 +0000 Subject: Integer camera --- gfx/gl/camera.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'gfx/gl/camera.cpp') 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 -#include // IWYU pragma: keep -#include // IWYU pragma: keep -#include +#include #include #include -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(zNear), static_cast(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 -Camera::extentsAtDist(const float dist) const +std::array +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(dist - near)) * static_cast(far)) + / (static_cast(dist) * (static_cast(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) { -- cgit v1.2.3 From 04f42212ba67ec7d8160bf4a19c0b1283aec69bc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 11 Dec 2023 20:49:52 +0000 Subject: Fix clamping to seafloor and add specific test --- gfx/gl/camera.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index a0d76ab..ff4c91e 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -41,9 +41,9 @@ Camera::extentsAtDist(const GlobalDistance dist) const 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}; + const auto diff = target - position; + const auto limit = -1500 - position.z; + return {position + (limit * diff) / diff.z, (limit * dist) / diff.z}; } return {target, dist}; }; -- cgit v1.2.3 From 512a47b2b8a7248b640441a828c2ea5f97dc385f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Dec 2023 18:57:15 +0000 Subject: Use new calc types in camera extents to address overflow --- gfx/gl/camera.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index ff4c91e..06e409e 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -41,9 +41,9 @@ Camera::extentsAtDist(const GlobalDistance dist) const const auto clampToSeaFloor = [this, dist](GlobalPosition3D target) -> GlobalPosition4D { target += position; if (target.z < -1500) { - const auto diff = target - position; - const auto limit = -1500 - position.z; - return {position + (limit * diff) / diff.z, (limit * dist) / diff.z}; + const CalcPosition3D diff = target - position; + const CalcDistance limit = -1500 - position.z; + return {position + GlobalPosition3D((limit * diff) / diff.z), (limit * dist) / diff.z}; } return {target, dist}; }; -- cgit v1.2.3 From 048f18e2a0b32044525cef41fa053984433c74b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 14:12:40 +0000 Subject: Remove misleading power operator^ on vec2/3 --- gfx/gl/camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 06e409e..9f40998 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -18,7 +18,7 @@ Camera::unProject(const ScreenRelCoord & mouse) const { static constexpr const glm::vec4 screen {0, 0, 1, 1}; const auto mouseProjection = glm::lookAt(::origin, forward, up); - return {position, glm::normalize(glm::unProject(mouse ^ 1, mouseProjection, projection, screen))}; + return {position, glm::normalize(glm::unProject(mouse || 1.F, mouseProjection, projection, screen))}; } void -- cgit v1.2.3 From 69e6b7d2d349dcc42d2d415a72181ba729d5a19d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 Jan 2024 15:53:54 +0000 Subject: Remove more use of legacy types --- gfx/gl/camera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/camera.cpp') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 9f40998..d362b94 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -17,14 +17,14 @@ Ray Camera::unProject(const ScreenRelCoord & mouse) const { static constexpr const glm::vec4 screen {0, 0, 1, 1}; - const auto mouseProjection = glm::lookAt(::origin, forward, up); + const auto mouseProjection = glm::lookAt({}, forward, up); return {position, glm::normalize(glm::unProject(mouse || 1.F, mouseProjection, projection, screen))}; } void Camera::updateView() { - viewProjection = projection * glm::lookAt(origin, forward, up); + viewProjection = projection * glm::lookAt({}, forward, up); inverseViewProjection = glm::inverse(viewProjection); } -- cgit v1.2.3