CylinderShapeTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/Shapes/CylinderShapeTest.h>
  5. #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
  6. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  7. #include <Layers.h>
  8. JPH_IMPLEMENT_RTTI_VIRTUAL(CylinderShapeTest)
  9. {
  10. JPH_ADD_BASE_CLASS(CylinderShapeTest, Test)
  11. }
  12. void CylinderShapeTest::Initialize()
  13. {
  14. // Floor
  15. CreateFloor();
  16. // Cylinder on flat part
  17. RefConst<Shape> big_cylinder = new CylinderShape(2.5f, 2);
  18. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_cylinder, Vec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  19. // Cylinder on round part
  20. mBodyInterface->CreateAndAddBody(BodyCreationSettings(big_cylinder, Vec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  21. // Tower of cylinders
  22. RefConst<Shape> long_cylinder = new CylinderShape(5, 1);
  23. for (int i = 0; i < 10; ++i)
  24. {
  25. for (int j = 0; j < 2; ++j)
  26. {
  27. Vec3 position;
  28. Quat rotation;
  29. if (i & 1)
  30. {
  31. position = Vec3(-4.0f + 8.0f * j, 2.0f + 3.0f * i, -20.0f);
  32. rotation = Quat::sRotation(Vec3::sAxisX(), 0.5f * JPH_PI);
  33. }
  34. else
  35. {
  36. position = Vec3(0, 2.0f + 3.0f * i, -20.0f - 4.0f + 8.0f * j);
  37. rotation = Quat::sRotation(Vec3::sAxisZ(), 0.5f * JPH_PI);
  38. }
  39. mBodyInterface->CreateAndAddBody(BodyCreationSettings(long_cylinder, position, rotation, EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  40. }
  41. }
  42. // Tower of thin cylinders
  43. RefConst<Shape> thin_cylinder = new CylinderShape(0.1f, 5.0f);
  44. for (int i = 0; i < 10; ++i)
  45. mBodyInterface->CreateAndAddBody(BodyCreationSettings(thin_cylinder, Vec3(20.0f, 10.0f - 1.0f * i, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  46. }