TwoDFunnelTest.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2022 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/General/TwoDFunnelTest.h>
  6. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  7. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  8. #include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
  9. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  10. #include <Layers.h>
  11. JPH_IMPLEMENT_RTTI_VIRTUAL(TwoDFunnelTest)
  12. {
  13. JPH_ADD_BASE_CLASS(TwoDFunnelTest, Test)
  14. }
  15. void TwoDFunnelTest::Initialize()
  16. {
  17. // Floor
  18. CreateFloor();
  19. RefConst<Shape> wall = new BoxShape(Vec3(0.1f, 10, 1));
  20. // 2D funnel
  21. mBodyInterface->CreateAndAddBody(BodyCreationSettings(wall, RVec3(-12, 8, -5), Quat::sRotation(Vec3::sAxisZ(), 0.2f * JPH_PI), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  22. mBodyInterface->CreateAndAddBody(BodyCreationSettings(wall, RVec3(12, 8, -5), Quat::sRotation(Vec3::sAxisZ(), -0.2f * JPH_PI), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  23. // Shapes falling in 2D funnel
  24. Ref<Shape> shapes[] = {
  25. new SphereShape(0.5f),
  26. new BoxShape(Vec3::sReplicate(0.5f)),
  27. new CapsuleShape(0.2f, 0.3f)
  28. };
  29. BodyCreationSettings bcs(shapes[0], RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
  30. bcs.mAllowedDOFs = EAllowedDOFs::Plane2D;
  31. for (int x = 0; x < 20; ++x)
  32. for (int y = 0; y < 10; ++y)
  33. {
  34. bcs.SetShape(shapes[(x * y) % size(shapes)]);
  35. bcs.mPosition = RVec3(-10.0_r + x, 10.0_r + y, -5.0_r);
  36. mBodyInterface->CreateAndAddBody(bcs, EActivation::Activate);
  37. }
  38. }