PyramidScene.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. // Jolt includes
  6. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  7. // Local includes
  8. #include "PerformanceTestScene.h"
  9. #include "Layers.h"
  10. // A scene that creates a pyramid of boxes to create a very large island
  11. class PyramidScene : public PerformanceTestScene
  12. {
  13. public:
  14. virtual const char * GetName() const override
  15. {
  16. return "Pyramid";
  17. }
  18. virtual void StartTest(PhysicsSystem &inPhysicsSystem, EMotionQuality inMotionQuality) override
  19. {
  20. BodyInterface &bi = inPhysicsSystem.GetBodyInterface();
  21. // Floor
  22. bi.CreateAndAddBody(BodyCreationSettings(new BoxShape(Vec3(50.0f, 1.0f, 50.0f), 0.0f), RVec3(Vec3(0.0f, -1.0f, 0.0f)), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  23. const float cBoxSize = 2.0f;
  24. const float cBoxSeparation = 0.5f;
  25. const float cHalfBoxSize = 0.5f * cBoxSize;
  26. const int cPyramidHeight = 15;
  27. RefConst<Shape> box_shape = new BoxShape(Vec3::sReplicate(cHalfBoxSize), 0.0f); // No convex radius to force more collisions
  28. // Pyramid
  29. for (int i = 0; i < cPyramidHeight; ++i)
  30. for (int j = i / 2; j < cPyramidHeight - (i + 1) / 2; ++j)
  31. for (int k = i / 2; k < cPyramidHeight - (i + 1) / 2; ++k)
  32. {
  33. RVec3 position(Real(-cPyramidHeight + cBoxSize * j + (i & 1? cHalfBoxSize : 0.0f)), Real(1.0f + (cBoxSize + cBoxSeparation) * i), Real(-cPyramidHeight + cBoxSize * k + (i & 1? cHalfBoxSize : 0.0f)));
  34. BodyCreationSettings settings(box_shape, position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
  35. settings.mAllowSleeping = false; // No sleeping to force the large island to stay awake
  36. bi.CreateAndAddBody(settings, EActivation::Activate);
  37. }
  38. }
  39. };