2017-08-01 12:30:58 +00:00
|
|
|
#ifndef B3_PGS_JACOBI_SOLVER
|
|
|
|
#define B3_PGS_JACOBI_SOLVER
|
|
|
|
|
|
|
|
struct b3Contact4;
|
|
|
|
struct b3ContactPoint;
|
|
|
|
|
|
|
|
class b3Dispatcher;
|
|
|
|
|
|
|
|
#include "b3TypedConstraint.h"
|
|
|
|
#include "b3ContactSolverInfo.h"
|
|
|
|
#include "b3SolverBody.h"
|
|
|
|
#include "b3SolverConstraint.h"
|
|
|
|
|
|
|
|
struct b3RigidBodyData;
|
|
|
|
struct b3InertiaData;
|
|
|
|
|
|
|
|
class b3PgsJacobiSolver
|
|
|
|
{
|
|
|
|
protected:
|
2019-01-03 13:26:51 +00:00
|
|
|
b3AlignedObjectArray<b3SolverBody> m_tmpSolverBodyPool;
|
|
|
|
b3ConstraintArray m_tmpSolverContactConstraintPool;
|
|
|
|
b3ConstraintArray m_tmpSolverNonContactConstraintPool;
|
|
|
|
b3ConstraintArray m_tmpSolverContactFrictionConstraintPool;
|
|
|
|
b3ConstraintArray m_tmpSolverContactRollingFrictionConstraintPool;
|
|
|
|
|
|
|
|
b3AlignedObjectArray<int> m_orderTmpConstraintPool;
|
|
|
|
b3AlignedObjectArray<int> m_orderNonContactConstraintPool;
|
|
|
|
b3AlignedObjectArray<int> m_orderFrictionConstraintPool;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3AlignedObjectArray<b3TypedConstraint::b3ConstraintInfo1> m_tmpConstraintSizesPool;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3AlignedObjectArray<int> m_bodyCount;
|
|
|
|
b3AlignedObjectArray<int> m_bodyCountCheck;
|
|
|
|
|
|
|
|
b3AlignedObjectArray<b3Vector3> m_deltaLinearVelocities;
|
|
|
|
b3AlignedObjectArray<b3Vector3> m_deltaAngularVelocities;
|
|
|
|
|
|
|
|
bool m_usePgs;
|
|
|
|
void averageVelocities();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int m_maxOverrideNumSolverIterations;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int m_numSplitImpulseRecoveries;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Scalar getContactProcessingThreshold(b3Contact4* contact)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return 0.02f;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
void setupFrictionConstraint(b3RigidBodyData* bodies, b3InertiaData* inertias, b3SolverConstraint& solverConstraint, const b3Vector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
|
|
|
|
b3ContactPoint& cp, const b3Vector3& rel_pos1, const b3Vector3& rel_pos2,
|
|
|
|
b3RigidBodyData* colObj0, b3RigidBodyData* colObj1, b3Scalar relaxation,
|
|
|
|
b3Scalar desiredVelocity = 0., b3Scalar cfmSlip = 0.);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setupRollingFrictionConstraint(b3RigidBodyData* bodies, b3InertiaData* inertias, b3SolverConstraint& solverConstraint, const b3Vector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
|
|
|
|
b3ContactPoint& cp, const b3Vector3& rel_pos1, const b3Vector3& rel_pos2,
|
|
|
|
b3RigidBodyData* colObj0, b3RigidBodyData* colObj1, b3Scalar relaxation,
|
|
|
|
b3Scalar desiredVelocity = 0., b3Scalar cfmSlip = 0.);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3SolverConstraint& addFrictionConstraint(b3RigidBodyData* bodies, b3InertiaData* inertias, const b3Vector3& normalAxis, int solverBodyIdA, int solverBodyIdB, int frictionIndex, b3ContactPoint& cp, const b3Vector3& rel_pos1, const b3Vector3& rel_pos2, b3RigidBodyData* colObj0, b3RigidBodyData* colObj1, b3Scalar relaxation, b3Scalar desiredVelocity = 0., b3Scalar cfmSlip = 0.);
|
|
|
|
b3SolverConstraint& addRollingFrictionConstraint(b3RigidBodyData* bodies, b3InertiaData* inertias, const b3Vector3& normalAxis, int solverBodyIdA, int solverBodyIdB, int frictionIndex, b3ContactPoint& cp, const b3Vector3& rel_pos1, const b3Vector3& rel_pos2, b3RigidBodyData* colObj0, b3RigidBodyData* colObj1, b3Scalar relaxation, b3Scalar desiredVelocity = 0, b3Scalar cfmSlip = 0.f);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
void setupContactConstraint(b3RigidBodyData* bodies, b3InertiaData* inertias,
|
2019-01-03 13:26:51 +00:00
|
|
|
b3SolverConstraint& solverConstraint, int solverBodyIdA, int solverBodyIdB, b3ContactPoint& cp,
|
|
|
|
const b3ContactSolverInfo& infoGlobal, b3Vector3& vel, b3Scalar& rel_vel, b3Scalar& relaxation,
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Vector3& rel_pos1, b3Vector3& rel_pos2);
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setFrictionConstraintImpulse(b3RigidBodyData* bodies, b3InertiaData* inertias, b3SolverConstraint& solverConstraint, int solverBodyIdA, int solverBodyIdB,
|
|
|
|
b3ContactPoint& cp, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction
|
2019-01-03 13:26:51 +00:00
|
|
|
unsigned long m_btSeed2;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
b3Scalar restitutionCurve(b3Scalar rel_vel, b3Scalar restitution);
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void convertContact(b3RigidBodyData* bodies, b3InertiaData* inertias, b3Contact4* manifold, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSplitPenetrationSIMD(
|
|
|
|
b3SolverBody& bodyA, b3SolverBody& bodyB,
|
|
|
|
const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSplitPenetrationImpulseCacheFriendly(
|
|
|
|
b3SolverBody& bodyA, b3SolverBody& bodyB,
|
|
|
|
const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//internal method
|
2019-01-03 13:26:51 +00:00
|
|
|
int getOrInitSolverBody(int bodyIndex, b3RigidBodyData* bodies, b3InertiaData* inertias);
|
|
|
|
void initSolverBody(int bodyIndex, b3SolverBody* solverBody, b3RigidBodyData* collisionObject);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSingleConstraintRowGeneric(b3SolverBody& bodyA, b3SolverBody& bodyB, const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSingleConstraintRowGenericSIMD(b3SolverBody& bodyA, b3SolverBody& bodyB, const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSingleConstraintRowLowerLimit(b3SolverBody& bodyA, b3SolverBody& bodyB, const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void resolveSingleConstraintRowLowerLimitSIMD(b3SolverBody& bodyA, b3SolverBody& bodyB, const b3SolverConstraint& contactConstraint);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
protected:
|
|
|
|
virtual b3Scalar solveGroupCacheFriendlySetup(b3RigidBodyData* bodies, b3InertiaData* inertias, int numBodies, b3Contact4* manifoldPtr, int numManifolds, b3TypedConstraint** constraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual b3Scalar solveGroupCacheFriendlyIterations(b3TypedConstraint** constraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
|
|
|
|
virtual void solveGroupCacheFriendlySplitImpulseIterations(b3TypedConstraint** constraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
|
|
|
|
b3Scalar solveSingleIteration(int iteration, b3TypedConstraint** constraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual b3Scalar solveGroupCacheFriendlyFinish(b3RigidBodyData* bodies, b3InertiaData* inertias, int numBodies, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
B3_DECLARE_ALIGNED_ALLOCATOR();
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
b3PgsJacobiSolver(bool usePgs);
|
|
|
|
virtual ~b3PgsJacobiSolver();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
// void solveContacts(int numBodies, b3RigidBodyData* bodies, b3InertiaData* inertias, int numContacts, b3Contact4* contacts);
|
|
|
|
void solveContacts(int numBodies, b3RigidBodyData* bodies, b3InertiaData* inertias, int numContacts, b3Contact4* contacts, int numConstraints, b3TypedConstraint** constraints);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Scalar solveGroup(b3RigidBodyData* bodies, b3InertiaData* inertias, int numBodies, b3Contact4* manifoldPtr, int numManifolds, b3TypedConstraint** constraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
///clear internal cached data and reset random seed
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void reset();
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
unsigned long b3Rand2();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int b3RandInt2(int n);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setRandSeed(unsigned long seed)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_btSeed2 = seed;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
unsigned long getRandSeed() const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_btSeed2;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //B3_PGS_JACOBI_SOLVER
|