SimpleTest.cpp 1.6 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/General/SimpleTest.h>
  6. #include <Jolt/Physics/Collision/Shape/BoxShape.h>
  7. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  8. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  9. #include <Jolt/Physics/Body/BodyActivationListener.h>
  10. #include <Layers.h>
  11. JPH_IMPLEMENT_RTTI_VIRTUAL(SimpleTest)
  12. {
  13. JPH_ADD_BASE_CLASS(SimpleTest, Test)
  14. }
  15. SimpleTest::~SimpleTest()
  16. {
  17. // Unregister activation listener
  18. mPhysicsSystem->SetBodyActivationListener(nullptr);
  19. }
  20. void SimpleTest::Initialize()
  21. {
  22. // Register activation listener
  23. mPhysicsSystem->SetBodyActivationListener(&mBodyActivationListener);
  24. // Floor
  25. CreateFloor();
  26. RefConst<Shape> box_shape = new BoxShape(Vec3(0.5f, 1.0f, 2.0f));
  27. // Dynamic body 1
  28. Body &body1 = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  29. mBodyInterface->AddBody(body1.GetID(), EActivation::Activate);
  30. // Dynamic body 2
  31. Body &body2 = *mBodyInterface->CreateBody(BodyCreationSettings(box_shape, RVec3(5, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
  32. mBodyInterface->AddBody(body2.GetID(), EActivation::Activate);
  33. // Dynamic body 3
  34. Body &body3 = *mBodyInterface->CreateBody(BodyCreationSettings(new SphereShape(2.0f), RVec3(10, 10, 0), Quat::sRotation(Vec3::sAxisX(), 0.25f * JPH_PI), EMotionType::Dynamic, Layers::MOVING));
  35. mBodyInterface->AddBody(body3.GetID(), EActivation::Activate);
  36. }