Minor fix in friction: calculate second friction direction based on un-scaling first friction direction (issue if it was scaled to zero)

Force activation state of static objects to be ISLAND_SLEEPING, once they are added to the world
Add backwards compatibility option btDiscreteDynamicsWorld::setSynchronizeAllMotionStates, just in case only updating active objects broke someones code
Don't disable 3D box-box in box2ddemo
This commit is contained in:
erwin.coumans
2009-06-11 12:22:41 +00:00
parent 3e5fc86a6c
commit 6c80353556
4 changed files with 41 additions and 59 deletions

View File

@@ -97,7 +97,7 @@ void Box2dDemo::initPhysics()
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,new btEmptyAlgorithm::CreateFunc);
m_dispatcher->registerCollisionCreateFunc(CUSTOM_CONVEX_SHAPE_TYPE,CUSTOM_CONVEX_SHAPE_TYPE,new btBox2dBox2dCollisionAlgorithm::CreateFunc);
m_broadphase = new btDbvtBroadphase();

View File

@@ -619,9 +619,6 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
if (!(infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION) && lat_rel_vel > SIMD_EPSILON)
{
cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
if((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS))
{
cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
@@ -630,21 +627,26 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2);
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
}
applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
cp.m_lateralFrictionInitialized = true;
} else
{
//re-calculate friction direction every frame, todo: check if this is really needed
btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2);
applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS))
{
applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2);
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2);
addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
}
applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1);
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1);
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
cp.m_lateralFrictionInitialized = true;
}
@@ -1090,7 +1092,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject** bod
int numPoolConstraints = m_tmpSolverContactConstraintPool.size();
int j;
//copy back the applied impulses for contacts
for (j=0;j<numPoolConstraints;j++)
{
@@ -1107,39 +1108,6 @@ btScalar btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject** bod
//do a callback here?
}
int currentRow = 0;
int totalNumRows = m_tmpSolverNonContactConstraintPool.size();
#if 1
//copy back the applied impulses for joints
for (i=0;i<numConstraints;i++)
{
btTypedConstraint* constraint = constraints[i];
if (constraint->needsFeedback())
{
const btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i];
if (info1.m_numConstraintRows)
{
btAssert(currentRow<totalNumRows);
btSolverConstraint* currentConstraintRow = &m_tmpSolverNonContactConstraintPool[currentRow];
constraint->getAppliedLinearImpulse().setValue(0,0,0);
constraint->getAppliedAngularImpulseA().setValue(0,0,0);
constraint->getAppliedAngularImpulseB().setValue(0,0,0);
int j;
btScalar maxAppliedImpulse(0.);
for ( j=0;j<info1.m_numConstraintRows;j++)
{
btSetMax(maxAppliedImpulse,(btScalar)currentConstraintRow[i].m_appliedImpulse);
constraint->getAppliedLinearImpulse() += currentConstraintRow[i].m_contactNormal*currentConstraintRow[i].m_appliedImpulse;
constraint->getAppliedAngularImpulseA() += currentConstraintRow[i].m_relpos1CrossNormal*currentConstraintRow[i].m_appliedImpulse;
constraint->getAppliedAngularImpulseB() += currentConstraintRow[i].m_relpos2CrossNormal*currentConstraintRow[i].m_appliedImpulse;
}
constraint->internalSetAppliedImpulse(maxAppliedImpulse);
}
}
currentRow+=m_tmpConstraintSizesPool[i].m_numConstraintRows;
}
#endif
if (infoGlobal.m_splitImpulse)
{
for ( i=0;i<m_tmpSolverBodyPool.size();i++)

View File

@@ -64,7 +64,8 @@ btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroa
m_constraintSolver(constraintSolver),
m_gravity(0,-10,0),
m_localTime(btScalar(1.)/btScalar(60.)),
m_profileTimings(0)
m_profileTimings(0),
m_synchronizeAllMotionStates(false)
{
if (!m_constraintSolver)
{
@@ -264,8 +265,19 @@ void btDiscreteDynamicsWorld::synchronizeSingleMotionState(btRigidBody* body)
void btDiscreteDynamicsWorld::synchronizeMotionStates()
{
BT_PROFILE("synchronizeMotionStates");
if (m_synchronizeAllMotionStates)
{
//todo: iterate over awake simulation islands!
//iterate over all collision objects
for ( int i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* colObj = m_collisionObjects[i];
btRigidBody* body = btRigidBody::upcast(colObj);
if (body)
synchronizeSingleMotionState(body);
}
} else
{
//iterate over all active rigid bodies
for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
{
btRigidBody* body = m_nonStaticRigidBodies[i];
@@ -273,21 +285,6 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
synchronizeSingleMotionState(body);
}
}
/*
if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
{
for ( int i=0;i<this->m_vehicles.size();i++)
{
for (int v=0;v<m_vehicles[i]->getNumWheels();v++)
{
//synchronize the wheels with the (interpolated) chassis worldtransform
m_vehicles[i]->updateWheelTransform(v,true);
}
}
}
*/
}
@@ -438,6 +435,9 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
if (!body->isStaticObject())
{
m_nonStaticRigidBodies.push_back(body);
} else
{
body->setActivationState(ISLAND_SLEEPING);
}
bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
@@ -460,6 +460,10 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short
if (!body->isStaticObject())
{
m_nonStaticRigidBodies.push_back(body);
}
else
{
body->setActivationState(ISLAND_SLEEPING);
}
addCollisionObject(body,group,mask);
}

View File

@@ -52,6 +52,7 @@ protected:
bool m_ownsIslandManager;
bool m_ownsConstraintSolver;
bool m_synchronizeAllMotionStates;
btAlignedObjectArray<btActionInterface*> m_actions;
@@ -177,6 +178,15 @@ public:
///obsolete, use removeAction instead
virtual void removeCharacter(btActionInterface* character);
void setSynchronizeAllMotionStates(bool synchronizeAll)
{
m_synchronizeAllMotionStates = synchronizeAll;
}
bool getSynchronizeAllMotionStates() const
{
return m_synchronizeAllMotionStates;
}
};
#endif //BT_DISCRETE_DYNAMICS_WORLD_H