MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / initBeforeSolve

Method initBeforeSolve

src/systems/SolveFixedJointSystem.cpp:48–142  ·  view source on GitHub ↗

Initialize before solving the constraint

Source from the content-addressed store, hash-verified

46
47// Initialize before solving the constraint
48void SolveFixedJointSystem::initBeforeSolve() {
49
50 const decimal biasFactor = BETA / mTimeStep;
51
52 // For each joint
53 const uint32 nbJoints = mFixedJointComponents.getNbEnabledComponents();
54 for (uint32 i=0; i < nbJoints; i++) {
55
56 const Entity jointEntity = mFixedJointComponents.mJointEntities[i];
57 const uint32 jointIndex = mJointComponents.getEntityIndex(jointEntity);
58
59 // Get the bodies entities
60 const Entity body1Entity = mJointComponents.mBody1Entities[jointIndex];
61 const Entity body2Entity = mJointComponents.mBody2Entities[jointIndex];
62
63 const uint32 componentIndexBody1 = mRigidBodyComponents.getEntityIndex(body1Entity);
64 const uint32 componentIndexBody2 = mRigidBodyComponents.getEntityIndex(body2Entity);
65
66 assert(!mRigidBodyComponents.getIsEntityDisabled(body1Entity) || !mRigidBodyComponents.getIsEntityDisabled(body2Entity));
67
68 // Get the inertia tensor of bodies
69 mFixedJointComponents.mI1[i] = mRigidBodyComponents.mInverseInertiaTensorsWorld[componentIndexBody1];
70 mFixedJointComponents.mI2[i] = mRigidBodyComponents.mInverseInertiaTensorsWorld[componentIndexBody2];
71
72 const Quaternion& orientationBody1 = mTransformComponents.getTransform(body1Entity).getOrientation();
73 const Quaternion& orientationBody2 = mTransformComponents.getTransform(body2Entity).getOrientation();
74
75 // Compute the vector from body center to the anchor point in world-space
76 mFixedJointComponents.mR1World[i] = orientationBody1 * (mFixedJointComponents.mLocalAnchorPointBody1[i] - mRigidBodyComponents.mCentersOfMassLocal[componentIndexBody1]);
77 mFixedJointComponents.mR2World[i] = orientationBody2 * (mFixedJointComponents.mLocalAnchorPointBody2[i] - mRigidBodyComponents.mCentersOfMassLocal[componentIndexBody2]);
78
79 // Compute the corresponding skew-symmetric matrices
80 Matrix3x3 skewSymmetricMatrixU1 = Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(mFixedJointComponents.mR1World[i]);
81 Matrix3x3 skewSymmetricMatrixU2 = Matrix3x3::computeSkewSymmetricMatrixForCrossProduct(mFixedJointComponents.mR2World[i]);
82
83 // Compute the matrix K=JM^-1J^t (3x3 matrix) for the 3 translation constraints
84 const decimal body1MassInverse = mRigidBodyComponents.mInverseMasses[componentIndexBody1];
85 const decimal body2MassInverse = mRigidBodyComponents.mInverseMasses[componentIndexBody2];
86 const decimal inverseMassBodies = body1MassInverse + body2MassInverse;
87 Matrix3x3 massMatrix = Matrix3x3(inverseMassBodies, 0, 0,
88 0, inverseMassBodies, 0,
89 0, 0, inverseMassBodies) +
90 skewSymmetricMatrixU1 * mFixedJointComponents.mI1[i] * skewSymmetricMatrixU1.getTranspose() +
91 skewSymmetricMatrixU2 * mFixedJointComponents.mI2[i] * skewSymmetricMatrixU2.getTranspose();
92
93 // Compute the inverse mass matrix K^-1 for the 3 translation constraints
94 mFixedJointComponents.mInverseMassMatrixTranslation[i].setToZero();
95 decimal massMatrixDeterminant = massMatrix.getDeterminant();
96 if (std::abs(massMatrixDeterminant) > MACHINE_EPSILON) {
97 if (mRigidBodyComponents.mBodyTypes[componentIndexBody1] == BodyType::DYNAMIC ||
98 mRigidBodyComponents.mBodyTypes[componentIndexBody2] == BodyType::DYNAMIC) {
99 mFixedJointComponents.mInverseMassMatrixTranslation[i] = massMatrix.getInverse(massMatrixDeterminant);
100 }
101 }
102
103 // Get the bodies positions and orientations
104 const Vector3& x1 = mRigidBodyComponents.mCentersOfMassWorld[componentIndexBody1];
105 const Vector3& x2 = mRigidBodyComponents.mCentersOfMassWorld[componentIndexBody2];

Callers

nothing calls this directly

Calls 9

getEntityIndexMethod · 0.80
getIsEntityDisabledMethod · 0.80
getVectorVMethod · 0.80
Matrix3x3Class · 0.50
getTransposeMethod · 0.45
setToZeroMethod · 0.45
getDeterminantMethod · 0.45
getInverseMethod · 0.45

Tested by

no test coverage detected