summaryrefslogtreecommitdiff
path: root/lib/ray.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ray.h')
-rw-r--r--lib/ray.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/ray.h b/lib/ray.h
index 2b117b7..642cd4d 100644
--- a/lib/ray.h
+++ b/lib/ray.h
@@ -78,21 +78,30 @@ public:
return std::nullopt;
}
- bool
- intersectSphere(const PositionType centre, const PositionType::value_type size, PositionType & position,
- Normal3D & normal) const
+ struct IntersectSphereResult {
+ PositionType position;
+ Normal3D normal;
+ };
+
+ std::optional<IntersectSphereResult>
+ intersectSphere(const PositionType centre, const PositionType::value_type size) const
{
+ IntersectSphereResult out;
if constexpr (std::is_floating_point_v<typename PositionType::value_type>) {
- return glm::intersectRaySphere(start, direction, centre, size, position, normal);
+ if (glm::intersectRaySphere(start, direction, centre, size, out.position, out.normal)) {
+ return out;
+ }
}
else {
const RelativePosition3D cr = centre - start;
RelativePosition3D positionF {};
- const auto r = glm::intersectRaySphere(
- {}, direction, cr, static_cast<RelativeDistance>(size), positionF, normal);
- position = GlobalPosition3D(positionF) + start;
- return r;
+ if (glm::intersectRaySphere(
+ {}, direction, cr, static_cast<RelativeDistance>(size), positionF, out.normal)) {
+ out.position = GlobalPosition3D(positionF) + start;
+ return out;
+ }
}
+ return std::nullopt;
}
};