ScaledOffsetCenterOfMassShapeTest.cpp 2.1 KB

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