DampingTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/DampingTest.h>
  6. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  7. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(DampingTest)
  10. {
  11. JPH_ADD_BASE_CLASS(DampingTest, Test)
  12. }
  13. void DampingTest::Initialize()
  14. {
  15. // Floor
  16. CreateFloor();
  17. RefConst<Shape> sphere = new SphereShape(2.0f);
  18. // Bodies with increasing damping
  19. for (int i = 0; i <= 10; ++i)
  20. {
  21. Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(sphere, RVec3(-50.0f + i * 10.0f, 2.0f, -80.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  22. body.GetMotionProperties()->SetAngularDamping(0.0f);
  23. body.GetMotionProperties()->SetLinearDamping(0.1f * i);
  24. body.SetLinearVelocity(Vec3(0, 0, 10));
  25. mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
  26. SetBodyLabel(body.GetID(), StringFormat("Linear damping: %.1f", double(body.GetMotionProperties()->GetLinearDamping())));
  27. }
  28. for (int i = 0; i <= 10; ++i)
  29. {
  30. Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(sphere, RVec3(-50.0f + i * 10.0f, 2.0f, -90.0f), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  31. body.GetMotionProperties()->SetLinearDamping(0.0f);
  32. body.GetMotionProperties()->SetAngularDamping(0.1f * i);
  33. body.SetAngularVelocity(Vec3(0, 10, 0));
  34. mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
  35. SetBodyLabel(body.GetID(), StringFormat("Angular damping: %.1f", double(body.GetMotionProperties()->GetAngularDamping())));
  36. }
  37. }