TaperedCapsuleShapeTest.cpp 2.2 KB

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