summaryrefslogtreecommitdiff
path: root/lib/geometricPlane.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 23:29:00 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 23:29:00 +0100
commitb6b3944e9507f337f77a72ea44b5c0ccba7a2c01 (patch)
treea487df54853522f973ed987006e787117804b9eb /lib/geometricPlane.cpp
parentSwap messy glmvec wrapper for OpenMesh Point/Normal with real glm::vec and a ... (diff)
parentMove remaining split/plane functions to use library (diff)
downloadilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.bz2
ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.xz
ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.zip
Merge branch 'model-factory-textures'
Diffstat (limited to 'lib/geometricPlane.cpp')
-rw-r--r--lib/geometricPlane.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp
new file mode 100644
index 0000000..71216c1
--- /dev/null
+++ b/lib/geometricPlane.cpp
@@ -0,0 +1,28 @@
+#include "geometricPlane.h"
+#include "ray.hpp"
+#include <glm/geometric.hpp>
+#include <glm/gtx/intersect.hpp>
+
+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;
+}
+
+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)};
+}