OffsetCenterOfMassShapeTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/Shapes/OffsetCenterOfMassShapeTest.h>
  5. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  6. #include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>
  7. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(OffsetCenterOfMassShapeTest)
  10. {
  11. JPH_ADD_BASE_CLASS(OffsetCenterOfMassShapeTest, Test)
  12. }
  13. void OffsetCenterOfMassShapeTest::Initialize()
  14. {
  15. // Floor
  16. Body &floor = CreateFloor();
  17. floor.SetFriction(1.0f);
  18. Ref<ShapeSettings> sphere = new SphereShapeSettings(1.0f);
  19. Ref<OffsetCenterOfMassShapeSettings> left = new OffsetCenterOfMassShapeSettings(Vec3(-1, 0, 0), sphere);
  20. Ref<OffsetCenterOfMassShapeSettings> right = new OffsetCenterOfMassShapeSettings(Vec3(1, 0, 0), sphere);
  21. // Sphere with center of mass moved to the left side
  22. Body &body_left = *mBodyInterface->CreateBody(BodyCreationSettings(left, Vec3(-5, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  23. body_left.SetFriction(1.0f);
  24. mBodyInterface->AddBody(body_left.GetID(), EActivation::Activate);
  25. // Sphere with center of mass centered
  26. Body &body_center = *mBodyInterface->CreateBody(BodyCreationSettings(sphere, Vec3(0, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  27. body_center.SetFriction(1.0f);
  28. mBodyInterface->AddBody(body_center.GetID(), EActivation::Activate);
  29. // Sphere with center of mass moved to the right side
  30. Body &body_right = *mBodyInterface->CreateBody(BodyCreationSettings(right, Vec3(5, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  31. body_right.SetFriction(1.0f);
  32. mBodyInterface->AddBody(body_right.GetID(), EActivation::Activate);
  33. }