From b222c21715384efc2eaa53d3ba295fb34da5b599 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Apr 2023 12:24:55 +0100 Subject: Start to factor out geometric place from face controller split --- lib/geometricPlane.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lib/geometricPlane.cpp (limited to 'lib/geometricPlane.cpp') diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp new file mode 100644 index 0000000..cb52997 --- /dev/null +++ b/lib/geometricPlane.cpp @@ -0,0 +1,9 @@ +#include "geometricPlane.h" +#include + +GeometricPlane::PlaneRelation +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; +} -- cgit v1.2.3 From 560bfce98146895cfd8429150792d49a18e24d98 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Apr 2023 13:15:46 +0100 Subject: Add lots of split required stuff to geometric plane --- lib/geometricPlane.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/geometricPlane.cpp') 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 +#include 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::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)}; +} -- cgit v1.2.3