SoftBodyRestitutionTest.cpp 1.2 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());
  20. sphere.mObjectLayer = Layers::MOVING;
  21. sphere.mPressure = 2000.0f;
  22. for (int i = 0; i <= 10; ++i)
  23. {
  24. sphere.mPosition = RVec3(-50.0f + i * 10.0f, 10.0f, 0);
  25. sphere.mRestitution = 0.1f * i;
  26. mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
  27. }
  28. SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube());
  29. cube.mObjectLayer = Layers::MOVING;
  30. for (int i = 0; i <= 10; ++i)
  31. {
  32. cube.mPosition = RVec3(-50.0f + i * 10.0f, 10.0f, -5.0f);
  33. cube.mRestitution = 0.1f * i;
  34. mBodyInterface->CreateAndAddSoftBody(cube, EActivation::Activate);
  35. }
  36. }