disable constraints when they exceed a breaking threshold, control it with new methods in btTypedConstraint: get/setBreakingImpulseThreshold and get/setEnabled
Disabled constraints are not removed from the world and they use negligible CPU cycles
This commit is contained in:
@@ -13,7 +13,6 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
//#define TEST_SERIALIZATION 1
|
||||
|
||||
|
||||
|
||||
@@ -29,12 +28,6 @@ subject to the following restrictions:
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
#include "LinearMath/btSerializer.h"
|
||||
#include "btBulletFile.h"
|
||||
#include "btBulletWorldImporter.h"
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
|
||||
const int numObjects = 3;
|
||||
|
||||
@@ -121,6 +114,30 @@ void ConstraintDemo::initPhysics()
|
||||
trans.setOrigin(btVector3(0,20,0));
|
||||
|
||||
float mass = 1.f;
|
||||
|
||||
|
||||
#if ENABLE_ALL_DEMOS
|
||||
//point to point constraint with a breaking threshold
|
||||
{
|
||||
trans.setIdentity();
|
||||
trans.setOrigin(btVector3(1,30,-5));
|
||||
localCreateRigidBody( mass,trans,shape);
|
||||
trans.setOrigin(btVector3(0,0,-5));
|
||||
|
||||
btRigidBody* body0 = localCreateRigidBody( mass,trans,shape);
|
||||
trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));
|
||||
mass = 1.f;
|
||||
btRigidBody* body1 = 0;//localCreateRigidBody( mass,trans,shape);
|
||||
btVector3 pivotInA(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,0);
|
||||
btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,pivotInA);
|
||||
m_dynamicsWorld->addConstraint(p2p);
|
||||
p2p ->setBreakingImpulseThreshold(10.2);
|
||||
p2p->setDbgDrawSize(btScalar(5.f));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if ENABLE_ALL_DEMOS
|
||||
//point to point constraint (ball socket)
|
||||
{
|
||||
@@ -141,7 +158,7 @@ void ConstraintDemo::initPhysics()
|
||||
(body1->getCenterOfMassTransform().getBasis().inverse()*(body1->getCenterOfMassTransform().getBasis() * axisInA)) :
|
||||
body0->getCenterOfMassTransform().getBasis() * axisInA;
|
||||
|
||||
//#define P2P
|
||||
#define P2P
|
||||
#ifdef P2P
|
||||
btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,pivotInA);
|
||||
//btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB);
|
||||
@@ -518,27 +535,6 @@ void ConstraintDemo::initPhysics()
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TEST_SERIALIZATION
|
||||
|
||||
int maxSerializeBufferSize = 1024*1024*5;
|
||||
|
||||
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
|
||||
m_dynamicsWorld->serialize(serializer);
|
||||
|
||||
FILE* f2 = fopen("testFile.bullet","wb");
|
||||
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
|
||||
fclose(f2);
|
||||
|
||||
|
||||
exitPhysics();
|
||||
|
||||
setupEmptyDynamicsWorld();
|
||||
|
||||
btBulletWorldImporter* fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
|
||||
fileLoader->loadFile("testFile.bullet");
|
||||
|
||||
#endif //TEST_SERIALIZATION
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user