Initialize before solving the constraint
| 46 | |
| 47 | // Initialize before solving the constraint |
| 48 | void SolveSliderJointSystem::initBeforeSolve() { |
| 49 | |
| 50 | const decimal biasFactor = (BETA / mTimeStep); |
| 51 | |
| 52 | // For each joint |
| 53 | const uint32 nbJoints = mSliderJointComponents.getNbEnabledComponents(); |
| 54 | for (uint32 i=0; i < nbJoints; i++) { |
| 55 | |
| 56 | const Entity jointEntity = mSliderJointComponents.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 | mSliderJointComponents.mI1[i] = mRigidBodyComponents.mInverseInertiaTensorsWorld[componentIndexBody1]; |
| 70 | mSliderJointComponents.mI2[i] = mRigidBodyComponents.mInverseInertiaTensorsWorld[componentIndexBody2]; |
| 71 | |
| 72 | const Quaternion& orientationBody1 = mTransformComponents.getTransform(body1Entity).getOrientation(); |
| 73 | const Quaternion& orientationBody2 = mTransformComponents.getTransform(body2Entity).getOrientation(); |
| 74 | |
| 75 | // Vector from body center to the anchor point |
| 76 | mSliderJointComponents.mR1[i] = orientationBody1 * (mSliderJointComponents.mLocalAnchorPointBody1[i] - mRigidBodyComponents.mCentersOfMassLocal[componentIndexBody1]); |
| 77 | mSliderJointComponents.mR2[i] = orientationBody2 * (mSliderJointComponents.mLocalAnchorPointBody2[i] - mRigidBodyComponents.mCentersOfMassLocal[componentIndexBody2]); |
| 78 | |
| 79 | // Compute the two orthogonal vectors to the slider axis in world-space |
| 80 | mSliderJointComponents.mSliderAxisWorld[i] = orientationBody1 * mSliderJointComponents.mSliderAxisBody1[i]; |
| 81 | mSliderJointComponents.mSliderAxisWorld[i].normalize(); |
| 82 | |
| 83 | mSliderJointComponents.mN1[i] = mSliderJointComponents.mSliderAxisWorld[i].getOneUnitOrthogonalVector(); |
| 84 | mSliderJointComponents.mN2[i] = mSliderJointComponents.mSliderAxisWorld[i].cross(mSliderJointComponents.mN1[i]); |
| 85 | |
| 86 | const Vector3& x1 = mRigidBodyComponents.mCentersOfMassWorld[componentIndexBody1]; |
| 87 | const Vector3& x2 = mRigidBodyComponents.mCentersOfMassWorld[componentIndexBody2]; |
| 88 | |
| 89 | const Vector3& r1 = mSliderJointComponents.mR1[i]; |
| 90 | const Vector3& r2 = mSliderJointComponents.mR2[i]; |
| 91 | |
| 92 | // Compute the vector u (difference between anchor points) |
| 93 | const Vector3 u = x2 + r2 - x1 - r1; |
| 94 | |
| 95 | // Compute the cross products used in the Jacobians |
| 96 | const Vector3 r1PlusU = mSliderJointComponents.mR1[i] + u; |
| 97 | mSliderJointComponents.mR1PlusUCrossN1[i] = r1PlusU.cross(mSliderJointComponents.mN1[i]); |
| 98 | mSliderJointComponents.mR1PlusUCrossN2[i] = r1PlusU.cross(mSliderJointComponents.mN2[i]); |
| 99 | mSliderJointComponents.mR1PlusUCrossSliderAxis[i] = r1PlusU.cross(mSliderJointComponents.mSliderAxisWorld[i]); |
| 100 | |
| 101 | // Check if the limit constraints are violated or not |
| 102 | decimal uDotSliderAxis = u.dot(mSliderJointComponents.mSliderAxisWorld[i]); |
| 103 | decimal lowerLimitError = uDotSliderAxis - mSliderJointComponents.mLowerLimit[i]; |
| 104 | decimal upperLimitError = mSliderJointComponents.mUpperLimit[i] - uDotSliderAxis; |
| 105 | bool oldIsLowerLimitViolated = mSliderJointComponents.mIsLowerLimitViolated[i]; |
nothing calls this directly
no test coverage detected