#include "glm.hpp"
#include <algorithm>
+#include <ostream>
+#include <glm/gtx/io.hpp>
namespace blobs {
};
+inline std::ostream &operator <<(std::ostream &out, const AABB &b) {
+ return out << "AABB(" << b.min << ", " << b.max << ")";
+}
/// matrices must not scale
bool Intersect(
const AABB &a_box,
glm::dvec3 &normal,
double &depth) noexcept;
+
class Ray {
public:
};
+inline Ray operator *(const glm::dmat4 &m, const Ray &r) noexcept {
+ glm::dvec4 o(m * glm::dvec4(r.Origin(), 1.0));
+ glm::dvec4 d(m * glm::dvec4(r.Origin() + r.Direction(), 1.0));
+ return Ray(glm::dvec3(o) / o.w, glm::normalize((glm::dvec3(d) / d.w) - (glm::dvec3(o) / o.w)));
+}
+
+inline std::ostream &operator <<(std::ostream &out, const Ray &r) {
+ return out << "Ray(" << r.Origin() << ", " << r.Direction() << ")";
+}
+
/// oriented ray/box intersection test
bool Intersect(
const Ray &,
glm::dvec3 &normal,
double &dist) noexcept;
+
+struct Sphere {
+
+ glm::dvec3 origin;
+ double radius;
+
+};
+
+/// matrix may scale, but only uniformly
+inline Sphere operator *(const glm::dmat4 &m, const Sphere &s) noexcept {
+ glm::dvec4 o(m * glm::dvec4(s.origin, 1.0));
+ glm::dvec4 p(m * glm::dvec4(s.origin + glm::dvec3(s.radius, 0.0, 0.0), 1.0));
+ return Sphere{glm::dvec3(o) / o.w, glm::length((glm::dvec3(p) / p.w) - (glm::dvec3(o) / o.w))};
+}
+
+inline std::ostream &operator <<(std::ostream &out, const Sphere &s) {
+ return out << "Sphere(" << s.origin << ", " << s.radius << ")";
+}
+
+/// oriented ray/sphere intersection test
+bool Intersect(
+ const Ray &,
+ const Sphere &,
+ glm::dvec3 &normal,
+ double &dist) noexcept;
+
}
}