From 78193d9b03b8c98bcc933e9106800284624f3270 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 20 Sep 2014 16:59:47 +0200 Subject: [PATCH] Small improvements in sphere and cylinder raycasting --- src/collision/shapes/CylinderShape.cpp | 4 +--- src/collision/shapes/SphereShape.cpp | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/collision/shapes/CylinderShape.cpp b/src/collision/shapes/CylinderShape.cpp index da0a9f49..abaa04b2 100644 --- a/src/collision/shapes/CylinderShape.cpp +++ b/src/collision/shapes/CylinderShape.cpp @@ -175,10 +175,8 @@ bool CylinderShape::raycast(const Ray& ray, ProxyShape* proxyShape) const { (mDotN - nDotD) + t) <= decimal(0.0)); } - t = t0; - // If the intersection is behind the origin of the ray, we return no hit - return (t >= decimal(0.0)); + return (t0 >= decimal(0.0)); } // Raycast method with feedback information diff --git a/src/collision/shapes/SphereShape.cpp b/src/collision/shapes/SphereShape.cpp index d8eefaf8..b5c9b694 100644 --- a/src/collision/shapes/SphereShape.cpp +++ b/src/collision/shapes/SphereShape.cpp @@ -69,10 +69,7 @@ bool SphereShape::raycast(const Ray& ray, ProxyShape* proxyShape) const { decimal discriminant = b*b - c; // If the discriminant is negative, there is no intersection - if (discriminant < decimal(0.0)) return false; - - // There is an intersection - return true; + return (discriminant >= decimal(0.0)); } // Raycast method with feedback information