summaryrefslogtreecommitdiff
path: root/lib/ray.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ray.h')
-rw-r--r--lib/ray.h16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/ray.h b/lib/ray.h
index e1f43c3..a831270 100644
--- a/lib/ray.h
+++ b/lib/ray.h
@@ -43,15 +43,27 @@ public:
}
bool
+ intersectPlane(const PositionType orig, const Direction3D norm, RelativeDistance & distance) const
+ {
+ if constexpr (std::is_floating_point_v<typename PositionType::value_type>) {
+ return glm::intersectRayPlane(start, direction, orig, norm, distance) && distance >= 0.F;
+ }
+ else {
+ const RelativePosition3D origr = orig - start;
+ return glm::intersectRayPlane({}, direction, origr, norm, distance) && distance >= 0.F;
+ }
+ }
+
+ bool
intersectTriangle(const PositionType t0, const PositionType t1, const PositionType t2, BaryPosition & bary,
RelativeDistance & distance) const
{
if constexpr (std::is_floating_point_v<typename PositionType::value_type>) {
- return glm::intersectRayTriangle(start, direction, t0, t1, t2, bary, distance);
+ return glm::intersectRayTriangle(start, direction, t0, t1, t2, bary, distance) && distance >= 0.F;
}
else {
const RelativePosition3D t0r = t0 - start, t1r = t1 - start, t2r = t2 - start;
- return glm::intersectRayTriangle({}, direction, t0r, t1r, t2r, bary, distance);
+ return glm::intersectRayTriangle({}, direction, t0r, t1r, t2r, bary, distance) && distance >= 0.F;
}
}