From 7ad46a0e239c7e68c4436e632a77a0d8a14b6333 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 5 Jan 2024 20:08:26 +0000 Subject: Inline functions of GeometricPlane --- lib/geometricPlane.h | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/geometricPlane.h') diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index c74beff..5be76ec 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -1,11 +1,12 @@ #pragma once #include "config/types.h" +#include "ray.h" +#include +#include #include #include -class Ray; - class GeometricPlane { public: struct DistAndPosition { @@ -17,8 +18,27 @@ public: Position3D origin; Normal3D normal; - [[nodiscard]] PlaneRelation getRelation(Position3D point) const; - [[nodiscard]] std::optional getRayIntersectPosition(const Ray &) const; + [[nodiscard]] inline PlaneRelation + getRelation(Position3D point) const + { + const auto d = glm::dot(normal, point - origin); + return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On; + } + + [[nodiscard]] inline std::optional + getRayIntersectPosition(const Ray & ray) const + { + float dist {}; + if (!glm::intersectRayPlane(ray.start, ray.direction, origin, normal, dist)) { + return {}; + } + return DistAndPosition {dist, ray.start + (ray.direction * dist)}; + } - static bool isIntersect(PlaneRelation a, PlaneRelation b); + inline static bool + isIntersect(PlaneRelation a, PlaneRelation b) + { + return ((a == PlaneRelation::Above && b == PlaneRelation::Below) + || (a == PlaneRelation::Below && b == PlaneRelation::Above)); + } }; -- cgit v1.2.3 From 335e9c6b4bbc5bbf1a861ac16abf612f5519dd5e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 5 Jan 2024 20:20:14 +0000 Subject: Template GeometicPlane on Position type --- lib/geometricPlane.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'lib/geometricPlane.h') diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index 5be76ec..fd3a1d7 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -8,18 +8,24 @@ #include class GeometricPlane { +public: + enum class PlaneRelation { Above, Below, On }; + + static bool isIntersect(PlaneRelation a, PlaneRelation b); +}; + +template class GeometricPlaneT : public GeometricPlane { public: struct DistAndPosition { - float dist; - Position3D position; + PositionType::value_type dist; + PositionType position; }; - enum class PlaneRelation { Above, Below, On }; - Position3D origin; + PositionType origin; Normal3D normal; [[nodiscard]] inline PlaneRelation - getRelation(Position3D point) const + getRelation(PositionType point) const { const auto d = glm::dot(normal, point - origin); return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On; @@ -34,11 +40,4 @@ public: } return DistAndPosition {dist, ray.start + (ray.direction * dist)}; } - - inline static bool - isIntersect(PlaneRelation a, PlaneRelation b) - { - return ((a == PlaneRelation::Above && b == PlaneRelation::Below) - || (a == PlaneRelation::Below && b == PlaneRelation::Above)); - } }; -- cgit v1.2.3 From 6a1df3dfbae98a05e74c646cc216fbc19ffdb6d6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 7 Jan 2024 13:04:31 +0000 Subject: Template Ray on position type --- lib/geometricPlane.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/geometricPlane.h') diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index fd3a1d7..3f95d3c 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -32,7 +32,7 @@ public: } [[nodiscard]] inline std::optional - getRayIntersectPosition(const Ray & ray) const + getRayIntersectPosition(const Ray & ray) const { float dist {}; if (!glm::intersectRayPlane(ray.start, ray.direction, origin, normal, dist)) { -- cgit v1.2.3