ScaledPlaneShapeTest.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/ScaledShapes/ScaledPlaneShapeTest.h>
  6. #include <Jolt/Physics/Collision/Shape/PlaneShape.h>
  7. #include <Jolt/Physics/Collision/Shape/ScaledShape.h>
  8. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  9. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  10. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  11. #include <Layers.h>
  12. JPH_IMPLEMENT_RTTI_VIRTUAL(ScaledPlaneShapeTest)
  13. {
  14. JPH_ADD_BASE_CLASS(ScaledPlaneShapeTest, Test)
  15. }
  16. void ScaledPlaneShapeTest::Initialize()
  17. {
  18. // Floor
  19. CreateFloor();
  20. RefConst<ShapeSettings> plane_shape = new PlaneShapeSettings(Plane(Vec3(0.1f, 1.0f, 0.1f).Normalized(), -0.5f), nullptr, 5.0f);
  21. // Original shape
  22. mBodyInterface->CreateAndAddBody(BodyCreationSettings(plane_shape, RVec3(-60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  23. // Uniformly scaled shape < 1
  24. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(0.5f)), RVec3(-40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  25. // Uniformly scaled shape > 1
  26. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3::sReplicate(1.5f)), RVec3(-20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  27. // Non-uniform scaled shape
  28. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, 1.0f, 1.5f)), RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  29. // Flipped in 2 axis
  30. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, -1.5f)), RVec3(20, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  31. // Inside out
  32. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(-0.5f, 1.0f, 1.5f)), RVec3(40, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  33. // Upside down
  34. mBodyInterface->CreateAndAddBody(BodyCreationSettings(new ScaledShapeSettings(plane_shape, Vec3(0.5f, -1.0f, 1.5f)), RVec3(60, 10, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING), EActivation::DontActivate);
  35. // Create a number of balls above the planes
  36. RefConst<Shape> sphere_shape = new SphereShape(0.2f);
  37. RefConst<Shape> box_shape = new BoxShape(Vec3(0.2f, 0.2f, 0.4f), 0.01f);
  38. for (int i = 0; i < 7; ++i)
  39. for (int j = 0; j < 5; ++j)
  40. mBodyInterface->CreateAndAddBody(BodyCreationSettings((j & 1)? box_shape : sphere_shape, RVec3(-60.0f + 20.0f * i, 15.0f + 0.5f * j, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate);
  41. }