TaperedCapsuleShapeTest.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  21. // Tapered capsule on other outer sphere
  22. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule2, RVec3(10, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  23. // Tapered capsule on side
  24. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_taperedcapsule, RVec3(20, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  25. RefConst<ShapeSettings> long_taperedcapsule = new TaperedCapsuleShapeSettings(5, 0.5f, 1.0f);
  26. // Tower of tapered capsules
  27. for (int i = 0; i < 10; ++i)
  28. {
  29. for (int j = 0; j < 2; ++j)
  30. {
  31. RVec3 position;
  32. Quat rotation;
  33. if (i & 1)
  34. {
  35. position = RVec3(-4.0f + 8.0f * j, 2.0f + 3.0f * i, -20.0f);
  36. rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
  37. }
  38. else
  39. {
  40. position = RVec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
  41. rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI + (j & 1) * JPH_PI);
  42. }
  43. mBodyInterface->CreateAndAddBody(BodyCreationSettings(long_taperedcapsule, position, rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  44. }
  45. }
  46. }