Warm start the constraint (apply the previous impulse at the beginning of the step)
| 160 | |
| 161 | // Warm start the constraint (apply the previous impulse at the beginning of the step) |
| 162 | void SolveBallAndSocketJointSystem::warmstart() { |
| 163 | |
| 164 | // For each joint component |
| 165 | const uint32 nbJoints = mBallAndSocketJointComponents.getNbEnabledComponents(); |
| 166 | for (uint32 i=0; i < nbJoints; i++) { |
| 167 | |
| 168 | const Entity jointEntity = mBallAndSocketJointComponents.mJointEntities[i]; |
| 169 | const uint32 jointIndex = mJointComponents.getEntityIndex(jointEntity); |
| 170 | |
| 171 | const Entity body1Entity = mJointComponents.mBody1Entities[jointIndex]; |
| 172 | const Entity body2Entity = mJointComponents.mBody2Entities[jointIndex]; |
| 173 | |
| 174 | const uint32 componentIndexBody1 = mRigidBodyComponents.getEntityIndex(body1Entity); |
| 175 | const uint32 componentIndexBody2 = mRigidBodyComponents.getEntityIndex(body2Entity); |
| 176 | |
| 177 | // Get the velocities |
| 178 | Vector3& v1 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody1]; |
| 179 | Vector3& v2 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody2]; |
| 180 | Vector3& w1 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody1]; |
| 181 | Vector3& w2 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody2]; |
| 182 | |
| 183 | const Vector3& r1World = mBallAndSocketJointComponents.mR1World[i]; |
| 184 | const Vector3& r2World = mBallAndSocketJointComponents.mR2World[i]; |
| 185 | |
| 186 | const Matrix3x3& i1 = mBallAndSocketJointComponents.mI1[i]; |
| 187 | const Matrix3x3& i2 = mBallAndSocketJointComponents.mI2[i]; |
| 188 | |
| 189 | // Compute the impulse P=J^T * lambda for the body 1 |
| 190 | Vector3 linearImpulseBody1 = -mBallAndSocketJointComponents.mImpulse[i]; |
| 191 | Vector3 angularImpulseBody1 = mBallAndSocketJointComponents.mImpulse[i].cross(r1World); |
| 192 | |
| 193 | // Compute the impulse P=J^T * lambda for the lower and upper limits constraints |
| 194 | const Vector3 coneLimitImpulse = mBallAndSocketJointComponents.mConeLimitImpulse[i] * mBallAndSocketJointComponents.mConeLimitACrossB[i]; |
| 195 | |
| 196 | // Compute the impulse P=J^T * lambda for the cone limit constraint of body 1 |
| 197 | angularImpulseBody1 += coneLimitImpulse; |
| 198 | |
| 199 | // Apply the impulse to the body 1 |
| 200 | v1 += mRigidBodyComponents.mInverseMasses[componentIndexBody1] * mRigidBodyComponents.mLinearLockAxisFactors[componentIndexBody1] * linearImpulseBody1; |
| 201 | w1 += mRigidBodyComponents.mAngularLockAxisFactors[componentIndexBody1] * (i1 * angularImpulseBody1); |
| 202 | |
| 203 | // Compute the impulse P=J^T * lambda for the body 2 |
| 204 | Vector3 angularImpulseBody2 = -mBallAndSocketJointComponents.mImpulse[i].cross(r2World); |
| 205 | |
| 206 | // Compute the impulse P=J^T * lambda for the cone limit constraint of body 2 |
| 207 | angularImpulseBody2 += -coneLimitImpulse; |
| 208 | |
| 209 | // Apply the impulse to the body to the body 2 |
| 210 | v2 += mRigidBodyComponents.mInverseMasses[componentIndexBody2] * mRigidBodyComponents.mLinearLockAxisFactors[componentIndexBody2] * mBallAndSocketJointComponents.mImpulse[i]; |
| 211 | w2 += mRigidBodyComponents.mAngularLockAxisFactors[componentIndexBody2] * (i2 * angularImpulseBody2); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // Solve the velocity constraint |
| 216 | void SolveBallAndSocketJointSystem::solveVelocityConstraint() { |
nothing calls this directly
no test coverage detected