Add support for broadphase acceleration of convex cast (re-use rayTest implementation with an added aabb min/max, zero for rays)

Add Concave Convexcast demo back in AllBulletDemos, and tweaked it a bit.
Fix view frustum of ForkLiftDemo (caused picking to fail)
Removed innerloop profiling for ray and convex casts, it hurts performance.
Set default #aabb's in CDTestFramework to 8192
This commit is contained in:
erwin.coumans
2008-11-19 00:38:29 +00:00
parent cb03329d06
commit 50344c4a23
18 changed files with 176 additions and 54 deletions

View File

@@ -104,13 +104,14 @@ btDemoEntry g_demoEntries[] =
{
{"ForkLiftDemo",ForkLiftDemo::Create},
{"RagdollDemo",RagdollDemo::Create},
{"BasicDemo", BasicDemo::Create},
{"ConvexDecomposition",ConvexDecompositionDemo::Create},
{"ForkLift Demo",ForkLiftDemo::Create},
{"Ragdoll Demo",RagdollDemo::Create},
{"Basic Demo", BasicDemo::Create},
{"Convex Decomposition",ConvexDecompositionDemo::Create},
{"Concave Moving", GimpactConcaveDemo::Create},
{"DynamicControlDemo",MotorDemo::Create},
{"ConcaveDemo",ConcaveDemo::Create},
{"Dynamic Control Demo",MotorDemo::Create},
//{"ConcaveDemo",ConcaveDemo::Create},
{"Concave Convexcast Demo",ConcaveConvexcastDemo::Create},
// {"SoftBody Cloth",SoftDemo0::Create},
// {"SoftBody Pressure",SoftDemo1::Create},
{"SoftBody Ropes Attach",SoftDemo4::Create},
@@ -144,7 +145,6 @@ btDemoEntry g_demoEntries[] =
// {"SliderConstraint",SliderConstraintDemo::Create},
// {"CcdPhysicsDemo", CcdPhysicsDemo::Create},
// {"ConcaveRaycastDemo",ConcaveRaycastDemo::Create},
// {"ConcaveConvexcastDemo",ConcaveConvexcastDemo::Create},
//{"BspDemo", BspDemo::Create},
// {"Raytracer Test",Raytracer::Create},
// {"GjkConvexCast",LinearConvexCastDemo::Create},
@@ -156,7 +156,7 @@ btDemoEntry g_demoEntries[] =
{"Benchmark Mesh-Convex",BenchmarkDemo6::Create},
{"Benchmark Raycast",BenchmarkDemo7::Create},
{"MemoryLeakChecker",btEmptyDebugDemo::Create},
{"MemoryLeak Checker",btEmptyDebugDemo::Create},
{0, 0}
};

View File

@@ -118,6 +118,8 @@ void NextScene()
testSelection++;
if(testSelection>23)
testSelection=0;
if (glui)
glui->sync_live();
}

View File

@@ -21,6 +21,8 @@ subject to the following restrictions:
#include "GL_ShapeDrawer.h"
#include "GlutStuff.h"
#define NUM_DYNAMIC_BOXES_X 30
#define NUM_DYNAMIC_BOXES_Y 30
static btVector3* gVertices=0;
static int* gIndices=0;
@@ -74,7 +76,7 @@ public:
sum_ms = 0;
}
btConvexcastBatch (bool unused, btScalar ray_length, btScalar min_z, btScalar max_z, btScalar min_y = -10, btScalar max_y = 10) : boxShape(btVector3(0.0, 0.0, 0.0))
btConvexcastBatch (bool unused, btScalar ray_length, btScalar min_z, btScalar max_z, btScalar min_y , btScalar max_y ) : boxShape(btVector3(0.0, 0.0, 0.0))
{
boxShapeHalfExtents = btVector3(1.0, 1.0, 1.0);
boxShape = btBoxShape(boxShapeHalfExtents);
@@ -302,6 +304,7 @@ void ConcaveConvexcastDemo::initPhysics()
{
#define TRISIZE 10.f
setCameraDistance(100.f);
int vertStride = sizeof(btVector3);
@@ -366,10 +369,11 @@ void ConcaveConvexcastDemo::initPhysics()
m_collisionShapes.push_back(colShape);
{
for (int i=0;i<10;i++)
for (int j=0;j<NUM_DYNAMIC_BOXES_X;j++)
for (int i=0;i<NUM_DYNAMIC_BOXES_Y;i++)
{
//btCollisionShape* colShape = new btCapsuleShape(0.5,2.0);//boxShape = new btSphereShape(1.f);
startTransform.setOrigin(btVector3(2*i,10,1));
startTransform.setOrigin(btVector3(5*(i-NUM_DYNAMIC_BOXES_X/2),10,5*(j-NUM_DYNAMIC_BOXES_Y/2)));
localCreateRigidBody(1, startTransform,colShape);
}
}
@@ -383,7 +387,7 @@ void ConcaveConvexcastDemo::initPhysics()
//enable custom material callback
staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
convexcastBatch = btConvexcastBatch (40.0, 0.0, -10.0);
convexcastBatch = btConvexcastBatch (40.0, 0.0, -10.0,80.0);
//convexcastBatch = btConvexcastBatch (true, 40.0, -50.0, 50.0);
}
@@ -398,12 +402,34 @@ void ConcaveConvexcastDemo::clientMoveAndDisplay()
static float offset=0.f;
offset+=0.01f;
setVertexPositions(waveheight,offset);
int i;
int j;
btVector3 aabbMin(1e30,1e30,1e30);
btVector3 aabbMax(-1e30,-1e30,-1e30);
btVector3 worldMin(-1000,-1000,-1000);
btVector3 worldMax(1000,1000,1000);
for ( i=NUM_VERTS_X/2-3;i<NUM_VERTS_X/2+2;i++)
{
for (j=NUM_VERTS_X/2-3;j<NUM_VERTS_Y/2+2;j++)
{
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
//0.f,
waveheight*sinf((float)i+offset)*cosf((float)j+offset),
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
aabbMin.setMin(gVertices[i+j*NUM_VERTS_X]);
aabbMax.setMax(gVertices[i+j*NUM_VERTS_X]);
}
}
trimeshShape->partialRefitTree(aabbMin,aabbMax);
trimeshShape->refitTree(worldMin,worldMax);
//clear all contact points involving mesh proxy. Note: this is a slow/unoptimized operation.
m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(staticBody->getBroadphaseHandle(),getDynamicsWorld()->getDispatcher());

View File

@@ -49,7 +49,7 @@ class ConcaveConvexcastDemo : public DemoApplication
public:
ConcaveConvexcastDemo() : m_animatedMesh(false)
ConcaveConvexcastDemo() : m_animatedMesh(true)
{
}

View File

@@ -794,7 +794,8 @@ void ForkLiftDemo::updateCamera()
m_cameraPosition -= correctionFactor*camToObject;
//update OpenGL camera settings
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
btScalar aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight;
glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

View File

@@ -31,8 +31,8 @@ subject to the following restrictions:
#include "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h"
#include "LinearMath/btQuickprof.h"
//#define NUM_SAP_BOXES 8192
#define NUM_SAP_BOXES 16384
#define NUM_SAP_BOXES 8192
//#define NUM_SAP_BOXES 16384
//#define NUM_SAP_BOXES 1024
int percentUpdate = 100;

View File

@@ -148,8 +148,8 @@ public:
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const;
///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
void unQuantize(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
@@ -264,12 +264,11 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::setAabb(btBroadphaseProxy* proxy,cons
}
template <typename BP_FP_INT_TYPE>
void btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
void btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin,const btVector3& aabbMax)
{
if (m_raycastAccelerator)
{
m_raycastAccelerator->rayTest(rayFrom,rayTo,rayCallback);
m_raycastAccelerator->rayTest(rayFrom,rayTo,rayCallback,aabbMin,aabbMax);
} else
{
//choose axis?
@@ -286,6 +285,7 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,cons
}
template <typename BP_FP_INT_TYPE>
void btAxisSweep3Internal<BP_FP_INT_TYPE>::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
{

View File

@@ -52,7 +52,7 @@ public:
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher)=0;
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const =0;
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback) = 0;
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0;
///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
virtual void calculateOverlappingPairs(btDispatcher* dispatcher)=0;

View File

@@ -336,6 +336,8 @@ struct btDbvt
const btVector3& rayDirectionInverse,
unsigned int signs[3],
btScalar lambda_max,
const btVector3& aabbMin,
const btVector3& aabbMax,
DBVT_IPOLICY) const;
DBVT_PREFIX
@@ -955,6 +957,8 @@ inline void btDbvt::rayTestInternal( const btDbvtNode* root,
const btVector3& rayDirectionInverse,
unsigned int signs[3],
btScalar lambda_max,
const btVector3& aabbMin,
const btVector3& aabbMax,
DBVT_IPOLICY) const
{
DBVT_CHECKTYPE
@@ -971,8 +975,8 @@ inline void btDbvt::rayTestInternal( const btDbvtNode* root,
do
{
const btDbvtNode* node=stack[--depth];
bounds[0] = node->volume.Mins();
bounds[1] = node->volume.Maxs();
bounds[0] = node->volume.Mins()+aabbMin;
bounds[1] = node->volume.Maxs()+aabbMax;
btScalar tmin=1.f,lambda_min=0.f;
unsigned int result1=false;
result1 = btRayAabb2(rayFrom,rayDirectionInverse,signs,bounds,tmin,lambda_min,lambda_max);

View File

@@ -210,7 +210,7 @@ void btDbvtBroadphase::getAabb(btBroadphaseProxy* absproxy,btVector3& aabbMin, b
aabbMax = proxy->m_aabbMax;
}
void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin,const btVector3& aabbMax)
{
struct BroadphaseRayTester : btDbvt::ICollide
@@ -235,6 +235,8 @@ void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
rayCallback.m_rayDirectionInverse,
rayCallback.m_signs,
rayCallback.m_lambda_max,
aabbMin,
aabbMax,
callback);
m_sets[1].rayTestInternal( m_sets[1].m_root,
@@ -243,6 +245,8 @@ void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
rayCallback.m_rayDirectionInverse,
rayCallback.m_signs,
rayCallback.m_lambda_max,
aabbMin,
aabbMax,
callback);
}

View File

@@ -105,7 +105,7 @@ struct btDbvtBroadphase : btBroadphaseInterface
btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
void calculateOverlappingPairs(btDispatcher* dispatcher);

View File

@@ -156,7 +156,7 @@ void btMultiSapBroadphase::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin,
aabbMax = multiProxy->m_aabbMax;
}
void btMultiSapBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
void btMultiSapBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin,const btVector3& aabbMax)
{
for (int i=0;i<m_multiSapProxies.size();i++)
{
@@ -224,7 +224,9 @@ void btMultiSapBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aab
m_optimizedAabbTree->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
if (m_optimizedAabbTree)
m_optimizedAabbTree->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
int i;
for ( i=0;i<multiProxy->m_bridgeProxies.size();i++)

View File

@@ -26,6 +26,7 @@ class btSimpleBroadphase;
typedef btAlignedObjectArray<btBroadphaseInterface*> btSapBroadphaseArray;
///The btMultiSapBroadphase is a research project, not recommended to use in production. Use btAxisSweep3 or btDbvtBroadphase instead.
///The btMultiSapBroadphase is a broadphase that contains multiple SAP broadphases.
///The user can add SAP broadphases that cover the world. A btBroadphaseProxy can be in multiple child broadphases at the same time.
///A btQuantizedBvh acceleration structures finds overlapping SAPs for each btBroadphaseProxy.
@@ -110,7 +111,7 @@ public:
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase);

View File

@@ -152,7 +152,7 @@ void btSimpleBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aabbM
sbp->m_aabbMax = aabbMax;
}
void btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback)
void btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin,const btVector3& aabbMax)
{
for (int i=0; i <= m_LastHandleIndex; i++)
{

View File

@@ -132,7 +132,7 @@ public:
virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
btOverlappingPairCache* getOverlappingPairCache()
{

View File

@@ -231,7 +231,7 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
if (collisionShape->isConvex())
{
BT_PROFILE("rayTestConvex");
// BT_PROFILE("rayTestConvex");
btConvexCast::CastResult castResult;
castResult.m_fraction = resultCallback.m_closestHitFraction;
@@ -275,7 +275,7 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
} else {
if (collisionShape->isConcave())
{
BT_PROFILE("rayTestConcave");
// BT_PROFILE("rayTestConcave");
if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
///optimized version for btBvhTriangleMeshShape
@@ -324,7 +324,8 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
} else
{
btTriangleMeshShape* triangleMesh = (btTriangleMeshShape*)collisionShape;
//generic (slower) case
btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
btTransform worldTocollisionObject = colObjWorldTransform.inverse();
@@ -337,10 +338,10 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
{
btCollisionWorld::RayResultCallback* m_resultCallback;
btCollisionObject* m_collisionObject;
btTriangleMeshShape* m_triangleMesh;
btConcaveShape* m_triangleMesh;
BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh):
btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh):
btTriangleRaycastCallback(from,to),
m_resultCallback(resultCallback),
m_collisionObject(collisionObject),
@@ -370,7 +371,7 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
};
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape);
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
btVector3 rayAabbMinLocal = rayFromLocal;
@@ -378,10 +379,10 @@ void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
btVector3 rayAabbMaxLocal = rayFromLocal;
rayAabbMaxLocal.setMax(rayToLocal);
triangleMesh->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
concaveShape->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
}
} else {
BT_PROFILE("rayTestCompound");
// BT_PROFILE("rayTestCompound");
///@todo: use AABB tree or other BVH acceleration structure, see btDbvt
if (collisionShape->isCompound())
{
@@ -416,10 +417,10 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
{
if (collisionShape->isConvex())
{
//BT_PROFILE("convexSweepConvex");
btConvexCast::CastResult castResult;
castResult.m_allowedPenetration = allowedPenetration;
castResult.m_fraction = btScalar(1.);//??
castResult.m_fraction = resultCallback.m_closestHitFraction;//btScalar(1.);//??
btConvexShape* convexShape = (btConvexShape*) collisionShape;
btVoronoiSimplexSolver simplexSolver;
@@ -461,6 +462,7 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
{
if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
//BT_PROFILE("convexSweepbtBvhTriangleMesh");
btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
btTransform worldTocollisionObject = colObjWorldTransform.inverse();
btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
@@ -517,7 +519,8 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
triangleMesh->performConvexcast(&tccb,convexFromLocal,convexToLocal,boxMinLocal, boxMaxLocal);
} else
{
btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
//BT_PROFILE("convexSweepConcave");
btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
btTransform worldTocollisionObject = colObjWorldTransform.inverse();
btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
@@ -529,10 +532,10 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
{
btCollisionWorld::ConvexResultCallback* m_resultCallback;
btCollisionObject* m_collisionObject;
btTriangleMeshShape* m_triangleMesh;
btConcaveShape* m_triangleMesh;
BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld):
btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& triangleToWorld):
btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
m_resultCallback(resultCallback),
m_collisionObject(collisionObject),
@@ -565,7 +568,7 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
};
BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
tccb.m_hitFraction = resultCallback.m_closestHitFraction;
btVector3 boxMinLocal, boxMaxLocal;
castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
@@ -576,12 +579,13 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
rayAabbMaxLocal.setMax(convexToLocal);
rayAabbMinLocal += boxMinLocal;
rayAabbMaxLocal += boxMaxLocal;
triangleMesh->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
}
} else {
///@todo : use AABB tree or other BVH acceleration structure!
if (collisionShape->isCompound())
{
BT_PROFILE("convexSweepCompound");
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
int i=0;
for (i=0;i<compoundShape->getNumChildShapes();i++)
@@ -686,7 +690,8 @@ struct btSingleRayCallback : public btBroadphaseRayCallback
void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const
{
BT_PROFILE("rayTest");
/// go over all objects, and if the ray intersects their aabb, do a ray-shape query using convexCaster (CCD)
/// use the broadphase to accelerate the search for objects, based on their aabb
/// and for each object with ray-aabb overlap, perform an exact ray test
btSingleRayCallback rayCB(rayFromWorld,rayToWorld,this,resultCallback);
#ifndef USE_BRUTEFORCE_RAYBROADPHASE
@@ -700,8 +705,76 @@ void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& r
}
struct btSingleSweepCallback : public btBroadphaseRayCallback
{
btTransform m_convexFromTrans;
btTransform m_convexToTrans;
btVector3 m_hitNormal;
const btCollisionWorld* m_world;
btCollisionWorld::ConvexResultCallback& m_resultCallback;
btScalar m_allowedCcdPenetration;
const btConvexShape* m_castShape;
btSingleSweepCallback(const btConvexShape* castShape, const btTransform& convexFromTrans,const btTransform& convexToTrans,const btCollisionWorld* world,btCollisionWorld::ConvexResultCallback& resultCallback,btScalar allowedPenetration)
:m_convexFromTrans(convexFromTrans),
m_convexToTrans(convexToTrans),
m_world(world),
m_resultCallback(resultCallback),
m_allowedCcdPenetration(allowedPenetration),
m_castShape(castShape)
{
btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin()-m_convexFromTrans.getOrigin());
btVector3 rayDir = unnormalizedRayDir.normalized();
///what about division by zero? --> just set rayDirection[i] to INF/1e30
m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
m_signs[0] = m_rayDirectionInverse[0] < 0.0;
m_signs[1] = m_rayDirectionInverse[1] < 0.0;
m_signs[2] = m_rayDirectionInverse[2] < 0.0;
m_lambda_max = rayDir.dot(unnormalizedRayDir);
}
virtual bool process(const btBroadphaseProxy* proxy)
{
///terminate further convex sweep tests, once the closestHitFraction reached zero
if (m_resultCallback.m_closestHitFraction == btScalar(0.f))
return false;
btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject;
//only perform raycast if filterMask matches
if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) {
//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans,
collisionObject,
collisionObject->getCollisionShape(),
collisionObject->getWorldTransform(),
m_resultCallback,
m_allowedCcdPenetration);
}
return true;
}
};
void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, ConvexResultCallback& resultCallback) const
{
BT_PROFILE("convexSweepTest");
/// use the broadphase to accelerate the search for objects, based on their aabb
/// and for each object with ray-aabb overlap, perform an exact ray test
/// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical
btTransform convexFromTrans,convexToTrans;
convexFromTrans = convexFromWorld;
convexToTrans = convexToWorld;
@@ -710,12 +783,21 @@ void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
{
btVector3 linVel, angVel;
btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
btVector3 zeroLinVel;
zeroLinVel.setValue(0,0,0);
btTransform R;
R.setIdentity ();
R.setRotation (convexFromTrans.getRotation());
castShape->calculateTemporalAabb (R, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
castShape->calculateTemporalAabb (R, zeroLinVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
}
#ifndef USE_BRUTEFORCE_RAYBROADPHASE
btSingleSweepCallback convexCB(castShape,convexFromWorld,convexToWorld,this,resultCallback,getDispatchInfo().m_allowedCcdPenetration);
m_broadphasePairCache->rayTest(convexFromTrans.getOrigin(),convexToTrans.getOrigin(),convexCB,castShapeAabbMin,castShapeAabbMax);
#else
/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
// do a ray-shape query using convexCaster (CCD)
int i;
@@ -741,5 +823,5 @@ void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
}
}
}
#endif //USE_BRUTEFORCE_RAYBROADPHASE
}

View File

@@ -93,7 +93,7 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
///debug drawing of the overlapping triangles
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
{
btVector3 color(255,255,0);
btTransform& tr = ob->getWorldTransform();