From 2ab1aace7c662d224c9b707ec11b08688db210a0 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 29 Nov 2014 17:05:53 +0100 Subject: [PATCH] Raycast query now returns false if the body is not active --- src/body/CollisionBody.cpp | 5 +++-- src/collision/ProxyShape.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index 05c03e4b..9c2cd841 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -287,14 +287,15 @@ bool CollisionBody::testPointInside(const Vector3& worldPoint) const { /// The method returns the closest hit among all the collision shapes of the body bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) { + // If the body is not active, it cannot be hit by rays + if (!mIsActive) return false; + bool isHit = false; Ray rayTemp(ray); // For each collision shape of the body for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { - // TODO : Test for broad-phase hit for each shape before testing actual shape raycast - // Test if the ray hits the collision shape if (shape->raycast(rayTemp, raycastInfo)) { rayTemp.maxFraction = raycastInfo.hitFraction; diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 8493b0d1..fa38a68c 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -167,6 +167,10 @@ inline decimal ProxyShape::getMargin() const { // Raycast method with feedback information inline bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) { + + // If the corresponding body is not active, it cannot be hit by rays + if (!mBody->isActive()) return false; + return mCollisionShape->raycast(ray, raycastInfo, this); }