diff --git a/Demos/ConstraintDemo/ConstraintDemo.cpp b/Demos/ConstraintDemo/ConstraintDemo.cpp index 5590e9fcf..a35faa717 100644 --- a/Demos/ConstraintDemo/ConstraintDemo.cpp +++ b/Demos/ConstraintDemo/ConstraintDemo.cpp @@ -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 } diff --git a/Demos/OpenGL/DemoApplication.cpp b/Demos/OpenGL/DemoApplication.cpp index b6699d4b3..859d67d29 100644 --- a/Demos/OpenGL/DemoApplication.cpp +++ b/Demos/OpenGL/DemoApplication.cpp @@ -1345,6 +1345,11 @@ void DemoApplication::clientResetScene() if (m_dynamicsWorld) { + int numConstraints = m_dynamicsWorld->getNumConstraints(); + for (i=0;igetConstraint(0)->setEnabled(true); + } numObjects = m_dynamicsWorld->getNumCollisionObjects(); ///create a copy of the array, not a reference! diff --git a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index 4a3440d5a..c05e22fb1 100644 --- a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -805,7 +805,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol for (i=0;igetInfo1(&info1); + if (constraints[i]->isEnabled()) + { + constraints[i]->getInfo1(&info1); + } else + { + info1.m_numConstraintRows = 0; + info1.nub = 0; + } totalNumRows += info1.m_numConstraintRows; } m_tmpSolverNonContactConstraintPool.resize(totalNumRows); @@ -826,7 +833,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol btTypedConstraint* constraint = constraints[i]; - btRigidBody& rbA = constraint->getRigidBodyA(); btRigidBody& rbB = constraint->getRigidBodyB(); @@ -835,8 +841,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol for ( j=0;jgetInfo2(&info2); + if (currentConstraintRow->m_upperLimit>constraints[i]->getBreakingImpulseThreshold()) + { + currentConstraintRow->m_upperLimit = constraints[i]->getBreakingImpulseThreshold(); + } + + if (currentConstraintRow->m_lowerLimit<-constraints[i]->getBreakingImpulseThreshold()) + { + currentConstraintRow->m_lowerLimit = -constraints[i]->getBreakingImpulseThreshold(); + } + + + ///finalize the constraint setup for ( j=0;jinternalGetAppliedImpulse(); - sum += solverConstr.m_appliedImpulse; - constr->internalSetAppliedImpulse(sum); + constr->internalSetAppliedImpulse(solverConstr.m_appliedImpulse); + if (solverConstr.m_appliedImpulse>constr->getBreakingImpulseThreshold()) + { + constr->setEnabled(false); + } } diff --git a/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp b/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp index 8212c36ff..fb77b1c53 100644 --- a/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp +++ b/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp @@ -29,7 +29,9 @@ m_needsFeedback(false), m_rbA(rbA), m_rbB(getFixedBody()), m_appliedImpulse(btScalar(0.)), -m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) +m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE), +m_breakingImpulseThreshold(SIMD_INFINITY), +m_isEnabled(true) { } @@ -42,7 +44,9 @@ m_needsFeedback(false), m_rbA(rbA), m_rbB(rbB), m_appliedImpulse(btScalar(0.)), -m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) +m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE), +m_breakingImpulseThreshold(SIMD_INFINITY), +m_isEnabled(true) { } diff --git a/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h b/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h index 4ae32736d..20df8e5b2 100644 --- a/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h +++ b/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h @@ -62,6 +62,10 @@ class btTypedConstraint : public btTypedObject void* m_userConstraintPtr; }; + btScalar m_breakingImpulseThreshold; + bool m_isEnabled; + + bool m_needsFeedback; btTypedConstraint& operator=(btTypedConstraint& other) @@ -155,6 +159,28 @@ public: return m_appliedImpulse; } + + btScalar getBreakingImpulseThreshold() const + { + return m_breakingImpulseThreshold; + } + + void setBreakingImpulseThreshold(btScalar threshold) + { + m_breakingImpulseThreshold = threshold; + } + + bool isEnabled() const + { + return m_isEnabled; + } + + void setEnabled(bool enabled) + { + m_isEnabled=enabled; + } + + ///internal method used by the constraint solver, don't use them directly virtual void solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar /*timeStep*/) {}; diff --git a/src/BulletMultiThreaded/btParallelConstraintSolver.cpp b/src/BulletMultiThreaded/btParallelConstraintSolver.cpp index cc3d05e58..7ab3245fb 100644 --- a/src/BulletMultiThreaded/btParallelConstraintSolver.cpp +++ b/src/BulletMultiThreaded/btParallelConstraintSolver.cpp @@ -1165,11 +1165,8 @@ btScalar btParallelConstraintSolver::solveGroup(btCollisionObject** bodies1,int if (info1.m_numConstraintRows) { btAssert(currentRowgetRigidBodyA(); btRigidBody& rbB = constraint->getRigidBodyB(); @@ -1212,6 +1209,7 @@ btScalar btParallelConstraintSolver::solveGroup(btCollisionObject** bodies1,int info2.m_numIterations = infoGlobal.m_numIterations; constraints[i]->getInfo2(&info2); + int idA = constraint->getRigidBodyA().getCompanionId(); int idB = constraint->getRigidBodyB().getCompanionId();