move the m_maxAppliedImpulse into base class, and use it for motor strength/point to point constraint strength

This commit is contained in:
erwin.coumans
2013-10-22 21:49:52 +00:00
parent f22ceecb82
commit 0024c87316
8 changed files with 25 additions and 22 deletions

View File

@@ -194,7 +194,7 @@ void FeatherstoneMultiBodyDemo::initPhysics()
} }
btMultiBody* mbA = createFeatherstoneMultiBody(world, 4, btVector3 (60,29.5,-2)*scaling, false, true,true,true); btMultiBody* mbA = createFeatherstoneMultiBody(world, 2, btVector3 (60,29.5,-2)*scaling, false, true,true,true);
int numLinks = 10; int numLinks = 10;

View File

@@ -7,7 +7,8 @@ btMultiBodyConstraint::btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bod
m_linkA(linkA), m_linkA(linkA),
m_linkB(linkB), m_linkB(linkB),
m_num_rows(numRows), m_num_rows(numRows),
m_isUnilateral(isUnilateral) m_isUnilateral(isUnilateral),
m_maxAppliedImpulse(100)
{ {
m_jac_size_A = (6 + bodyA->getNumLinks()); m_jac_size_A = (6 + bodyA->getNumLinks());
m_jac_size_both = (m_jac_size_A + (bodyB ? 6 + bodyB->getNumLinks() : 0)); m_jac_size_both = (m_jac_size_A + (bodyB ? 6 + bodyB->getNumLinks() : 0));
@@ -519,8 +520,8 @@ void btMultiBodyConstraint::fillMultiBodyConstraintMixed(btMultiBodySolverConstr
} }
solverConstraint.m_cfm = 0.f; solverConstraint.m_cfm = 0.f;
solverConstraint.m_lowerLimit = 0; solverConstraint.m_lowerLimit = -m_maxAppliedImpulse;
solverConstraint.m_upperLimit = 1e10f; solverConstraint.m_upperLimit = m_maxAppliedImpulse;
} }
} }

View File

@@ -55,6 +55,9 @@ protected:
bool m_isUnilateral; bool m_isUnilateral;
btScalar m_maxAppliedImpulse;
// data block laid out as follows: // data block laid out as follows:
// cached impulses. (one per row.) // cached impulses. (one per row.)
// jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc) // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
@@ -147,6 +150,14 @@ public:
return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A]; return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A];
} }
btScalar getMaxAppliedImpulse() const
{
return m_maxAppliedImpulse;
}
void setMaxAppliedImpulse(btScalar maxImp)
{
m_maxAppliedImpulse = maxImp;
}
}; };

View File

@@ -90,7 +90,7 @@ void btMultiBodyJointLimitConstraint::createConstraintRows(btMultiBodyConstraint
constraintRow.m_multiBodyA = m_bodyA; constraintRow.m_multiBodyA = m_bodyA;
constraintRow.m_multiBodyB = m_bodyB; constraintRow.m_multiBodyB = m_bodyB;
btScalar rel_vel = fillConstraintRowMultiBodyMultiBody(constraintRow,data,jacobianA(row),jacobianB(row),infoGlobal,0,0,1e30); btScalar rel_vel = fillConstraintRowMultiBodyMultiBody(constraintRow,data,jacobianA(row),jacobianB(row),infoGlobal,0,-m_maxAppliedImpulse,m_maxAppliedImpulse);
{ {
btScalar penetration = getPosition(row); btScalar penetration = getPosition(row);
btScalar positionalError = 0.f; btScalar positionalError = 0.f;

View File

@@ -23,9 +23,9 @@ subject to the following restrictions:
btMultiBodyJointMotor::btMultiBodyJointMotor(btMultiBody* body, int link, btScalar desiredVelocity, btScalar maxMotorImpulse) btMultiBodyJointMotor::btMultiBodyJointMotor(btMultiBody* body, int link, btScalar desiredVelocity, btScalar maxMotorImpulse)
:btMultiBodyConstraint(body,body,link,link,1,true), :btMultiBodyConstraint(body,body,link,link,1,true),
m_desiredVelocity(desiredVelocity), m_desiredVelocity(desiredVelocity)
m_maxMotorImpulse(maxMotorImpulse)
{ {
m_maxAppliedImpulse = maxMotorImpulse;
// the data.m_jacobians never change, so may as well // the data.m_jacobians never change, so may as well
// initialize them here // initialize them here
@@ -82,7 +82,7 @@ void btMultiBodyJointMotor::createConstraintRows(btMultiBodyConstraintArray& con
btMultiBodySolverConstraint& constraintRow = constraintRows.expandNonInitializing(); btMultiBodySolverConstraint& constraintRow = constraintRows.expandNonInitializing();
btScalar penetration = 0; btScalar penetration = 0;
fillConstraintRowMultiBodyMultiBody(constraintRow,data,jacobianA(row),jacobianB(row),infoGlobal,m_desiredVelocity,-m_maxMotorImpulse,m_maxMotorImpulse); fillConstraintRowMultiBodyMultiBody(constraintRow,data,jacobianA(row),jacobianB(row),infoGlobal,m_desiredVelocity,-m_maxAppliedImpulse,m_maxAppliedImpulse);
} }
} }

View File

@@ -25,7 +25,7 @@ class btMultiBodyJointMotor : public btMultiBodyConstraint
{ {
protected: protected:
btScalar m_maxMotorImpulse;
btScalar m_desiredVelocity; btScalar m_desiredVelocity;
public: public:

View File

@@ -24,8 +24,7 @@ btMultiBodyPoint2Point::btMultiBodyPoint2Point(btMultiBody* body, int link, btRi
m_rigidBodyA(0), m_rigidBodyA(0),
m_rigidBodyB(bodyB), m_rigidBodyB(bodyB),
m_pivotInA(pivotInA), m_pivotInA(pivotInA),
m_pivotInB(pivotInB), m_pivotInB(pivotInB)
m_maxAppliedImpulse(1e30f)
{ {
} }
@@ -34,8 +33,7 @@ btMultiBodyPoint2Point::btMultiBodyPoint2Point(btMultiBody* bodyA, int linkA, bt
m_rigidBodyA(0), m_rigidBodyA(0),
m_rigidBodyB(0), m_rigidBodyB(0),
m_pivotInA(pivotInA), m_pivotInA(pivotInA),
m_pivotInB(pivotInB), m_pivotInB(pivotInB)
m_maxAppliedImpulse(1e30f)
{ {
} }

View File

@@ -28,7 +28,7 @@ protected:
btRigidBody* m_rigidBodyB; btRigidBody* m_rigidBodyB;
btVector3 m_pivotInA; btVector3 m_pivotInA;
btVector3 m_pivotInB; btVector3 m_pivotInB;
btScalar m_maxAppliedImpulse;
public: public:
@@ -54,14 +54,7 @@ public:
m_pivotInB = pivotInB; m_pivotInB = pivotInB;
} }
btScalar getMaxAppliedImpulse() const
{
return m_maxAppliedImpulse;
}
void setMaxAppliedImpulse(btScalar maxImp)
{
m_maxAppliedImpulse = maxImp;
}
}; };
#endif //BT_MULTIBODY_POINT2POINT_H #endif //BT_MULTIBODY_POINT2POINT_H