GyroscopicForceTest.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/General/GyroscopicForceTest.h>
  6. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  7. #include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
  8. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  9. #include <Layers.h>
  10. JPH_IMPLEMENT_RTTI_VIRTUAL(GyroscopicForceTest)
  11. {
  12. JPH_ADD_BASE_CLASS(GyroscopicForceTest, Test)
  13. }
  14. void GyroscopicForceTest::Initialize()
  15. {
  16. // Floor
  17. CreateFloor();
  18. StaticCompoundShapeSettings compound;
  19. compound.AddShape(Vec3::sZero(), Quat::sIdentity(), new BoxShape(Vec3(0.5f, 5.0f, 0.5f)));
  20. compound.AddShape(Vec3(1.5f, 0, 0), Quat::sIdentity(), new BoxShape(Vec3(1.0f, 0.5f, 0.5f)));
  21. compound.SetEmbedded();
  22. // One body without gyroscopic force
  23. BodyCreationSettings bcs(&compound, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
  24. bcs.mLinearDamping = 0.0f;
  25. bcs.mAngularDamping = 0.0f;
  26. bcs.mAngularVelocity = Vec3(10, 1, 0);
  27. bcs.mGravityFactor = 0.0f;
  28. mBodyInterface->CreateAndAddBody(bcs, EActivation::Activate);
  29. // One body with gyroscopic force
  30. bcs.mPosition += RVec3(10, 0, 0);
  31. bcs.mApplyGyroscopicForce = true;
  32. mBodyInterface->CreateAndAddBody(bcs, EActivation::Activate);
  33. }