SoftBodyRestitutionTest.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/SoftBody/SoftBodyRestitutionTest.h>
  6. #include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
  7. #include <Utils/SoftBodyCreator.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyRestitutionTest)
  10. {
  11. JPH_ADD_BASE_CLASS(SoftBodyRestitutionTest, Test)
  12. }
  13. void SoftBodyRestitutionTest::Initialize()
  14. {
  15. // Floor
  16. Body &floor = CreateFloor();
  17. floor.SetRestitution(0.0f);
  18. // Bodies with increasing restitution
  19. SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
  20. sphere.mPressure = 2000.0f;
  21. for (int i = 0; i <= 10; ++i)
  22. {
  23. sphere.mPosition = RVec3(-50.0f + i * 10.0f, 10.0f, 0);
  24. sphere.mRestitution = 0.1f * i;
  25. BodyID id = mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
  26. SetBodyLabel(id, StringFormat("Restitution: %.1f", double(sphere.mRestitution)));
  27. }
  28. SoftBodyCreationSettings cube(SoftBodySharedSettings::sCreateCube(5, 0.5f), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
  29. for (int i = 0; i <= 10; ++i)
  30. {
  31. cube.mPosition = RVec3(-50.0f + i * 10.0f, 10.0f, -5.0f);
  32. cube.mRestitution = 0.1f * i;
  33. BodyID id = mBodyInterface->CreateAndAddSoftBody(cube, EActivation::Activate);
  34. SetBodyLabel(id, StringFormat("Restitution: %.1f", double(cube.mRestitution)));
  35. }
  36. }