CapsuleShapeTest.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/Shapes/CapsuleShapeTest.h>
  6. #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
  7. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(CapsuleShapeTest)
  10. {
  11. JPH_ADD_BASE_CLASS(CapsuleShapeTest, Test)
  12. }
  13. void CapsuleShapeTest::Initialize()
  14. {
  15. // Floor
  16. CreateFloor();
  17. RefConst<Shape> big_capsule = new CapsuleShape(2.5f, 2);
  18. // Capsule on outer sphere
  19. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_capsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  20. // Capsule on cylinder
  21. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_capsule, RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  22. RefConst<Shape> long_capsule = new CapsuleShape(5, 1);
  23. // Tower of capsules
  24. for (int i = 0; i < 10; ++i)
  25. {
  26. for (int j = 0; j < 2; ++j)
  27. {
  28. RVec3 position;
  29. Quat rotation;
  30. if (i & 1)
  31. {
  32. position = RVec3(-4.0f + 8.0f * j, 2.0f + 3.0f * i, -20.0f);
  33. rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI);
  34. }
  35. else
  36. {
  37. position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
  38. rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
  39. }
  40. mBodyInterface->CreateAndAddBody(BodyCreationSettings(long_capsule, position, rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  41. }
  42. }
  43. }