SoftBodyFrictionTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. BodyID id = mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
  29. SetBodyLabel(id, StringFormat("Friction: %.1f", double(sphere.mFriction)));
  30. }
  31. Ref<SoftBodySharedSettings> cube_settings = SoftBodySharedSettings::sCreateCube(5, 0.5f);
  32. for (SoftBodySharedSettings::Vertex &v : cube_settings->mVertices)
  33. v.mVelocity = Float3(0, 0, 10);
  34. SoftBodyCreationSettings cube(cube_settings, RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
  35. for (int i = 0; i <= 10; ++i)
  36. {
  37. cube.mPosition = RVec3(-50.0f + i * 10.0f, 1.0f, -5.0f);
  38. cube.mFriction = 0.1f * i;
  39. BodyID id = mBodyInterface->CreateAndAddSoftBody(cube, EActivation::Activate);
  40. SetBodyLabel(id, StringFormat("Friction: %.1f", double(cube.mFriction)));
  41. }
  42. }