diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 13:15:46 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 13:15:46 +0100 |
commit | 560bfce98146895cfd8429150792d49a18e24d98 (patch) | |
tree | b9ae5e5db2ec374658e7a5c95b8b88155406c344 /lib/geometricPlane.cpp | |
parent | Add helper to create a Ray from two points (diff) | |
download | ilt-560bfce98146895cfd8429150792d49a18e24d98.tar.bz2 ilt-560bfce98146895cfd8429150792d49a18e24d98.tar.xz ilt-560bfce98146895cfd8429150792d49a18e24d98.zip |
Add lots of split required stuff to geometric plane
Diffstat (limited to 'lib/geometricPlane.cpp')
-rw-r--r-- | lib/geometricPlane.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp index cb52997..71216c1 100644 --- a/lib/geometricPlane.cpp +++ b/lib/geometricPlane.cpp @@ -1,5 +1,7 @@ #include "geometricPlane.h" +#include "ray.hpp" #include <glm/geometric.hpp> +#include <glm/gtx/intersect.hpp> GeometricPlane::PlaneRelation GeometricPlane::getRelation(glm::vec3 p) const @@ -7,3 +9,20 @@ GeometricPlane::getRelation(glm::vec3 p) const const auto d = glm::dot(normal, p - origin); return d < 0.f ? PlaneRelation::Below : d > 0.f ? PlaneRelation::Above : PlaneRelation::On; } + +bool +GeometricPlane::isIntersect(PlaneRelation a, PlaneRelation b) +{ + return ((a == PlaneRelation::Above && b == PlaneRelation::Below) + || (a == PlaneRelation::Below && b == PlaneRelation::Above)); +} + +std::optional<GeometricPlane::DistAndPosition> +GeometricPlane::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)}; +} |