Warm start the constraint (apply the previous impulse at the beginning of the step)
| 143 | |
| 144 | // Warm start the constraint (apply the previous impulse at the beginning of the step) |
| 145 | void SolveFixedJointSystem::warmstart() { |
| 146 | |
| 147 | // For each joint |
| 148 | const uint32 nbJoints = mFixedJointComponents.getNbEnabledComponents(); |
| 149 | for (uint32 i=0; i < nbJoints; i++) { |
| 150 | |
| 151 | const Entity jointEntity = mFixedJointComponents.mJointEntities[i]; |
| 152 | const uint32 jointIndex = mJointComponents.getEntityIndex(jointEntity); |
| 153 | |
| 154 | // Get the bodies entities |
| 155 | const Entity body1Entity = mJointComponents.mBody1Entities[jointIndex]; |
| 156 | const Entity body2Entity = mJointComponents.mBody2Entities[jointIndex]; |
| 157 | |
| 158 | const uint32 componentIndexBody1 = mRigidBodyComponents.getEntityIndex(body1Entity); |
| 159 | const uint32 componentIndexBody2 = mRigidBodyComponents.getEntityIndex(body2Entity); |
| 160 | |
| 161 | // Get the velocities |
| 162 | Vector3& v1 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody1]; |
| 163 | Vector3& v2 = mRigidBodyComponents.mConstrainedLinearVelocities[componentIndexBody2]; |
| 164 | Vector3& w1 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody1]; |
| 165 | Vector3& w2 = mRigidBodyComponents.mConstrainedAngularVelocities[componentIndexBody2]; |
| 166 | |
| 167 | // Get the inverse mass of the bodies |
| 168 | const decimal inverseMassBody1 = mRigidBodyComponents.mInverseMasses[componentIndexBody1]; |
| 169 | const decimal inverseMassBody2 = mRigidBodyComponents.mInverseMasses[componentIndexBody2]; |
| 170 | |
| 171 | const Vector3& impulseTranslation = mFixedJointComponents.mImpulseTranslation[i]; |
| 172 | const Vector3& impulseRotation = mFixedJointComponents.mImpulseRotation[i]; |
| 173 | |
| 174 | const Vector3& r1World = mFixedJointComponents.mR1World[i]; |
| 175 | const Vector3& r2World = mFixedJointComponents.mR2World[i]; |
| 176 | |
| 177 | // Compute the impulse P=J^T * lambda for the 3 translation constraints for body 1 |
| 178 | Vector3 linearImpulseBody1 = -impulseTranslation; |
| 179 | Vector3 angularImpulseBody1 = impulseTranslation.cross(r1World); |
| 180 | |
| 181 | // Compute the impulse P=J^T * lambda for the 3 rotation constraints for body 1 |
| 182 | angularImpulseBody1 += -impulseRotation; |
| 183 | |
| 184 | const Matrix3x3& i1 = mFixedJointComponents.mI1[i]; |
| 185 | |
| 186 | // Apply the impulse to the body 1 |
| 187 | v1 += inverseMassBody1 * mRigidBodyComponents.mLinearLockAxisFactors[componentIndexBody1] * linearImpulseBody1; |
| 188 | w1 += mRigidBodyComponents.mAngularLockAxisFactors[componentIndexBody1] * (i1 * angularImpulseBody1); |
| 189 | |
| 190 | // Compute the impulse P=J^T * lambda for the 3 translation constraints for body 2 |
| 191 | Vector3 angularImpulseBody2 = -impulseTranslation.cross(r2World); |
| 192 | |
| 193 | // Compute the impulse P=J^T * lambda for the 3 rotation constraints for body 2 |
| 194 | angularImpulseBody2 += impulseRotation; |
| 195 | |
| 196 | const Matrix3x3& i2 = mFixedJointComponents.mI2[i]; |
| 197 | |
| 198 | // Apply the impulse to the body 2 |
| 199 | v2 += inverseMassBody2 * mRigidBodyComponents.mLinearLockAxisFactors[componentIndexBody2] * impulseTranslation; |
| 200 | w2 += mRigidBodyComponents.mAngularLockAxisFactors[componentIndexBody2] * (i2 * angularImpulseBody2); |
| 201 | } |
| 202 | } |
nothing calls this directly
no test coverage detected