ScaledOffsetCenterOfMassShapeTest.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/ScaledShapes/ScaledOffsetCenterOfMassShapeTest.h>
  5. #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
  6. #include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
  7. #include <Jolt/Physics/Collision/Shape/ScaledShape.h>
  8. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  9. #include <Layers.h>
  10. JPH_IMPLEMENT_RTTI_VIRTUAL(ScaledOffsetCenterOfMassShapeTest)
  11. {
  12. JPH_ADD_BASE_CLASS(ScaledOffsetCenterOfMassShapeTest, Test)
  13. }
  14. void ScaledOffsetCenterOfMassShapeTest::Initialize()
  15. {
  16. // Floor
  17. Body &floor = CreateFloor();
  18. floor.SetFriction(1.0f);
  19. Ref<ShapeSettings> cylinder = new CylinderShapeSettings(1.0f, 0.1f);
  20. Ref<OffsetCenterOfMassShapeSettings> top = new OffsetCenterOfMassShapeSettings(Vec3(0, 1, 0), cylinder);
  21. Ref<OffsetCenterOfMassShapeSettings> bottom = new OffsetCenterOfMassShapeSettings(Vec3(0, -1, 0), cylinder);
  22. // Initial body rotation
  23. Quat rotation = Quat::sRotation(Vec3::sAxisZ(), 0.4f * JPH_PI);
  24. // Cylinder with center of mass moved to the top side
  25. Body &body_top = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(top, Vec3(2.0f, 1.0f, 2.0f)), Vec3(-5, 5, 0), rotation, EMotionType::Dynamic, Layers::MOVING));
  26. body_top.SetFriction(1.0f);
  27. mBodyInterface->AddBody(body_top.GetID(), EActivation::Activate);
  28. // Cylinder with center of mass centered
  29. Body &body_center = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(cylinder, Vec3(2.0f, 1.0f, 2.0f)), Vec3(0, 5, 0), rotation, EMotionType::Dynamic, Layers::MOVING));
  30. body_center.SetFriction(1.0f);
  31. mBodyInterface->AddBody(body_center.GetID(), EActivation::Activate);
  32. // Cylinder with center of mass moved to the bottom side
  33. Body &body_bottom = *mBodyInterface->CreateBody(BodyCreationSettings(new ScaledShapeSettings(bottom, Vec3(2.0f, 1.0f, 2.0f)), Vec3(5, 5, 0), rotation, EMotionType::Dynamic, Layers::MOVING));
  34. body_bottom.SetFriction(1.0f);
  35. mBodyInterface->AddBody(body_bottom.GetID(), EActivation::Activate);
  36. }