Add support for childshape index for btCompoundShape during ContactAddedCallback,
see example in Bullet/Demos/ConvexDecompositionDemo Removed some warnings
This commit is contained in:
@@ -111,7 +111,7 @@ btDemoEntry g_demoEntries[] =
|
||||
{"Basic Demo", BasicDemo::Create},
|
||||
{"Convex Decomposition",ConvexDecompositionDemo::Create},
|
||||
{"Concave Moving", GimpactConcaveDemo::Create},
|
||||
// {"Dynamic Control Demo",MotorDemo::Create},
|
||||
{"Dynamic Control Demo",MotorDemo::Create},
|
||||
//{"ConcaveDemo",ConcaveDemo::Create},
|
||||
{"Concave Convexcast Demo",ConcaveConvexcastDemo::Create},
|
||||
// {"SoftBody Cloth",SoftDemo0::Create},
|
||||
|
||||
@@ -62,9 +62,39 @@ void ConvexDecompositionDemo::initPhysics()
|
||||
|
||||
|
||||
|
||||
///MyContactCallback is just an example to show how to get access to the child shape that collided
|
||||
bool MyContactCallback (
|
||||
btManifoldPoint& cp,
|
||||
const btCollisionObject* colObj0,
|
||||
int partId0,
|
||||
int index0,
|
||||
const btCollisionObject* colObj1,
|
||||
int partId1,
|
||||
int index1)
|
||||
{
|
||||
|
||||
if (colObj0->getRootCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btCompoundShape* compound = (btCompoundShape*)colObj0->getRootCollisionShape();
|
||||
btCollisionShape* childShape;
|
||||
childShape = compound->getChildShape(index0);
|
||||
}
|
||||
|
||||
if (colObj1->getRootCollisionShape()->getShapeType()==COMPOUND_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btCompoundShape* compound = (btCompoundShape*)colObj1->getRootCollisionShape();
|
||||
btCollisionShape* childShape;
|
||||
childShape = compound->getChildShape(index1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
{
|
||||
gContactAddedCallback = &MyContactCallback;
|
||||
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
|
||||
@@ -396,7 +426,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
//now create some bodies
|
||||
|
||||
{
|
||||
btCompoundShape* compound = new btCompoundShape();
|
||||
btCompoundShape* compound = new btCompoundShape(false);
|
||||
m_collisionShapes.push_back (compound);
|
||||
|
||||
btTransform trans;
|
||||
@@ -411,14 +441,19 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
}
|
||||
btScalar mass=10.f;
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
btRigidBody* body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
convexDecompositionObjectOffset.setZ(6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
convexDecompositionObjectOffset.setZ(-6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
|
||||
body = localCreateRigidBody( mass, trans,compound);
|
||||
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -338,7 +338,8 @@ void MotorDemo::clientMoveAndDisplay()
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
|
||||
///run the simulation at 120 hertz internally (maximum of 10 substeps)
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000000.f,10,1./120.f);
|
||||
m_dynamicsWorld->debugDrawWorld();
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +283,10 @@ static float gDepth;
|
||||
|
||||
struct MyResult : public btDiscreteCollisionDetectorInterface::Result
|
||||
{
|
||||
virtual void setShapeIdentifiers(int partId0, int index0, int partId1, int index1)
|
||||
virtual void setShapeIdentifiersA(int partId0, int index0)
|
||||
{
|
||||
}
|
||||
virtual void setShapeIdentifiersB(int partId1, int index1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -349,6 +349,9 @@ void RagdollDemo::initPhysics()
|
||||
m_solver = new btSequentialImpulseConstraintSolver;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
//m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
|
||||
//m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f;
|
||||
|
||||
|
||||
|
||||
// Setup a big ground box
|
||||
|
||||
Reference in New Issue
Block a user