From 08b57b8861d2767a8467a689bde23d2b8ecb421a Mon Sep 17 00:00:00 2001
From: Lukas Werner <lks.werner@fau.de>
Date: Tue, 30 Jan 2018 15:28:29 +0100
Subject: [PATCH] Added transform to BF method to Ray class

---
 src/pe/raytracing/Intersects.h | 3 ++-
 src/pe/raytracing/Ray.h        | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/pe/raytracing/Intersects.h b/src/pe/raytracing/Intersects.h
index a1fdb7c65..08ef13b65 100644
--- a/src/pe/raytracing/Intersects.h
+++ b/src/pe/raytracing/Intersects.h
@@ -45,6 +45,7 @@ inline bool intersects(const AABB& aabb, const Ray& ray, real_t& t, real_t paddi
 inline bool intersects(const SphereID sphere, const Ray& ray, real_t& t, Vec3& n);
 inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t, Vec3& n);
 inline bool intersects(const BoxID box, const Ray& ray, real_t& t, Vec3& n);
+inline bool intersects(const CapsuleID capsule, const Ray& ray, real_t& t, Vec3& n);
 
 struct IntersectsFunctor
 {
@@ -122,7 +123,7 @@ inline bool intersects(const PlaneID plane, const Ray& ray, real_t& t, Vec3& n)
 }
 
 inline bool intersects(const BoxID box, const Ray& ray, real_t& t, Vec3& n) {
-   Ray transformedRay(box->pointFromWFtoBF(ray.getOrigin()), box->vectorFromWFtoBF(ray.getDirection()));
+   Ray transformedRay = ray.transformedToBF(box);
    
    const Vec3& lengths = box->getLengths();
    const Vec3 lengthsHalved = lengths/real_t(2);
diff --git a/src/pe/raytracing/Ray.h b/src/pe/raytracing/Ray.h
index c3e5d28d6..65079d9ff 100644
--- a/src/pe/raytracing/Ray.h
+++ b/src/pe/raytracing/Ray.h
@@ -117,6 +117,14 @@ public:
       sign_[1] = int8_c(inv_direction_[1] < 0);
       sign_[2] = int8_c(inv_direction_[2] < 0);
    }
+   
+   /*!\brief Transforms the ray to the body frame.
+    *
+    * \return Ray transformed to the body frame.
+    */
+   Ray transformedToBF(const BodyID body) const {
+      return Ray(body->pointFromWFtoBF(getOrigin()), body->vectorFromWFtoBF(getDirection()));
+   }
    //@}
 };
 
-- 
GitLab