38 nonContactResidual = 0;
46 nonContactResidual =
btMax(nonContactResidual, residual * residual);
54 leastSquaredResidual =
btMax(leastSquaredResidual, nonContactResidual);
69 leastSquaredResidual =
btMax(leastSquaredResidual, residual * residual);
94 leastSquaredResidual =
btMax(leastSquaredResidual, residual * residual);
124 leastSquaredResidual =
btMax(leastSquaredResidual, residual * residual);
159 leastSquaredResidual =
btMax(leastSquaredResidual, residual * residual);
190 leastSquaredResidual =
btMax(leastSquaredResidual, residual * residual);
200 return leastSquaredResidual;
215 for (
int i = 0; i < numBodies; i++)
231 for (
int i = 0; i < ndof; ++i)
248 for (
int i = 0; i < ndofA; ++i)
260 for (
int i = 0; i < ndofB; ++i)
291#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
304#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
333 for (
int i = 0; i < ndofA; ++i)
345 for (
int i = 0; i < ndofB; ++i)
370 for (
int i = 0; i < ndofA; ++i)
382 for (
int i = 0; i < ndofB; ++i)
403 if (sumA < -sumAclipped)
408 else if (sumA > sumAclipped)
418 if (sumB < -sumBclipped)
423 else if (sumB > sumBclipped)
446#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
459#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
473#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
486#ifdef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
503 BT_PROFILE(
"setupMultiBodyContactConstraint");
524 relaxation = infoGlobal.
m_sor;
569 if (solverConstraint.
m_linkA < 0)
577 const int ndofA = multiBodyA->
getNumDofs() + 6;
616 if (solverConstraint.
m_linkB < 0)
625 const int ndofB = multiBodyB->
getNumDofs() + 6;
671 for (
int i = 0; i < ndofA; ++i)
688 const int ndofB = multiBodyB->
getNumDofs() + 6;
691 for (
int i = 0; i < ndofB; ++i)
744 for (
int i = 0; i < ndofA; ++i)
761 for (
int i = 0; i < ndofB; ++i)
789 btScalar velocityError = restitution - rel_vel;
792 positionalError = -distance * erp / infoGlobal.
m_timeStep;
799 velocityError -= distance / infoGlobal.
m_timeStep;
803 positionalError = -distance * erp / infoGlobal.
m_timeStep;
815 solverConstraint.
m_rhs = penetrationImpulse + velocityImpulse;
830 solverConstraint.
m_rhs = penetrationImpulse + velocityImpulse;
896 BT_PROFILE(
"setupMultiBodyRollingFrictionConstraint");
917 relaxation = infoGlobal.
m_sor;
923 if (solverConstraint.
m_linkA < 0)
931 const int ndofA = multiBodyA->
getNumDofs() + 6;
956 btVector3 torqueAxis0 = constraintNormal;
962 btVector3 torqueAxis0 = constraintNormal;
970 if (solverConstraint.
m_linkB < 0)
979 const int ndofB = multiBodyB->
getNumDofs() + 6;
998 btVector3 torqueAxis1 = -constraintNormal;
1004 btVector3 torqueAxis1 = -constraintNormal;
1024 for (
int i = 0; i < ndofA; ++i)
1041 const int ndofB = multiBodyB->
getNumDofs() + 6;
1044 for (
int i = 0; i < ndofB; ++i)
1086 for (
int i = 0; i < ndofA; ++i)
1101 for (
int i = 0; i < ndofB; ++i)
1113 solverConstraint.
m_friction = combinedTorsionalFriction;
1129 btScalar velocityError = 0 - rel_vel;
1133 solverConstraint.
m_rhs = velocityImpulse;
1142btMultiBodySolverConstraint&
btMultiBodyConstraintSolver::addMultiBodyFrictionConstraint(
const btVector3& normalAxis,
const btScalar& appliedImpulse,
btPersistentManifold* manifold,
int frictionIndex,
btManifoldPoint& cp,
btCollisionObject* colObj0,
btCollisionObject* colObj1,
btScalar relaxation,
const btContactSolverInfo& infoGlobal,
btScalar desiredVelocity,
btScalar cfmSlip)
1144 BT_PROFILE(
"addMultiBodyFrictionConstraint");
1150 bool isFriction =
true;
1174 return solverConstraint;
1178 btScalar combinedTorsionalFriction,
1181 BT_PROFILE(
"addMultiBodyRollingFrictionConstraint");
1190 bool isFriction =
true;
1214 return solverConstraint;
1218 btScalar combinedTorsionalFriction,
1221 BT_PROFILE(
"addMultiBodyRollingFrictionConstraint");
1228 bool isFriction =
true;
1252 return solverConstraint;
1278 int rollingFriction = 4;
1308 bool isFriction =
false;
1315#define ENABLE_FRICTION
1316#ifdef ENABLE_FRICTION
1339 if (rollingFriction > 0)
1400 addMultiBodyFrictionConstraint(cp.
m_lateralFrictionDir1, cp.
m_appliedImpulseLateral1, manifold, frictionIndex, cp, colObj0, colObj1, relaxation, infoGlobal, cp.
m_contactMotion1, cp.
m_frictionCFM);
1403 addMultiBodyFrictionConstraint(cp.
m_lateralFrictionDir2, cp.
m_appliedImpulseLateral2, manifold, frictionIndex, cp, colObj0, colObj1, relaxation, infoGlobal, cp.
m_contactMotion2, cp.
m_frictionCFM);
1421 for (
int i = 0; i < numManifolds; i++)
1508 forceVector.
resize(numDofsPlusBase);
1509 for (
int i=0;i<numDofsPlusBase;i++)
1511 forceVector[i] = data.
m_jacobians[jacIndex+i]*appliedImpulse;
1514 output.resize(numDofsPlusBase);
1515 bool applyJointFeedback =
true;
1574#ifndef DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
1590 BT_PROFILE(
"btMultiBodyConstraintSolver::solveGroupCacheFriendlyFinish");
1595 for (
int i = 0; i < numPoolConstraints; i++)
1617 for (
int j = 0; j < numPoolConstraints; j++)
1641 for (
int j=0;j<numPoolConstraints;j++)
1712 for (
int i=0;i<numPoolConstraints;i++)
1740void btMultiBodyConstraintSolver::solveMultiBodyGroup(
btCollisionObject** bodies,
int numBodies,
btPersistentManifold** manifold,
int numManifolds,
btTypedConstraint** constraints,
int numConstraints,
btMultiBodyConstraint** multiBodyConstraints,
int numMultiBodyConstraints,
const btContactSolverInfo& info,
btIDebugDraw* debugDrawer,
btDispatcher* dispatcher)
@ BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED
@ BT_CONTACT_FLAG_HAS_CONTACT_ERP
@ BT_CONTACT_FLAG_HAS_CONTACT_CFM
@ BT_CONTACT_FLAG_CONTACT_STIFFNESS_DAMPING
@ BT_CONTACT_FLAG_FRICTION_ANCHOR
const T & btMax(const T &a, const T &b)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btAtan2(btScalar x, btScalar y)
btScalar btSin(btScalar x)
btScalar btFabs(btScalar x)
btScalar btCos(btScalar x)
static T sum(const btAlignedObjectArray< T > &items)
#define btSimdScalar
Until we get other contributions, only use SIMD on Windows, when using Visual Studio 2008 or later,...
void btPlaneSpace1(const T &n, T &p, T &q)
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
T & expandNonInitializing()
btCollisionObject can be used to manage collision detection objects.
@ CF_ANISOTROPIC_ROLLING_FRICTION
@ CF_ANISOTROPIC_FRICTION
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
ManifoldContactPoint collects and maintains persistent contactpoints.
btScalar m_combinedSpinningFriction
btScalar m_combinedRollingFriction
btScalar getDistance() const
btScalar m_combinedContactStiffness1
btScalar m_combinedRestitution
btVector3 m_lateralFrictionDir2
btScalar m_combinedContactDamping1
const btVector3 & getPositionWorldOnB() const
btScalar m_appliedImpulseLateral2
const btVector3 & getPositionWorldOnA() const
btScalar m_appliedImpulse
btScalar m_appliedImpulseLateral1
btVector3 m_normalWorldOnB
btScalar m_combinedFriction
btScalar m_contactMotion2
btVector3 m_lateralFrictionDir1
btScalar m_contactMotion1
btScalar resolveSingleConstraintRowGeneric(const btMultiBodySolverConstraint &c)
btMultiBodyConstraint ** m_tmpMultiBodyConstraints
void writeBackSolverBodyToMultiBody(btMultiBodySolverConstraint &constraint, btScalar deltaTime)
int m_tmpNumMultiBodyConstraints
btMultiBodyConstraintArray m_multiBodyTorsionalFrictionContactConstraints
void convertContacts(btPersistentManifold **manifoldPtr, int numManifolds, const btContactSolverInfo &infoGlobal)
btMultiBodySolverConstraint & addMultiBodySpinningFrictionConstraint(const btVector3 &normalAxis, btPersistentManifold *manifold, int frictionIndex, btManifoldPoint &cp, btScalar combinedTorsionalFriction, btCollisionObject *colObj0, btCollisionObject *colObj1, btScalar relaxation, const btContactSolverInfo &infoGlobal, btScalar desiredVelocity=0, btScalar cfmSlip=0)
void applyDeltaVee(btScalar *deltaV, btScalar impulse, int velocityIndex, int ndof)
void setupMultiBodyContactConstraint(btMultiBodySolverConstraint &solverConstraint, const btVector3 &contactNormal, const btScalar &appliedImpulse, btManifoldPoint &cp, const btContactSolverInfo &infoGlobal, btScalar &relaxation, bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0)
btMultiBodyConstraintArray m_multiBodyNormalContactConstraints
virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject **bodies, int numBodies, const btContactSolverInfo &infoGlobal)
btMultiBodyConstraintArray m_multiBodySpinningFrictionContactConstraints
btMultiBodyConstraintArray m_multiBodyFrictionContactConstraints
virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
btMultiBodySolverConstraint & addMultiBodyFrictionConstraint(const btVector3 &normalAxis, const btScalar &appliedImpulse, btPersistentManifold *manifold, int frictionIndex, btManifoldPoint &cp, btCollisionObject *colObj0, btCollisionObject *colObj1, btScalar relaxation, const btContactSolverInfo &infoGlobal, btScalar desiredVelocity=0, btScalar cfmSlip=0)
btMultiBodySolverConstraint & addMultiBodyTorsionalFrictionConstraint(const btVector3 &normalAxis, btPersistentManifold *manifold, int frictionIndex, btManifoldPoint &cp, btScalar combinedTorsionalFriction, btCollisionObject *colObj0, btCollisionObject *colObj1, btScalar relaxation, const btContactSolverInfo &infoGlobal, btScalar desiredVelocity=0, btScalar cfmSlip=0)
btMultiBodyJacobianData m_data
btScalar resolveConeFrictionConstraintRows(const btMultiBodySolverConstraint &cA1, const btMultiBodySolverConstraint &cB)
virtual btScalar solveSingleIteration(int iteration, btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
void convertMultiBodyContact(btPersistentManifold *manifold, const btContactSolverInfo &infoGlobal)
virtual void solveMultiBodyGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, btMultiBodyConstraint **multiBodyConstraints, int numMultiBodyConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher)
void setupMultiBodyTorsionalFrictionConstraint(btMultiBodySolverConstraint &solverConstraint, const btVector3 &contactNormal, btManifoldPoint &cp, btScalar combinedTorsionalFriction, const btContactSolverInfo &infoGlobal, btScalar &relaxation, bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0)
btMultiBodyConstraintArray m_multiBodyNonContactConstraints
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher)
this method should not be called, it was just used during porting/integration of Featherstone btMulti...
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
btScalar getAppliedImpulse(int dof)
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
static btMultiBodyLinkCollider * upcast(btCollisionObject *colObj)
btMultiBody * m_multiBody
void fillContactJacobianMultiDof(int link, const btVector3 &contact_point, const btVector3 &normal, btScalar *jac, btAlignedObjectArray< btScalar > &scratch_r, btAlignedObjectArray< btVector3 > &scratch_v, btAlignedObjectArray< btMatrix3x3 > &scratch_m) const
const btVector3 & getBasePos() const
int getCompanionId() const
void addBaseConstraintForce(const btVector3 &f)
void addLinkConstraintForce(int i, const btVector3 &f)
const btMultibodyLink & getLink(int index) const
void calcAccelerationDeltasMultiDof(const btScalar *force, btScalar *output, btAlignedObjectArray< btScalar > &scratch_r, btAlignedObjectArray< btVector3 > &scratch_v) const
stepVelocitiesMultiDof is deprecated, use computeAccelerationsArticulatedBodyAlgorithmMultiDof instea...
void setPosUpdated(bool updated)
void addLinkConstraintTorque(int i, const btVector3 &t)
bool internalNeedsJointFeedback() const
void fillConstraintJacobianMultiDof(int link, const btVector3 &contact_point, const btVector3 &normal_ang, const btVector3 &normal_lin, btScalar *jac, btAlignedObjectArray< btScalar > &scratch_r, btAlignedObjectArray< btVector3 > &scratch_v, btAlignedObjectArray< btMatrix3x3 > &scratch_m) const
void addBaseConstraintTorque(const btVector3 &t)
void setCompanionId(int id)
void applyDeltaVeeMultiDof(const btScalar *delta_vee, btScalar multiplier)
void applyDeltaVeeMultiDof2(const btScalar *delta_vee, btScalar multiplier)
const btScalar * getVelocityVector() const
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
const btManifoldPoint & getContactPoint(int index) const
const btCollisionObject * getBody0() const
const btCollisionObject * getBody1() const
int getNumContacts() const
btScalar getContactProcessingThreshold() const
The btRigidBody is the main class for rigid body objects.
btVector3 getVelocityInLocalPoint(const btVector3 &rel_pos) const
const btVector3 & getTotalTorque() const
btScalar getInvMass() const
const btVector3 & getLinearFactor() const
const btVector3 & getTotalForce() const
const btVector3 & getAngularFactor() const
const btMatrix3x3 & getInvInertiaTensorWorld() const
virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject **bodies, int numBodies, const btContactSolverInfo &infoGlobal)
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher)
btSequentialImpulseConstraintSolver Sequentially applies impulses
static void applyAnisotropicFriction(btCollisionObject *colObj, btVector3 &frictionDirection, int frictionMode)
void convertContact(btPersistentManifold *manifold, const btContactSolverInfo &infoGlobal)
btAlignedObjectArray< btSolverBody > m_tmpSolverBodyPool
virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
int getOrInitSolverBody(btCollisionObject &body, btScalar timeStep)
btScalar restitutionCurve(btScalar rel_vel, btScalar restitution, btScalar velocityThreshold)
virtual btScalar solveSingleIteration(int iteration, btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
TypedConstraint is the baseclass for Bullet constraints and vehicles.
void setEnabled(bool enabled)
void internalSetAppliedImpulse(btScalar appliedImpulse)
internal method used by the constraint solver, don't use them directly
const btRigidBody & getRigidBodyA() const
btScalar getBreakingImpulseThreshold() const
const btRigidBody & getRigidBodyB() const
const btJointFeedback * getJointFeedback() const
btVector3 can be used to represent 3D points and vectors.
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
btScalar dot(const btVector3 &v) const
Return the dot product.
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
btVector3 m_appliedForceBodyA
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocities
btAlignedObjectArray< btScalar > m_jacobians
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
btAlignedObjectArray< btScalar > scratch_r
btAlignedObjectArray< btMatrix3x3 > scratch_m
btAlignedObjectArray< btVector3 > scratch_v
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
btMultiBodyConstraint * m_orgConstraint
btVector3 m_relpos1CrossNormal
void * m_originalContactPoint
btVector3 m_contactNormal2
btVector3 m_contactNormal1
btMultiBody * m_multiBodyB
btVector3 m_angularComponentA
btVector3 m_relpos2CrossNormal
btSimdScalar m_appliedImpulse
btSimdScalar m_appliedPushImpulse
btScalar m_rhsPenetration
btMultiBody * m_multiBodyA
btVector3 m_angularComponentB
btTransform m_cachedWorldTransform
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
btVector3 & internalGetDeltaAngularVelocity()
btVector3 m_angularVelocity
btRigidBody * m_originalBody
btVector3 m_linearVelocity
btVector3 & internalGetDeltaLinearVelocity()
some internal methods, don't use them
void internalApplyImpulse(const btVector3 &linearComponent, const btVector3 &angularComponent, const btScalar impulseMagnitude)
const btTransform & getWorldTransform() const
const btVector3 & internalGetInvMass() const
btVector3 m_externalForceImpulse