From 1c4150f21138ad0ab6e8b1a41688074e8a87e64c Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 28 Nov 2009 17:30:34 +0000 Subject: BGE: ray casting works on soft body, the hit polygon is also returned. The modifications to Bullet have been reported to Bullet forum. Note: welding is completely disabled on soft body as it breaks the relationship between the soft body collision shape and the graphics mesh without bringing any additional stability (the reverse actually). --- .../BroadphaseCollision/btBroadphaseProxy.h | 4 ++++ .../CollisionDispatch/btCollisionWorld.cpp | 26 ++++++++++++++++++++++ .../CollisionShapes/btCollisionShape.h | 4 ++++ 3 files changed, 34 insertions(+) (limited to 'extern/bullet2/src/BulletCollision') diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h index be261ec4080..a9f3223798b 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h @@ -152,6 +152,10 @@ BT_DECLARE_ALIGNED_ALLOCATOR(); { return (proxyType == STATIC_PLANE_PROXYTYPE); } + static SIMD_FORCE_INLINE bool isSoftBody(int proxyType) + { + return (proxyType == SOFTBODY_SHAPE_PROXYTYPE); + } } ; diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index 10e880e2523..7159f552829 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -31,6 +31,7 @@ subject to the following restrictions: #include "LinearMath/btAabbUtil2.h" #include "LinearMath/btQuickprof.h" #include "LinearMath/btStackAlloc.h" +#include "BulletSoftBody/btSoftBody.h" //#define USE_BRUTEFORCE_RAYBROADPHASE 1 //RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation' or 'updateAabbs' before using a rayTest @@ -411,6 +412,31 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra // restore collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); } + } else { + if (collisionShape->isSoftBody()) { + btSoftBody* softBody = static_cast(collisionObject); + btSoftBody::sRayCast softResult; + if (softBody->rayTest(rayFromTrans.getOrigin(), rayToTrans.getOrigin(), softResult)) + { + btCollisionWorld::LocalShapeInfo shapeInfo; + shapeInfo.m_shapePart = 0; + shapeInfo.m_triangleIndex = softResult.index; + // get the normal + btVector3 normal = softBody->m_faces[softResult.index].m_normal; + btVector3 rayDir = rayToTrans.getOrigin() - rayFromTrans.getOrigin(); + if (normal.dot(rayDir) > 0) { + // normal always point toward origin of the ray + normal = -normal; + } + btCollisionWorld::LocalRayResult rayResult + (collisionObject, + &shapeInfo, + normal, + softResult.fraction); + bool normalInWorldSpace = true; + resultCallback.addSingleResult(rayResult,normalInWorldSpace); + } + } } } } diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h index 1f4b9bec647..b6374e64153 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h @@ -72,6 +72,10 @@ public: { return btBroadphaseProxy::isCompound(getShapeType()); } + SIMD_FORCE_INLINE bool isSoftBody() const + { + return btBroadphaseProxy::isSoftBody(getShapeType()); + } ///isInfinite is used to catch simulation error (aabb check) SIMD_FORCE_INLINE bool isInfinite() const -- cgit v1.2.3