SliderConstraintTests.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include "UnitTestFramework.h"
  4. #include "PhysicsTestContext.h"
  5. #include <Jolt/Physics/Constraints/SliderConstraint.h>
  6. #include <Jolt/Physics/Collision/GroupFilterTable.h>
  7. #include "Layers.h"
  8. TEST_SUITE("SliderConstraintTests")
  9. {
  10. // Test a box attached to a slider constraint, test that the body doesn't move beyond the min limit
  11. TEST_CASE("TestSliderConstraintLimitMin")
  12. {
  13. const Vec3 cInitialPos(3.0f, 0, 0);
  14. const float cLimitMin = -7.0f;
  15. // Create group filter
  16. Ref<GroupFilterTable> group_filter = new GroupFilterTable;
  17. // Create two boxes
  18. PhysicsTestContext c;
  19. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1));
  20. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  21. // Give body 2 velocity towards min limit (and ensure that it arrives well before 1 second)
  22. body2.SetLinearVelocity(-Vec3(10.0f, 0, 0));
  23. // Bodies will go through each other, make sure they don't collide
  24. body1.SetCollisionGroup(CollisionGroup(group_filter, 0, 0));
  25. body2.SetCollisionGroup(CollisionGroup(group_filter, 0, 0));
  26. // Create slider constraint
  27. SliderConstraintSettings s;
  28. s.mAutoDetectPoint = true;
  29. s.SetSliderAxis(Vec3::sAxisX());
  30. s.mLimitsMin = cLimitMin;
  31. s.mLimitsMax = 0.0f;
  32. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  33. // Simulate
  34. c.Simulate(1.0f);
  35. // Test resulting velocity
  36. CHECK_APPROX_EQUAL(Vec3::sZero(), body2.GetLinearVelocity(), 1.0e-4f);
  37. // Test resulting position
  38. CHECK_APPROX_EQUAL(cInitialPos + cLimitMin * s.mSliderAxis1, body2.GetPosition(), 1.0e-4f);
  39. }
  40. // Test a box attached to a slider constraint, test that the body doesn't move beyond the max limit
  41. TEST_CASE("TestSliderConstraintLimitMax")
  42. {
  43. const Vec3 cInitialPos(3.0f, 0, 0);
  44. const float cLimitMax = 7.0f;
  45. // Create two boxes
  46. PhysicsTestContext c;
  47. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1));
  48. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  49. // Give body 2 velocity towards max limit (and ensure that it arrives well before 1 second)
  50. body2.SetLinearVelocity(Vec3(10.0f, 0, 0));
  51. // Create slider constraint
  52. SliderConstraintSettings s;
  53. s.mAutoDetectPoint = true;
  54. s.SetSliderAxis(Vec3::sAxisX());
  55. s.mLimitsMin = 0.0f;
  56. s.mLimitsMax = cLimitMax;
  57. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  58. // Simulate
  59. c.Simulate(1.0f);
  60. // Test resulting velocity
  61. CHECK_APPROX_EQUAL(Vec3::sZero(), body2.GetLinearVelocity(), 1.0e-4f);
  62. // Test resulting position
  63. CHECK_APPROX_EQUAL(cInitialPos + cLimitMax * s.mSliderAxis1, body2.GetPosition(), 1.0e-4f);
  64. }
  65. // Test a box attached to a slider constraint, test that a motor can drive it to a specific velocity
  66. TEST_CASE("TestSliderConstraintDriveVelocityStaticVsDynamic")
  67. {
  68. const Vec3 cInitialPos(3.0f, 0, 0);
  69. const float cMotorAcceleration = 2.0f;
  70. // Create two boxes
  71. PhysicsTestContext c;
  72. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1));
  73. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  74. // Create slider constraint
  75. SliderConstraintSettings s;
  76. s.mAutoDetectPoint = true;
  77. s.SetSliderAxis(Vec3::sAxisX());
  78. constexpr float mass = Cubed(2.0f) * 1000.0f; // Density * Volume
  79. s.mMotorSettings = MotorSettings(0.0f, 0.0f, mass * cMotorAcceleration, 0.0f);
  80. SliderConstraint &constraint = c.CreateConstraint<SliderConstraint>(body1, body2, s);
  81. constraint.SetMotorState(EMotorState::Velocity);
  82. constraint.SetTargetVelocity(1.5f * cMotorAcceleration);
  83. // Simulate
  84. c.Simulate(1.0f);
  85. // Test resulting velocity
  86. Vec3 expected_vel = cMotorAcceleration * s.mSliderAxis1;
  87. CHECK_APPROX_EQUAL(expected_vel, body2.GetLinearVelocity(), 1.0e-4f);
  88. // Simulate (after 0.5 seconds it should reach the target velocity)
  89. c.Simulate(1.0f);
  90. // Test resulting velocity
  91. expected_vel = 1.5f * cMotorAcceleration * s.mSliderAxis1;
  92. CHECK_APPROX_EQUAL(expected_vel, body2.GetLinearVelocity(), 1.0e-4f);
  93. // Test resulting position (1.5s of acceleration + 0.5s of constant speed)
  94. Vec3 expected_pos = c.PredictPosition(cInitialPos, Vec3::sZero(), cMotorAcceleration * s.mSliderAxis1, 1.5f) + 0.5f * expected_vel;
  95. CHECK_APPROX_EQUAL(expected_pos, body2.GetPosition(), 1.0e-4f);
  96. }
  97. // Test 2 dynamic boxes attached to a slider constraint, test that a motor can drive it to a specific velocity
  98. TEST_CASE("TestSliderConstraintDriveVelocityDynamicVsDynamic")
  99. {
  100. const Vec3 cInitialPos(3.0f, 0, 0);
  101. const float cMotorAcceleration = 2.0f;
  102. // Create two boxes
  103. PhysicsTestContext c;
  104. c.ZeroGravity();
  105. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  106. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  107. // Create slider constraint
  108. SliderConstraintSettings s;
  109. s.mAutoDetectPoint = true;
  110. s.SetSliderAxis(Vec3::sAxisX());
  111. constexpr float mass = Cubed(2.0f) * 1000.0f; // Density * Volume
  112. s.mMotorSettings = MotorSettings(0.0f, 0.0f, mass * cMotorAcceleration, 0.0f);
  113. SliderConstraint &constraint = c.CreateConstraint<SliderConstraint>(body1, body2, s);
  114. constraint.SetMotorState(EMotorState::Velocity);
  115. constraint.SetTargetVelocity(3.0f * cMotorAcceleration);
  116. // Simulate
  117. c.Simulate(1.0f);
  118. // Test resulting velocity (both boxes move in opposite directions with the same force, so the resulting velocity difference is 2x as big as the previous test)
  119. Vec3 expected_vel = cMotorAcceleration * s.mSliderAxis1;
  120. CHECK_APPROX_EQUAL(-expected_vel, body1.GetLinearVelocity(), 1.0e-4f);
  121. CHECK_APPROX_EQUAL(expected_vel, body2.GetLinearVelocity(), 1.0e-4f);
  122. // Simulate (after 0.5 seconds it should reach the target velocity)
  123. c.Simulate(1.0f);
  124. // Test resulting velocity
  125. expected_vel = 1.5f * cMotorAcceleration * s.mSliderAxis1;
  126. CHECK_APPROX_EQUAL(-expected_vel, body1.GetLinearVelocity(), 1.0e-4f);
  127. CHECK_APPROX_EQUAL(expected_vel, body2.GetLinearVelocity(), 1.0e-4f);
  128. // Test resulting position (1.5s of acceleration + 0.5s of constant speed)
  129. Vec3 expected_pos1 = c.PredictPosition(Vec3::sZero(), Vec3::sZero(), -cMotorAcceleration * s.mSliderAxis1, 1.5f) - 0.5f * expected_vel;
  130. Vec3 expected_pos2 = c.PredictPosition(cInitialPos, Vec3::sZero(), cMotorAcceleration * s.mSliderAxis1, 1.5f) + 0.5f * expected_vel;
  131. CHECK_APPROX_EQUAL(expected_pos1, body1.GetPosition(), 1.0e-4f);
  132. CHECK_APPROX_EQUAL(expected_pos2, body2.GetPosition(), 1.0e-4f);
  133. }
  134. // Test a box attached to a slider constraint, test that a motor can drive it to a specific position
  135. TEST_CASE("TestSliderConstraintDrivePosition")
  136. {
  137. const Vec3 cInitialPos(3.0f, 0, 0);
  138. const Vec3 cMotorPos(10.0f, 0, 0);
  139. // Create two boxes
  140. PhysicsTestContext c;
  141. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1));
  142. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  143. // Create slider constraint
  144. SliderConstraintSettings s;
  145. s.mAutoDetectPoint = true;
  146. s.SetSliderAxis(Vec3::sAxisX());
  147. SliderConstraint &constraint = c.CreateConstraint<SliderConstraint>(body1, body2, s);
  148. constraint.SetMotorState(EMotorState::Position);
  149. constraint.SetTargetPosition((cMotorPos - cInitialPos).Dot(s.mSliderAxis1));
  150. // Simulate
  151. c.Simulate(2.0f);
  152. // Test resulting velocity
  153. CHECK_APPROX_EQUAL(Vec3::sZero(), body2.GetLinearVelocity(), 1.0e-4f);
  154. // Test resulting position
  155. CHECK_APPROX_EQUAL(cMotorPos, body2.GetPosition(), 1.0e-4f);
  156. }
  157. // Test a box attached to a slider constraint, give it initial velocity and test that the friction provides the correct decelleration
  158. TEST_CASE("TestSliderConstraintFriction")
  159. {
  160. const Vec3 cInitialPos(3.0f, 0, 0);
  161. const Vec3 cInitialVelocity(10.0f, 0, 0);
  162. const float cFrictionAcceleration = 2.0f;
  163. const float cSimulationTime = 2.0f;
  164. // Create two boxes
  165. PhysicsTestContext c;
  166. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1));
  167. Body &body2 = c.CreateBox(cInitialPos, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1));
  168. body2.SetLinearVelocity(cInitialVelocity);
  169. // Create slider constraint
  170. SliderConstraintSettings s;
  171. s.mAutoDetectPoint = true;
  172. s.SetSliderAxis(Vec3::sAxisX());
  173. constexpr float mass = Cubed(2.0f) * 1000.0f; // Density * Volume
  174. s.mMaxFrictionForce = mass * cFrictionAcceleration;
  175. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  176. // Simulate while applying friction
  177. c.Simulate(cSimulationTime);
  178. // Test resulting velocity
  179. Vec3 expected_vel = cInitialVelocity - cFrictionAcceleration * cSimulationTime * s.mSliderAxis1;
  180. CHECK_APPROX_EQUAL(expected_vel, body2.GetLinearVelocity(), 1.0e-4f);
  181. // Test resulting position
  182. Vec3 expected_pos = c.PredictPosition(cInitialPos, cInitialVelocity, -cFrictionAcceleration * s.mSliderAxis1, cSimulationTime);
  183. CHECK_APPROX_EQUAL(expected_pos, body2.GetPosition(), 1.0e-4f);
  184. }
  185. // Test if a slider constraint wakes up connected bodies
  186. TEST_CASE("TestSliderStaticVsKinematic")
  187. {
  188. // Create two boxes far away enough so they are not touching
  189. PhysicsTestContext c;
  190. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  191. Body &body2 = c.CreateBox(Vec3(10, 0, 0), Quat::sIdentity(), EMotionType::Kinematic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  192. // Create slider constraint
  193. SliderConstraintSettings s;
  194. s.mAutoDetectPoint = true;
  195. s.SetSliderAxis(Vec3::sAxisX());
  196. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  197. // Verify they're not active
  198. CHECK(!body1.IsActive());
  199. CHECK(!body2.IsActive());
  200. // After a physics step, the bodies should still not be active
  201. c.SimulateSingleStep();
  202. CHECK(!body1.IsActive());
  203. CHECK(!body2.IsActive());
  204. // Activate the kinematic body
  205. c.GetSystem()->GetBodyInterface().ActivateBody(body2.GetID());
  206. CHECK(!body1.IsActive());
  207. CHECK(body2.IsActive());
  208. // The static body should not become active (it can't)
  209. c.SimulateSingleStep();
  210. CHECK(!body1.IsActive());
  211. CHECK(body2.IsActive());
  212. }
  213. // Test if a slider constraint wakes up connected bodies
  214. TEST_CASE("TestSliderStaticVsDynamic")
  215. {
  216. // Create two boxes far away enough so they are not touching
  217. PhysicsTestContext c;
  218. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, Layers::NON_MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  219. Body &body2 = c.CreateBox(Vec3(10, 0, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  220. // Create slider constraint
  221. SliderConstraintSettings s;
  222. s.mAutoDetectPoint = true;
  223. s.SetSliderAxis(Vec3::sAxisX());
  224. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  225. // Verify they're not active
  226. CHECK(!body1.IsActive());
  227. CHECK(!body2.IsActive());
  228. // After a physics step, the bodies should still not be active
  229. c.SimulateSingleStep();
  230. CHECK(!body1.IsActive());
  231. CHECK(!body2.IsActive());
  232. // Activate the dynamic body
  233. c.GetSystem()->GetBodyInterface().ActivateBody(body2.GetID());
  234. CHECK(!body1.IsActive());
  235. CHECK(body2.IsActive());
  236. // The static body should not become active (it can't)
  237. c.SimulateSingleStep();
  238. CHECK(!body1.IsActive());
  239. CHECK(body2.IsActive());
  240. }
  241. // Test if a slider constraint wakes up connected bodies
  242. TEST_CASE("TestSliderKinematicVsDynamic")
  243. {
  244. // Create two boxes far away enough so they are not touching
  245. PhysicsTestContext c;
  246. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Kinematic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  247. Body &body2 = c.CreateBox(Vec3(10, 0, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  248. // Create slider constraint
  249. SliderConstraintSettings s;
  250. s.mAutoDetectPoint = true;
  251. s.SetSliderAxis(Vec3::sAxisX());
  252. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  253. // Verify they're not active
  254. CHECK(!body1.IsActive());
  255. CHECK(!body2.IsActive());
  256. // After a physics step, the bodies should still not be active
  257. c.SimulateSingleStep();
  258. CHECK(!body1.IsActive());
  259. CHECK(!body2.IsActive());
  260. // Activate the keyframed body
  261. c.GetSystem()->GetBodyInterface().ActivateBody(body1.GetID());
  262. CHECK(body1.IsActive());
  263. CHECK(!body2.IsActive());
  264. // After a physics step, both bodies should be active now
  265. c.SimulateSingleStep();
  266. CHECK(body1.IsActive());
  267. CHECK(body2.IsActive());
  268. }
  269. // Test if a slider constraint wakes up connected bodies
  270. TEST_CASE("TestSliderKinematicVsKinematic")
  271. {
  272. // Create two boxes far away enough so they are not touching
  273. PhysicsTestContext c;
  274. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Kinematic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  275. Body &body2 = c.CreateBox(Vec3(10, 0, 0), Quat::sIdentity(), EMotionType::Kinematic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  276. // Create slider constraint
  277. SliderConstraintSettings s;
  278. s.mAutoDetectPoint = true;
  279. s.SetSliderAxis(Vec3::sAxisX());
  280. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  281. // Verify they're not active
  282. CHECK(!body1.IsActive());
  283. CHECK(!body2.IsActive());
  284. // After a physics step, the bodies should still not be active
  285. c.SimulateSingleStep();
  286. CHECK(!body1.IsActive());
  287. CHECK(!body2.IsActive());
  288. // Activate the first keyframed body
  289. c.GetSystem()->GetBodyInterface().ActivateBody(body1.GetID());
  290. CHECK(body1.IsActive());
  291. CHECK(!body2.IsActive());
  292. // After a physics step, the second keyframed body should not be woken up
  293. c.SimulateSingleStep();
  294. CHECK(body1.IsActive());
  295. CHECK(!body2.IsActive());
  296. }
  297. // Test if a slider constraint wakes up connected bodies
  298. TEST_CASE("TestSliderDynamicVsDynamic")
  299. {
  300. // Create two boxes far away enough so they are not touching
  301. PhysicsTestContext c;
  302. Body &body1 = c.CreateBox(Vec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  303. Body &body2 = c.CreateBox(Vec3(10, 0, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::DontActivate);
  304. // Create slider constraint
  305. SliderConstraintSettings s;
  306. s.mAutoDetectPoint = true;
  307. s.SetSliderAxis(Vec3::sAxisX());
  308. c.CreateConstraint<SliderConstraint>(body1, body2, s);
  309. // Verify they're not active
  310. CHECK(!body1.IsActive());
  311. CHECK(!body2.IsActive());
  312. // After a physics step, the bodies should still not be active
  313. c.SimulateSingleStep();
  314. CHECK(!body1.IsActive());
  315. CHECK(!body2.IsActive());
  316. // Activate the first dynamic body
  317. c.GetSystem()->GetBodyInterface().ActivateBody(body1.GetID());
  318. CHECK(body1.IsActive());
  319. CHECK(!body2.IsActive());
  320. // After a physics step, both bodies should be active now
  321. c.SimulateSingleStep();
  322. CHECK(body1.IsActive());
  323. CHECK(body2.IsActive());
  324. }
  325. // Test that when a reference frame is provided, the slider constraint is correctly constructed
  326. TEST_CASE("TestSliderReferenceFrame")
  327. {
  328. // Create two boxes in semi random position/orientation
  329. PhysicsTestContext c;
  330. Body &body1 = c.CreateBox(Vec3(1, 2, 3), Quat::sRotation(Vec3(1, 1, 1).Normalized(), 0.1f * JPH_PI), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::Activate);
  331. Body &body2 = c.CreateBox(Vec3(-3, -2, -1), Quat::sRotation(Vec3(1, 0, 1).Normalized(), 0.2f * JPH_PI), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3(1, 1, 1), EActivation::Activate);
  332. // Disable collision between the boxes
  333. GroupFilterTable *group_filter = new GroupFilterTable(2);
  334. group_filter->DisableCollision(0, 1);
  335. body1.SetCollisionGroup(CollisionGroup(group_filter, 0, 0));
  336. body2.SetCollisionGroup(CollisionGroup(group_filter, 0, 1));
  337. // Get their transforms
  338. Mat44 t1 = body1.GetCenterOfMassTransform();
  339. Mat44 t2 = body2.GetCenterOfMassTransform();
  340. // Create slider constraint so that slider connects the bodies at their center of mass and rotated XY -> YZ
  341. SliderConstraintSettings s;
  342. s.mPoint1 = t1.GetTranslation();
  343. s.mSliderAxis1 = t1.GetColumn3(0);
  344. s.mNormalAxis1 = t1.GetColumn3(1);
  345. s.mPoint2 = t2.GetTranslation();
  346. s.mSliderAxis2 = t2.GetColumn3(1);
  347. s.mNormalAxis2 = t2.GetColumn3(2);
  348. SliderConstraint &constraint = c.CreateConstraint<SliderConstraint>(body1, body2, s);
  349. // Activate the motor to drive to 0
  350. constraint.SetMotorState(EMotorState::Position);
  351. constraint.SetTargetPosition(0);
  352. // Simulate for a second
  353. c.Simulate(1.0f);
  354. // Now the bodies should have aligned so their COM is at the same position and they're rotated XY -> YZ
  355. t1 = body1.GetCenterOfMassTransform();
  356. t2 = body2.GetCenterOfMassTransform();
  357. CHECK_APPROX_EQUAL(t1.GetColumn3(0), t2.GetColumn3(1), 1.0e-4f);
  358. CHECK_APPROX_EQUAL(t1.GetColumn3(1), t2.GetColumn3(2), 1.0e-4f);
  359. CHECK_APPROX_EQUAL(t1.GetColumn3(2), t2.GetColumn3(0), 1.0e-4f);
  360. CHECK_APPROX_EQUAL(t1.GetTranslation(), t2.GetTranslation(), 1.0e-2f);
  361. }
  362. }