SliderConstraint.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <Jolt/Jolt.h>
  4. #include <Jolt/Physics/Constraints/SliderConstraint.h>
  5. #include <Jolt/Physics/Body/Body.h>
  6. #include <Jolt/ObjectStream/TypeDeclarations.h>
  7. #include <Jolt/Core/StreamIn.h>
  8. #include <Jolt/Core/StreamOut.h>
  9. #ifdef JPH_DEBUG_RENDERER
  10. #include <Jolt/Renderer/DebugRenderer.h>
  11. #endif // JPH_DEBUG_RENDERER
  12. JPH_NAMESPACE_BEGIN
  13. JPH_IMPLEMENT_SERIALIZABLE_VIRTUAL(SliderConstraintSettings)
  14. {
  15. JPH_ADD_BASE_CLASS(SliderConstraintSettings, TwoBodyConstraintSettings)
  16. JPH_ADD_ENUM_ATTRIBUTE(SliderConstraintSettings, mSpace)
  17. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mPoint1)
  18. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mSliderAxis1)
  19. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mNormalAxis1)
  20. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mPoint2)
  21. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mSliderAxis2)
  22. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mNormalAxis2)
  23. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mLimitsMin)
  24. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mLimitsMax)
  25. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mFrequency)
  26. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mDamping)
  27. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mMaxFrictionForce)
  28. JPH_ADD_ATTRIBUTE(SliderConstraintSettings, mMotorSettings)
  29. }
  30. void SliderConstraintSettings::SetPoint(const Body &inBody1, const Body &inBody2)
  31. {
  32. JPH_ASSERT(mSpace == EConstraintSpace::WorldSpace);
  33. // Determine anchor point: If any of the bodies can never be dynamic use the other body as anchor point
  34. Vec3 anchor;
  35. if (!inBody1.CanBeKinematicOrDynamic())
  36. anchor = inBody2.GetCenterOfMassPosition();
  37. else if (!inBody2.CanBeKinematicOrDynamic())
  38. anchor = inBody1.GetCenterOfMassPosition();
  39. else
  40. {
  41. // Otherwise use weighted anchor point towards the lightest body
  42. float inv_m1 = inBody1.GetMotionPropertiesUnchecked()->GetInverseMassUnchecked();
  43. float inv_m2 = inBody2.GetMotionPropertiesUnchecked()->GetInverseMassUnchecked();
  44. anchor = (inv_m1 * inBody1.GetCenterOfMassPosition() + inv_m2 * inBody2.GetCenterOfMassPosition()) / (inv_m1 + inv_m2);
  45. }
  46. mPoint1 = mPoint2 = anchor;
  47. }
  48. void SliderConstraintSettings::SetSliderAxis(Vec3Arg inSliderAxis)
  49. {
  50. JPH_ASSERT(mSpace == EConstraintSpace::WorldSpace);
  51. mSliderAxis1 = mSliderAxis2 = inSliderAxis;
  52. mNormalAxis1 = mNormalAxis2 = inSliderAxis.GetNormalizedPerpendicular();
  53. }
  54. void SliderConstraintSettings::SaveBinaryState(StreamOut &inStream) const
  55. {
  56. ConstraintSettings::SaveBinaryState(inStream);
  57. inStream.Write(mSpace);
  58. inStream.Write(mPoint1);
  59. inStream.Write(mSliderAxis1);
  60. inStream.Write(mNormalAxis1);
  61. inStream.Write(mPoint2);
  62. inStream.Write(mSliderAxis2);
  63. inStream.Write(mNormalAxis2);
  64. inStream.Write(mLimitsMin);
  65. inStream.Write(mLimitsMax);
  66. inStream.Write(mFrequency);
  67. inStream.Write(mDamping);
  68. inStream.Write(mMaxFrictionForce);
  69. mMotorSettings.SaveBinaryState(inStream);
  70. }
  71. void SliderConstraintSettings::RestoreBinaryState(StreamIn &inStream)
  72. {
  73. ConstraintSettings::RestoreBinaryState(inStream);
  74. inStream.Read(mSpace);
  75. inStream.Read(mPoint1);
  76. inStream.Read(mSliderAxis1);
  77. inStream.Read(mNormalAxis1);
  78. inStream.Read(mPoint2);
  79. inStream.Read(mSliderAxis2);
  80. inStream.Read(mNormalAxis2);
  81. inStream.Read(mLimitsMin);
  82. inStream.Read(mLimitsMax);
  83. inStream.Read(mFrequency);
  84. inStream.Read(mDamping);
  85. inStream.Read(mMaxFrictionForce);
  86. mMotorSettings.RestoreBinaryState(inStream);
  87. }
  88. TwoBodyConstraint *SliderConstraintSettings::Create(Body &inBody1, Body &inBody2) const
  89. {
  90. return new SliderConstraint(inBody1, inBody2, *this);
  91. }
  92. SliderConstraint::SliderConstraint(Body &inBody1, Body &inBody2, const SliderConstraintSettings &inSettings) :
  93. TwoBodyConstraint(inBody1, inBody2, inSettings),
  94. mLocalSpacePosition1(inSettings.mPoint1),
  95. mLocalSpacePosition2(inSettings.mPoint2),
  96. mLocalSpaceSliderAxis1(inSettings.mSliderAxis1),
  97. mLocalSpaceNormal1(inSettings.mNormalAxis1),
  98. mMaxFrictionForce(inSettings.mMaxFrictionForce),
  99. mMotorSettings(inSettings.mMotorSettings)
  100. {
  101. // Store inverse of initial rotation from body 1 to body 2 in body 1 space
  102. mInvInitialOrientation = RotationEulerConstraintPart::sGetInvInitialOrientationXY(inSettings.mSliderAxis1, inSettings.mNormalAxis1, inSettings.mSliderAxis2, inSettings.mNormalAxis2);
  103. if (inSettings.mSpace == EConstraintSpace::WorldSpace)
  104. {
  105. // If all properties were specified in world space, take them to local space now
  106. Mat44 inv_transform1 = inBody1.GetInverseCenterOfMassTransform();
  107. mLocalSpacePosition1 = inv_transform1 * mLocalSpacePosition1;
  108. mLocalSpaceSliderAxis1 = inv_transform1.Multiply3x3(mLocalSpaceSliderAxis1).Normalized();
  109. mLocalSpaceNormal1 = inv_transform1.Multiply3x3(mLocalSpaceNormal1).Normalized();
  110. mLocalSpacePosition2 = inBody2.GetInverseCenterOfMassTransform() * mLocalSpacePosition2;
  111. // Constraints were specified in world space, so we should have replaced c1 with q10^-1 c1 and c2 with q20^-1 c2
  112. // => r0^-1 = (q20^-1 c2) (q10^-1 c1)^1 = q20^-1 (c2 c1^-1) q10
  113. mInvInitialOrientation = inBody2.GetRotation().Conjugated() * mInvInitialOrientation * inBody1.GetRotation();
  114. }
  115. // Calculate 2nd local space normal
  116. mLocalSpaceNormal2 = mLocalSpaceSliderAxis1.Cross(mLocalSpaceNormal1);
  117. // Store limits
  118. JPH_ASSERT(inSettings.mLimitsMin != inSettings.mLimitsMax || inSettings.mFrequency > 0.0f, "Better use a fixed constraint");
  119. SetLimits(inSettings.mLimitsMin, inSettings.mLimitsMax);
  120. // Store frequency and damping
  121. SetFrequency(inSettings.mFrequency);
  122. SetDamping(inSettings.mDamping);
  123. }
  124. float SliderConstraint::GetCurrentPosition() const
  125. {
  126. // See: CalculateR1R2U and CalculateSlidingAxisAndPosition
  127. Vec3 r1 = mBody1->GetRotation() * mLocalSpacePosition1;
  128. Vec3 r2 = mBody2->GetRotation() * mLocalSpacePosition2;
  129. Vec3 u = mBody2->GetCenterOfMassPosition() + r2 - mBody1->GetCenterOfMassPosition() - r1;
  130. return u.Dot(mBody1->GetRotation() * mLocalSpaceSliderAxis1);
  131. }
  132. void SliderConstraint::SetLimits(float inLimitsMin, float inLimitsMax)
  133. {
  134. JPH_ASSERT(inLimitsMin <= 0.0f);
  135. JPH_ASSERT(inLimitsMax >= 0.0f);
  136. mLimitsMin = inLimitsMin;
  137. mLimitsMax = inLimitsMax;
  138. mHasLimits = mLimitsMin != -FLT_MAX || mLimitsMax != FLT_MAX;
  139. }
  140. void SliderConstraint::CalculateR1R2U(Mat44Arg inRotation1, Mat44Arg inRotation2)
  141. {
  142. // Calculate points relative to body
  143. mR1 = inRotation1 * mLocalSpacePosition1;
  144. mR2 = inRotation2 * mLocalSpacePosition2;
  145. // Calculate X2 + R2 - X1 - R1
  146. mU = mBody2->GetCenterOfMassPosition() + mR2 - mBody1->GetCenterOfMassPosition() - mR1;
  147. }
  148. void SliderConstraint::CalculatePositionConstraintProperties(Mat44Arg inRotation1, Mat44Arg inRotation2)
  149. {
  150. // Calculate world space normals
  151. mN1 = inRotation1 * mLocalSpaceNormal1;
  152. mN2 = inRotation1 * mLocalSpaceNormal2;
  153. mPositionConstraintPart.CalculateConstraintProperties(*mBody1, inRotation1, mR1 + mU, *mBody2, inRotation2, mR2, mN1, mN2);
  154. }
  155. void SliderConstraint::CalculateSlidingAxisAndPosition(Mat44Arg inRotation1)
  156. {
  157. if (mHasLimits || mMotorState != EMotorState::Off || mMaxFrictionForce > 0.0f)
  158. {
  159. // Calculate world space slider axis
  160. mWorldSpaceSliderAxis = inRotation1 * mLocalSpaceSliderAxis1;
  161. // Calculate slide distance along axis
  162. mD = mU.Dot(mWorldSpaceSliderAxis);
  163. }
  164. }
  165. void SliderConstraint::CalculatePositionLimitsConstraintProperties(float inDeltaTime)
  166. {
  167. // Check if distance is within limits
  168. bool below_min = mD <= mLimitsMin;
  169. if (mHasLimits && (below_min || mD >= mLimitsMax))
  170. mPositionLimitsConstraintPart.CalculateConstraintProperties(inDeltaTime, *mBody1, mR1 + mU, *mBody2, mR2, mWorldSpaceSliderAxis, 0.0f, mD - (below_min? mLimitsMin : mLimitsMax), mFrequency, mDamping);
  171. else
  172. mPositionLimitsConstraintPart.Deactivate();
  173. }
  174. void SliderConstraint::CalculateMotorConstraintProperties(float inDeltaTime)
  175. {
  176. switch (mMotorState)
  177. {
  178. case EMotorState::Off:
  179. if (mMaxFrictionForce > 0.0f)
  180. mMotorConstraintPart.CalculateConstraintProperties(inDeltaTime, *mBody1, mR1 + mU, *mBody2, mR2, mWorldSpaceSliderAxis);
  181. else
  182. mMotorConstraintPart.Deactivate();
  183. break;
  184. case EMotorState::Velocity:
  185. mMotorConstraintPart.CalculateConstraintProperties(inDeltaTime, *mBody1, mR1 + mU, *mBody2, mR2, mWorldSpaceSliderAxis, -mTargetVelocity);
  186. break;
  187. case EMotorState::Position:
  188. mMotorConstraintPart.CalculateConstraintProperties(inDeltaTime, *mBody1, mR1 + mU, *mBody2, mR2, mWorldSpaceSliderAxis, 0.0f, mD - mTargetPosition, mMotorSettings.mFrequency, mMotorSettings.mDamping);
  189. break;
  190. }
  191. }
  192. void SliderConstraint::SetupVelocityConstraint(float inDeltaTime)
  193. {
  194. // Calculate constraint properties that are constant while bodies don't move
  195. Mat44 rotation1 = Mat44::sRotation(mBody1->GetRotation());
  196. Mat44 rotation2 = Mat44::sRotation(mBody2->GetRotation());
  197. CalculateR1R2U(rotation1, rotation2);
  198. CalculatePositionConstraintProperties(rotation1, rotation2);
  199. mRotationConstraintPart.CalculateConstraintProperties(*mBody1, rotation1, *mBody2, rotation2);
  200. CalculateSlidingAxisAndPosition(rotation1);
  201. CalculatePositionLimitsConstraintProperties(inDeltaTime);
  202. CalculateMotorConstraintProperties(inDeltaTime);
  203. }
  204. void SliderConstraint::WarmStartVelocityConstraint(float inWarmStartImpulseRatio)
  205. {
  206. // Warm starting: Apply previous frame impulse
  207. mMotorConstraintPart.WarmStart(*mBody1, *mBody2, mWorldSpaceSliderAxis, inWarmStartImpulseRatio);
  208. mPositionConstraintPart.WarmStart(*mBody1, *mBody2, mN1, mN2, inWarmStartImpulseRatio);
  209. mRotationConstraintPart.WarmStart(*mBody1, *mBody2, inWarmStartImpulseRatio);
  210. mPositionLimitsConstraintPart.WarmStart(*mBody1, *mBody2, mWorldSpaceSliderAxis, inWarmStartImpulseRatio);
  211. }
  212. bool SliderConstraint::SolveVelocityConstraint(float inDeltaTime)
  213. {
  214. // Solve motor
  215. bool motor = false;
  216. if (mMotorConstraintPart.IsActive())
  217. {
  218. switch (mMotorState)
  219. {
  220. case EMotorState::Off:
  221. {
  222. float max_lambda = mMaxFrictionForce * inDeltaTime;
  223. motor = mMotorConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, -max_lambda, max_lambda);
  224. break;
  225. }
  226. case EMotorState::Velocity:
  227. case EMotorState::Position:
  228. motor = mMotorConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, inDeltaTime * mMotorSettings.mMinForceLimit, inDeltaTime * mMotorSettings.mMaxForceLimit);
  229. break;
  230. }
  231. }
  232. // Solve position constraint along 2 axis
  233. bool pos = mPositionConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2, mN1, mN2);
  234. // Solve rotation constraint
  235. bool rot = mRotationConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2);
  236. // Solve limits along slider axis
  237. bool limit = false;
  238. if (mPositionLimitsConstraintPart.IsActive())
  239. {
  240. if (mD <= mLimitsMin)
  241. limit = mPositionLimitsConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, 0, FLT_MAX);
  242. else
  243. {
  244. JPH_ASSERT(mD >= mLimitsMax);
  245. limit = mPositionLimitsConstraintPart.SolveVelocityConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, -FLT_MAX, 0);
  246. }
  247. }
  248. return motor || pos || rot || limit;
  249. }
  250. bool SliderConstraint::SolvePositionConstraint(float inDeltaTime, float inBaumgarte)
  251. {
  252. // Motor operates on velocities only, don't call SolvePositionConstraint
  253. // Solve position constraint along 2 axis
  254. Mat44 rotation1 = Mat44::sRotation(mBody1->GetRotation());
  255. Mat44 rotation2 = Mat44::sRotation(mBody2->GetRotation());
  256. CalculateR1R2U(rotation1, rotation2);
  257. CalculatePositionConstraintProperties(rotation1, rotation2);
  258. bool pos = mPositionConstraintPart.SolvePositionConstraint(*mBody1, *mBody2, mU, mN1, mN2, inBaumgarte);
  259. // Solve rotation constraint
  260. mRotationConstraintPart.CalculateConstraintProperties(*mBody1, Mat44::sRotation(mBody1->GetRotation()), *mBody2, Mat44::sRotation(mBody2->GetRotation()));
  261. bool rot = mRotationConstraintPart.SolvePositionConstraint(*mBody1, *mBody2, mInvInitialOrientation, inBaumgarte);
  262. // Solve limits along slider axis
  263. bool limit = false;
  264. if (mHasLimits && mFrequency <= 0.0f)
  265. {
  266. rotation1 = Mat44::sRotation(mBody1->GetRotation());
  267. rotation2 = Mat44::sRotation(mBody2->GetRotation());
  268. CalculateR1R2U(rotation1, rotation2);
  269. CalculateSlidingAxisAndPosition(rotation1);
  270. CalculatePositionLimitsConstraintProperties(inDeltaTime);
  271. if (mPositionLimitsConstraintPart.IsActive())
  272. {
  273. if (mD <= mLimitsMin)
  274. limit = mPositionLimitsConstraintPart.SolvePositionConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, mD - mLimitsMin, inBaumgarte);
  275. else
  276. {
  277. JPH_ASSERT(mD >= mLimitsMax);
  278. limit = mPositionLimitsConstraintPart.SolvePositionConstraint(*mBody1, *mBody2, mWorldSpaceSliderAxis, mD - mLimitsMax, inBaumgarte);
  279. }
  280. }
  281. }
  282. return pos || rot || limit;
  283. }
  284. #ifdef JPH_DEBUG_RENDERER
  285. void SliderConstraint::DrawConstraint(DebugRenderer *inRenderer) const
  286. {
  287. Mat44 transform1 = mBody1->GetCenterOfMassTransform();
  288. Mat44 transform2 = mBody2->GetCenterOfMassTransform();
  289. // Transform the local positions into world space
  290. Vec3 slider_axis = transform1.Multiply3x3(mLocalSpaceSliderAxis1);
  291. Vec3 position1 = transform1 * mLocalSpacePosition1;
  292. Vec3 position2 = transform2 * mLocalSpacePosition2;
  293. // Draw constraint
  294. inRenderer->DrawMarker(position1, Color::sRed, 0.1f);
  295. inRenderer->DrawMarker(position2, Color::sGreen, 0.1f);
  296. inRenderer->DrawLine(position1, position2, Color::sGreen);
  297. // Draw motor
  298. switch (mMotorState)
  299. {
  300. case EMotorState::Position:
  301. inRenderer->DrawMarker(position1 + mTargetPosition * slider_axis, Color::sYellow, 1.0f);
  302. break;
  303. case EMotorState::Velocity:
  304. {
  305. Vec3 cur_vel = (mBody2->GetLinearVelocity() - mBody1->GetLinearVelocity()).Dot(slider_axis) * slider_axis;
  306. inRenderer->DrawLine(position2, position2 + cur_vel, Color::sBlue);
  307. inRenderer->DrawArrow(position2 + cur_vel, position2 + mTargetVelocity * slider_axis, Color::sRed, 0.1f);
  308. break;
  309. }
  310. case EMotorState::Off:
  311. break;
  312. }
  313. }
  314. void SliderConstraint::DrawConstraintLimits(DebugRenderer *inRenderer) const
  315. {
  316. if (mHasLimits)
  317. {
  318. Mat44 transform1 = mBody1->GetCenterOfMassTransform();
  319. Mat44 transform2 = mBody2->GetCenterOfMassTransform();
  320. // Transform the local positions into world space
  321. Vec3 slider_axis = transform1.Multiply3x3(mLocalSpaceSliderAxis1);
  322. Vec3 position1 = transform1 * mLocalSpacePosition1;
  323. Vec3 position2 = transform2 * mLocalSpacePosition2;
  324. // Calculate the limits in world space
  325. Vec3 limits_min = position1 + mLimitsMin * slider_axis;
  326. Vec3 limits_max = position1 + mLimitsMax * slider_axis;
  327. inRenderer->DrawLine(limits_min, position1, Color::sWhite);
  328. inRenderer->DrawLine(position2, limits_max, Color::sWhite);
  329. inRenderer->DrawMarker(limits_min, Color::sWhite, 0.1f);
  330. inRenderer->DrawMarker(limits_max, Color::sWhite, 0.1f);
  331. }
  332. }
  333. #endif // JPH_DEBUG_RENDERER
  334. void SliderConstraint::SaveState(StateRecorder &inStream) const
  335. {
  336. TwoBodyConstraint::SaveState(inStream);
  337. mMotorConstraintPart.SaveState(inStream);
  338. mPositionConstraintPart.SaveState(inStream);
  339. mRotationConstraintPart.SaveState(inStream);
  340. mPositionLimitsConstraintPart.SaveState(inStream);
  341. inStream.Write(mMotorState);
  342. inStream.Write(mTargetVelocity);
  343. inStream.Write(mTargetPosition);
  344. }
  345. void SliderConstraint::RestoreState(StateRecorder &inStream)
  346. {
  347. TwoBodyConstraint::RestoreState(inStream);
  348. mMotorConstraintPart.RestoreState(inStream);
  349. mPositionConstraintPart.RestoreState(inStream);
  350. mRotationConstraintPart.RestoreState(inStream);
  351. mPositionLimitsConstraintPart.RestoreState(inStream);
  352. inStream.Read(mMotorState);
  353. inStream.Read(mTargetVelocity);
  354. inStream.Read(mTargetPosition);
  355. }
  356. Ref<ConstraintSettings> SliderConstraint::GetConstraintSettings() const
  357. {
  358. SliderConstraintSettings *settings = new SliderConstraintSettings;
  359. ToConstraintSettings(*settings);
  360. settings->mSpace = EConstraintSpace::LocalToBodyCOM;
  361. settings->mPoint1 = mLocalSpacePosition1;
  362. settings->mSliderAxis1 = mLocalSpaceSliderAxis1;
  363. settings->mNormalAxis1 = mLocalSpaceNormal1;
  364. settings->mPoint2 = mLocalSpacePosition2;
  365. Mat44 inv_initial_rotation = Mat44::sRotation(mInvInitialOrientation);
  366. settings->mSliderAxis2 = inv_initial_rotation.Multiply3x3(mLocalSpaceSliderAxis1);
  367. settings->mNormalAxis2 = inv_initial_rotation.Multiply3x3(mLocalSpaceNormal1);
  368. settings->mLimitsMin = mLimitsMin;
  369. settings->mLimitsMax = mLimitsMax;
  370. settings->mFrequency = mFrequency;
  371. settings->mDamping = mDamping;
  372. settings->mMaxFrictionForce = mMaxFrictionForce;
  373. settings->mMotorSettings = mMotorSettings;
  374. return settings;
  375. }
  376. Mat44 SliderConstraint::GetConstraintToBody1Matrix() const
  377. {
  378. return Mat44(Vec4(mLocalSpaceSliderAxis1, 0), Vec4(mLocalSpaceNormal1, 0), Vec4(mLocalSpaceNormal2, 0), Vec4(mLocalSpacePosition1, 1));
  379. }
  380. Mat44 SliderConstraint::GetConstraintToBody2Matrix() const
  381. {
  382. Mat44 mat = Mat44::sRotation(mInvInitialOrientation).Multiply3x3(Mat44(Vec4(mLocalSpaceSliderAxis1, 0), Vec4(mLocalSpaceNormal1, 0), Vec4(mLocalSpaceNormal2, 0), Vec4(0, 0, 0, 1)));
  383. mat.SetTranslation(mLocalSpacePosition2);
  384. return mat;
  385. }
  386. JPH_NAMESPACE_END