applied patches from Marten (Starbreeze) for per-rigidbody sleeping thresholds, access to constraint references.
Also added assert, to make sure users don't delete rigidbodies while constraints point to them.
This commit is contained in:
@@ -22,6 +22,7 @@ btCollisionObject::btCollisionObject()
|
||||
m_activationState1(1),
|
||||
m_deactivationTime(btScalar(0.)),
|
||||
m_userObjectPointer(0),
|
||||
m_internalOwner(0),
|
||||
m_hitFraction(btScalar(1.)),
|
||||
m_ccdSweptSphereRadius(btScalar(0.)),
|
||||
m_ccdSquareMotionThreshold(btScalar(0.)),
|
||||
|
||||
@@ -39,6 +39,8 @@ btRigidBody::btRigidBody(btScalar mass, btMotionState* motionState, btCollisionS
|
||||
m_totalTorque(btScalar(0.0), btScalar(0.0), btScalar(0.0)),
|
||||
m_linearDamping(btScalar(0.)),
|
||||
m_angularDamping(btScalar(0.5)),
|
||||
m_linearSleepingThreshold(gLinearSleepingThreshold),
|
||||
m_angularSleepingThreshold(gAngularSleepingThreshold),
|
||||
m_optionalMotionState(motionState),
|
||||
m_contactSolverType(0),
|
||||
m_frictionSolverType(0)
|
||||
@@ -79,12 +81,15 @@ btRigidBody::btRigidBody( btScalar mass,const btTransform& worldTransform,btColl
|
||||
m_totalForce(btScalar(0.0), btScalar(0.0), btScalar(0.0)),
|
||||
m_totalTorque(btScalar(0.0), btScalar(0.0), btScalar(0.0)),
|
||||
m_linearVelocity(btScalar(0.0), btScalar(0.0), btScalar(0.0)),
|
||||
m_angularVelocity(btScalar(0.),btScalar(0.),btScalar(0.)),
|
||||
m_angularVelocity(btScalar(0.),btScalar(0.),btScalar(0.)),
|
||||
m_linearSleepingThreshold(gLinearSleepingThreshold),
|
||||
m_angularSleepingThreshold(gAngularSleepingThreshold),
|
||||
m_linearDamping(btScalar(0.)),
|
||||
m_angularDamping(btScalar(0.5)),
|
||||
m_optionalMotionState(0),
|
||||
m_contactSolverType(0),
|
||||
m_frictionSolverType(0)
|
||||
|
||||
{
|
||||
|
||||
m_worldTransform = worldTransform;
|
||||
|
||||
@@ -53,7 +53,10 @@ class btRigidBody : public btCollisionObject
|
||||
|
||||
btScalar m_linearDamping;
|
||||
btScalar m_angularDamping;
|
||||
|
||||
|
||||
btScalar m_linearSleepingThreshold;
|
||||
btScalar m_angularSleepingThreshold;
|
||||
|
||||
|
||||
//m_optionalMotionState allows to automatic synchronize the world transform for active objects
|
||||
btMotionState* m_optionalMotionState;
|
||||
@@ -70,6 +73,14 @@ public:
|
||||
|
||||
btRigidBody(btScalar mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia=btVector3(0,0,0),btScalar linearDamping=btScalar(0.),btScalar angularDamping=btScalar(0.),btScalar friction=btScalar(0.5),btScalar restitution=btScalar(0.));
|
||||
|
||||
virtual ~btRigidBody()
|
||||
{
|
||||
//No constraints should point to this rigidbody
|
||||
//Remove constraints from the dynamics world before you delete the related rigidbodies.
|
||||
btAssert(m_constraintRefs.size()==0);
|
||||
}
|
||||
|
||||
|
||||
void proceedToTransform(const btTransform& newTrans);
|
||||
|
||||
///to keep collision detection and dynamics separate we don't store a rigidbody pointer
|
||||
@@ -134,6 +145,12 @@ public:
|
||||
m_invInertiaLocal = diagInvInertia;
|
||||
}
|
||||
|
||||
void setSleepingThresholds(btScalar linear,btScalar angular)
|
||||
{
|
||||
m_linearSleepingThreshold = linear;
|
||||
m_angularSleepingThreshold = angular;
|
||||
}
|
||||
|
||||
void applyTorque(const btVector3& torque)
|
||||
{
|
||||
m_totalTorque += torque;
|
||||
@@ -258,11 +275,12 @@ public:
|
||||
|
||||
inline void updateDeactivation(btScalar timeStep)
|
||||
{
|
||||
return;
|
||||
if ( (getActivationState() == ISLAND_SLEEPING) || (getActivationState() == DISABLE_DEACTIVATION))
|
||||
return;
|
||||
|
||||
if ((getLinearVelocity().length2() < gLinearSleepingThreshold*gLinearSleepingThreshold) &&
|
||||
(getAngularVelocity().length2() < gAngularSleepingThreshold*gAngularSleepingThreshold))
|
||||
if ((getLinearVelocity().length2() < m_linearSleepingThreshold*m_linearSleepingThreshold) &&
|
||||
(getAngularVelocity().length2() < m_angularSleepingThreshold*m_angularSleepingThreshold))
|
||||
{
|
||||
m_deactivationTime += timeStep;
|
||||
} else
|
||||
@@ -348,6 +366,17 @@ public:
|
||||
void addConstraintRef(btTypedConstraint* c);
|
||||
void removeConstraintRef(btTypedConstraint* c);
|
||||
|
||||
btTypedConstraint* getConstraintRef(int index)
|
||||
{
|
||||
return m_constraintRefs[index];
|
||||
}
|
||||
|
||||
int getNumConstraintRefs()
|
||||
{
|
||||
return m_constraintRefs.size();
|
||||
}
|
||||
|
||||
|
||||
int m_debugBodyId;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user