CapsuleShapeTest.cpp 1.7 KB

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