X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fmath%2Fgeometry.hpp;h=8f062841fe8adf64b05f6c8a0668f3e8a07adf2f;hp=6410ee013cb622f84879e3788dfd5dee8bb6d720;hb=200f9da6241613a1c19431896b09d1715c262c6d;hpb=76c09039792065ca1c259fb4b681c84c29a9dbd8 diff --git a/src/math/geometry.hpp b/src/math/geometry.hpp index 6410ee0..8f06284 100644 --- a/src/math/geometry.hpp +++ b/src/math/geometry.hpp @@ -4,6 +4,8 @@ #include "glm.hpp" #include +#include +#include namespace blobs { @@ -26,6 +28,9 @@ struct AABB { }; +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, @@ -54,6 +59,16 @@ private: }; +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 &,