One of the last parts of the refactoring (hopefully), made most members of btCollisionObject protected.
Also did some work on improving the constraint solver.
This commit is contained in:
@@ -56,9 +56,9 @@ subject to the following restrictions:
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld()
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver)
|
||||
:btDynamicsWorld(),
|
||||
m_constraintSolver(new btSequentialImpulseConstraintSolver),
|
||||
m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
|
||||
m_debugDrawer(0),
|
||||
m_gravity(0,-10,0),
|
||||
m_localTime(1.f/60.f),
|
||||
@@ -66,8 +66,7 @@ m_profileTimings(0)
|
||||
{
|
||||
m_islandManager = new btSimulationIslandManager();
|
||||
m_ownsIslandManager = true;
|
||||
m_ownsConstraintSolver = true;
|
||||
|
||||
m_ownsConstraintSolver = (constraintSolver==0);
|
||||
}
|
||||
|
||||
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
|
||||
@@ -142,7 +141,7 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
|
||||
}
|
||||
};
|
||||
|
||||
debugDrawObject(colObj->m_worldTransform,colObj->m_collisionShape,color);
|
||||
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
|
||||
}
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body && body->getMotionState() && !body->isStaticOrKinematicObject())
|
||||
@@ -150,8 +149,8 @@ void btDiscreteDynamicsWorld::synchronizeMotionStates()
|
||||
if (body->GetActivationState() != ISLAND_SLEEPING)
|
||||
{
|
||||
btTransform interpolatedTransform;
|
||||
btTransformUtil::integrateTransform(body->m_interpolationWorldTransform,
|
||||
body->m_interpolationLinearVelocity,body->m_interpolationAngularVelocity,m_localTime,interpolatedTransform);
|
||||
btTransformUtil::integrateTransform(body->getInterpolationWorldTransform(),
|
||||
body->getInterpolationLinearVelocity(),body->getInterpolationAngularVelocity(),m_localTime,interpolatedTransform);
|
||||
body->getMotionState()->setWorldTransform(interpolatedTransform);
|
||||
}
|
||||
}
|
||||
@@ -439,8 +438,8 @@ void btDiscreteDynamicsWorld::calculateSimulationIslands()
|
||||
if (colObj0->IsActive() || colObj1->IsActive())
|
||||
{
|
||||
|
||||
getSimulationIslandManager()->getUnionFind().unite((colObj0)->m_islandTag1,
|
||||
(colObj1)->m_islandTag1);
|
||||
getSimulationIslandManager()->getUnionFind().unite((colObj0)->getIslandTag(),
|
||||
(colObj1)->getIslandTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,13 +500,13 @@ void btDiscreteDynamicsWorld::updateAabbs()
|
||||
// if (body->IsActive() && (!body->IsStatic()))
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->getAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
||||
btSimpleBroadphase* bp = (btSimpleBroadphase*)m_broadphasePairCache;
|
||||
|
||||
//moving objects should be moderately sized, probably something wrong if not
|
||||
if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < 1e12f))
|
||||
{
|
||||
bp->setAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
bp->setAabb(body->getBroadphaseHandle(),minAabb,maxAabb);
|
||||
} else
|
||||
{
|
||||
//something went wrong, investigate
|
||||
@@ -575,7 +574,7 @@ void btDiscreteDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
body->integrateVelocities( timeStep);
|
||||
body->predictIntegratedTransform(timeStep,body->m_interpolationWorldTransform);
|
||||
body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -768,3 +767,13 @@ void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btDiscreteDynamicsWorld::setConstraintSolver(btConstraintSolver* solver)
|
||||
{
|
||||
if (m_ownsConstraintSolver)
|
||||
{
|
||||
delete m_constraintSolver;
|
||||
}
|
||||
m_ownsConstraintSolver = false;
|
||||
m_constraintSolver = solver;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver=0);
|
||||
|
||||
///this btDiscreteDynamicsWorld will create and own dispatcher, pairCache and constraintSolver, and deletes it in the destructor.
|
||||
btDiscreteDynamicsWorld();
|
||||
btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver = 0);
|
||||
|
||||
virtual ~btDiscreteDynamicsWorld();
|
||||
|
||||
@@ -136,6 +136,7 @@ public:
|
||||
|
||||
void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
|
||||
|
||||
virtual void setConstraintSolver(btConstraintSolver* solver);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
|
||||
class btTypedConstraint;
|
||||
class btRaycastVehicle;
|
||||
class btConstraintSolver;
|
||||
|
||||
|
||||
///btDynamicsWorld is the baseclass for several dynamics implementation, basic, discrete, parallel, and continuous
|
||||
class btDynamicsWorld : public btCollisionWorld
|
||||
@@ -65,6 +67,8 @@ class btDynamicsWorld : public btCollisionWorld
|
||||
|
||||
virtual void removeRigidBody(btRigidBody* body) = 0;
|
||||
|
||||
virtual void setConstraintSolver(btConstraintSolver* solver) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -42,7 +42,13 @@ btRigidBody::btRigidBody(float mass, btMotionState* motionState, btCollisionShap
|
||||
m_frictionSolverType(0)
|
||||
{
|
||||
|
||||
motionState->getWorldTransform(m_worldTransform);
|
||||
if (motionState)
|
||||
{
|
||||
motionState->getWorldTransform(m_worldTransform);
|
||||
} else
|
||||
{
|
||||
m_worldTransform = btTransform::getIdentity();
|
||||
}
|
||||
|
||||
m_interpolationWorldTransform = m_worldTransform;
|
||||
m_interpolationLinearVelocity.setValue(0,0,0);
|
||||
@@ -64,7 +70,7 @@ btRigidBody::btRigidBody(float mass, btMotionState* motionState, btCollisionShap
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef OBSOLETE_MOTIONSTATE_LESS
|
||||
btRigidBody::btRigidBody( float mass,const btTransform& worldTransform,btCollisionShape* collisionShape,const btVector3& localInertia,btScalar linearDamping,btScalar angularDamping,btScalar friction,btScalar restitution)
|
||||
:
|
||||
m_gravity(0.0f, 0.0f, 0.0f),
|
||||
@@ -100,30 +106,34 @@ btRigidBody::btRigidBody( float mass,const btTransform& worldTransform,btCollisi
|
||||
|
||||
}
|
||||
|
||||
#endif //OBSOLETE_MOTIONSTATE_LESS
|
||||
|
||||
|
||||
#define EXPERIMENTAL_JITTER_REMOVAL 1
|
||||
#ifdef EXPERIMENTAL_JITTER_REMOVAL
|
||||
//Bullet 2.20b has experimental code to reduce jitter just before objects fall asleep/deactivate
|
||||
//doesn't work very well yet (value 0 only reduces performance a bit, no difference in functionality)
|
||||
float gClippedAngvelThresholdSqr = 0.f;
|
||||
float gClippedLinearThresholdSqr = 0.f;
|
||||
//Bullet 2.20b has experimental damping code to reduce jitter just before objects fall asleep/deactivate
|
||||
//doesn't work very well yet (value 0 disabled this damping)
|
||||
//note there this influences deactivation thresholds!
|
||||
float gClippedAngvelThresholdSqr = 0.01f;
|
||||
float gClippedLinearThresholdSqr = 0.01f;
|
||||
float gJitterVelocityDampingFactor = 1.0f;
|
||||
#endif //EXPERIMENTAL_JITTER_REMOVAL
|
||||
|
||||
void btRigidBody::predictIntegratedTransform(btScalar timeStep,btTransform& predictedTransform)
|
||||
{
|
||||
|
||||
#ifdef EXPERIMENTAL_JITTER_REMOVAL
|
||||
//clip to avoid jitter
|
||||
if (m_angularVelocity.length2() < gClippedAngvelThresholdSqr)
|
||||
if (wantsSleeping())
|
||||
{
|
||||
m_angularVelocity.setValue(0,0,0);
|
||||
printf("clipped!\n");
|
||||
//clip to avoid jitter
|
||||
// if ((m_angularVelocity.length2() < gClippedAngvelThresholdSqr) &&
|
||||
// (m_linearVelocity.length2() < gClippedLinearThresholdSqr))
|
||||
{
|
||||
m_angularVelocity *= gJitterVelocityDampingFactor;
|
||||
m_linearVelocity *= gJitterVelocityDampingFactor;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_linearVelocity.length2() < gClippedLinearThresholdSqr)
|
||||
{
|
||||
m_linearVelocity.setValue(0,0,0);
|
||||
printf("clipped!\n");
|
||||
}
|
||||
#endif //EXPERIMENTAL_JITTER_REMOVAL
|
||||
|
||||
btTransformUtil::integrateTransform(m_worldTransform,m_linearVelocity,m_angularVelocity,timeStep,predictedTransform);
|
||||
|
||||
@@ -62,7 +62,11 @@ class btRigidBody : public btCollisionObject
|
||||
|
||||
public:
|
||||
|
||||
#ifdef OBSOLETE_MOTIONSTATE_LESS
|
||||
//not supported, please use btMotionState
|
||||
btRigidBody(float mass, const btTransform& worldTransform, btCollisionShape* collisionShape, const btVector3& localInertia=btVector3(0,0,0),btScalar linearDamping=0.f,btScalar angularDamping=0.f,btScalar friction=0.5f,btScalar restitution=0.f);
|
||||
#endif //OBSOLETE_MOTIONSTATE_LESS
|
||||
|
||||
btRigidBody(float mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia=btVector3(0,0,0),btScalar linearDamping=0.f,btScalar angularDamping=0.f,btScalar friction=0.5f,btScalar restitution=0.f);
|
||||
|
||||
void proceedToTransform(const btTransform& newTrans);
|
||||
@@ -71,11 +75,11 @@ public:
|
||||
///but a rigidbody is derived from btCollisionObject, so we can safely perform an upcast
|
||||
static const btRigidBody* upcast(const btCollisionObject* colObj)
|
||||
{
|
||||
return (const btRigidBody*)colObj->m_internalOwner;
|
||||
return (const btRigidBody*)colObj->getInternalOwner();
|
||||
}
|
||||
static btRigidBody* upcast(btCollisionObject* colObj)
|
||||
{
|
||||
return (btRigidBody*)colObj->m_internalOwner;
|
||||
return (btRigidBody*)colObj->getInternalOwner();
|
||||
}
|
||||
|
||||
/// continuous collision detection needs prediction
|
||||
|
||||
@@ -117,9 +117,9 @@ void btSimpleDynamicsWorld::updateAabbs()
|
||||
if (body->IsActive() && (!body->isStaticObject()))
|
||||
{
|
||||
btPoint3 minAabb,maxAabb;
|
||||
colObj->m_collisionShape->getAabb(colObj->m_worldTransform, minAabb,maxAabb);
|
||||
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
|
||||
btBroadphaseInterface* bp = getBroadphase();
|
||||
bp->setAabb(body->m_broadphaseHandle,minAabb,maxAabb);
|
||||
bp->setAabb(body->getBroadphaseHandle(),minAabb,maxAabb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ void btSimpleDynamicsWorld::predictUnconstraintMotion(float timeStep)
|
||||
{
|
||||
body->applyForces( timeStep);
|
||||
body->integrateVelocities( timeStep);
|
||||
body->predictIntegratedTransform(timeStep,body->m_interpolationWorldTransform);
|
||||
body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,9 +178,20 @@ void btSimpleDynamicsWorld::synchronizeMotionStates()
|
||||
{
|
||||
if (body->GetActivationState() != ISLAND_SLEEPING)
|
||||
{
|
||||
body->getMotionState()->setWorldTransform(body->m_worldTransform);
|
||||
body->getMotionState()->setWorldTransform(body->getWorldTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void btSimpleDynamicsWorld::setConstraintSolver(btConstraintSolver* solver)
|
||||
{
|
||||
if (m_ownsConstraintSolver)
|
||||
{
|
||||
delete m_constraintSolver;
|
||||
}
|
||||
m_ownsConstraintSolver = false;
|
||||
m_constraintSolver = solver;
|
||||
}
|
||||
@@ -77,6 +77,8 @@ public:
|
||||
|
||||
void synchronizeMotionStates();
|
||||
|
||||
virtual void setConstraintSolver(btConstraintSolver* solver);
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_SIMPLE_DYNAMICS_WORLD_H
|
||||
|
||||
Reference in New Issue
Block a user