diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-05 20:08:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-05 20:08:26 +0000 |
commit | 7ad46a0e239c7e68c4436e632a77a0d8a14b6333 (patch) | |
tree | 9cc27d180d6ef23dbdf655bf6f12a34bd5d0a7bf /lib/geometricPlane.h | |
parent | Remove more use of legacy types and unnecessary pointers from selectable inte... (diff) | |
download | ilt-7ad46a0e239c7e68c4436e632a77a0d8a14b6333.tar.bz2 ilt-7ad46a0e239c7e68c4436e632a77a0d8a14b6333.tar.xz ilt-7ad46a0e239c7e68c4436e632a77a0d8a14b6333.zip |
Inline functions of GeometricPlane
Diffstat (limited to 'lib/geometricPlane.h')
-rw-r--r-- | lib/geometricPlane.h | 30 |
1 files changed, 25 insertions, 5 deletions
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 <glm/geometric.hpp> +#include <glm/gtx/intersect.hpp> #include <glm/vec3.hpp> #include <optional> -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<DistAndPosition> 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<DistAndPosition> + 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)); + } }; |