CapsuleShapeTest.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(big_capsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  20. mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
  21. // Capsule on cylinder
  22. Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(big_capsule, RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
  23. mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
  24. RefConst<Shape> long_capsule = new CapsuleShape(5, 1);
  25. // Tower of capsules
  26. for (int i = 0; i < 10; ++i)
  27. {
  28. for (int j = 0; j < 2; ++j)
  29. {
  30. RVec3 position;
  31. Quat rotation;
  32. if (i & 1)
  33. {
  34. position = RVec3(-4.0f + 8.0f * j, 2.0f + 3.0f * i, -20.0f);
  35. rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI);
  36. }
  37. else
  38. {
  39. position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
  40. rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
  41. }
  42. Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(long_capsule, position, rotation, EMotionType::Dynamic, Layers::MOVING));
  43. mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
  44. }
  45. }
  46. }