SoftBodyLRAConstraintTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include <TestFramework.h>
  5. #include <Tests/SoftBody/SoftBodyLRAConstraintTest.h>
  6. #include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
  7. #include <Utils/SoftBodyCreator.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyLRAConstraintTest)
  10. {
  11. JPH_ADD_BASE_CLASS(SoftBodyLRAConstraintTest, Test)
  12. }
  13. void SoftBodyLRAConstraintTest::Initialize()
  14. {
  15. CreateFloor();
  16. // Cloth without LRA constraints
  17. auto inv_mass = [](uint, uint inZ) { return inZ == 0? 0.0f : 1.0f; };
  18. Ref<SoftBodySharedSettings> cloth_settings = SoftBodyCreator::CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass);
  19. for (SoftBodySharedSettings::Edge &e : cloth_settings->mEdgeConstraints)
  20. e.mCompliance = 1.0e-3f; // Soften the edges a bit so that the effect of the LRA constraints is more visible
  21. SoftBodyCreationSettings cloth(cloth_settings, RVec3(-10.0f, 25.0f, 0), Quat::sIdentity(), Layers::MOVING);
  22. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  23. // Cloth with LRA constraints
  24. Ref<SoftBodySharedSettings> lra_cloth_settings = cloth_settings->Clone();
  25. auto get_vertex = [](uint inX, uint inZ) { return inX + inZ * cNumVerticesX; };
  26. for (int z = 1; z < cNumVerticesZ; ++z)
  27. for (int x = 0; x < cNumVerticesX; ++x)
  28. lra_cloth_settings->mLRAConstraints.push_back(SoftBodySharedSettings::LRA(get_vertex(x, 0), get_vertex(x, z), 0.0f));
  29. lra_cloth_settings->CalculateLRALengths();
  30. SoftBodyCreationSettings lra_cloth(lra_cloth_settings, RVec3(10.0f, 25.0f, 0), Quat::sIdentity(), Layers::MOVING);
  31. mBodyInterface->CreateAndAddSoftBody(lra_cloth, EActivation::Activate);
  32. }