+
+std::ostream &operator <<(std::ostream &out, const Sphere &s) {
+ return out << "Sphere(" << s.origin << ", " << s.radius << ')';
+}
+
+bool Intersection(
+ const Sphere &sphere,
+ const Plane &plane,
+ float &dist,
+ glm::vec3 &norm
+) noexcept {
+ float sig_dist = SignedDistance(sphere.origin, plane);
+ dist = sphere.radius - std::abs(sig_dist);
+ if (dist > 0.0f) {
+ norm = sig_dist > 0.0f ? plane.normal : -plane.normal;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool Intersection(
+ const Sphere &sphere,
+ const Plane &plane,
+ float &dist
+) noexcept {
+ dist = sphere.radius - SignedDistance(sphere.origin, plane);
+ return dist > 0.0f;