2
0

TaperedCapsuleShapeTest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/TaperedCapsuleShapeTest.h>
  6. #include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
  7. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(TaperedCapsuleShapeTest)
  10. {
  11. JPH_ADD_BASE_CLASS(TaperedCapsuleShapeTest, Test)
  12. }
  13. void TaperedCapsuleShapeTest::Initialize()
  14. {
  15. // Floor
  16. CreateFloor();
  17. RefConst<ShapeSettings> big_taperedcapsule = new TaperedCapsuleShapeSettings(2.0f, 1.0f, 3.0f);
  18. RefConst<ShapeSettings> big_taperedcapsule2 = new TaperedCapsuleShapeSettings(2.0f, 3.0f, 1.0f);
  19. // Tapered capsule on outer sphere
  20. Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  21. mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
  22. // Tapered capsule on other outer sphere
  23. Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule2, RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  24. mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
  25. // Tapered capsule on side
  26. Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(big_taperedcapsule, RVec3(20, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
  27. mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
  28. RefConst<ShapeSettings> long_taperedcapsule = new TaperedCapsuleShapeSettings(5, 0.5f, 1.0f);
  29. // Tower of tapered capsules
  30. for (int i = 0; i < 10; ++i)
  31. {
  32. for (int j = 0; j < 2; ++j)
  33. {
  34. RVec3 position;
  35. Quat rotation;
  36. if (i & 1)
  37. {
  38. position = RVec3(-4.0f + 8.0f * j, 2.0f + 3.0f * i, -20.0f);
  39. rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
  40. }
  41. else
  42. {
  43. position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
  44. rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
  45. }
  46. Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(long_taperedcapsule, position, rotation, EMotionType::Dynamic, Layers::MOVING));
  47. mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
  48. }
  49. }
  50. }