2
0

CylinderShapeTest.cpp 1.9 KB

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