SoftBodyFrictionTest.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/SoftBodyFrictionTest.h>
  6. #include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
  7. #include <Utils/SoftBodyCreator.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyFrictionTest)
  10. {
  11. JPH_ADD_BASE_CLASS(SoftBodyFrictionTest, Test)
  12. }
  13. void SoftBodyFrictionTest::Initialize()
  14. {
  15. // Floor
  16. Body &floor = CreateFloor();
  17. floor.SetFriction(1.0f);
  18. // Bodies with increasing friction
  19. Ref<SoftBodySharedSettings> sphere_settings = SoftBodyCreator::CreateSphere();
  20. for (SoftBodySharedSettings::Vertex &v : sphere_settings->mVertices)
  21. v.mVelocity = Float3(0, 0, 10);
  22. SoftBodyCreationSettings sphere(sphere_settings, RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
  23. sphere.mPressure = 2000.0f;
  24. for (int i = 0; i <= 10; ++i)
  25. {
  26. sphere.mPosition = RVec3(-50.0f + i * 10.0f, 1.0f, 0);
  27. sphere.mFriction = 0.1f * i;
  28. mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
  29. }
  30. Ref<SoftBodySharedSettings> cube_settings = SoftBodyCreator::CreateCube();
  31. for (SoftBodySharedSettings::Vertex &v : cube_settings->mVertices)
  32. v.mVelocity = Float3(0, 0, 10);
  33. SoftBodyCreationSettings cube(cube_settings, RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
  34. for (int i = 0; i <= 10; ++i)
  35. {
  36. cube.mPosition = RVec3(-50.0f + i * 10.0f, 1.0f, -5.0f);
  37. cube.mFriction = 0.1f * i;
  38. mBodyInterface->CreateAndAddSoftBody(cube, EActivation::Activate);
  39. }
  40. }