SoftBodyLRAConstraintTest.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <Renderer/DebugRendererImp.h>
  10. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyLRAConstraintTest)
  11. {
  12. JPH_ADD_BASE_CLASS(SoftBodyLRAConstraintTest, Test)
  13. }
  14. void SoftBodyLRAConstraintTest::Initialize()
  15. {
  16. CreateFloor();
  17. for (int i = 0; i < 2; ++i)
  18. {
  19. auto inv_mass = [](uint, uint inZ) { return inZ == 0? 0.0f : 1.0f; };
  20. auto perturbation = [](uint, uint) { return Vec3::sZero(); };
  21. SoftBodySharedSettings::VertexAttributes va;
  22. va.mShearCompliance = va.mCompliance = 1.0e-3f; // Soften the edges a bit so that the effect of the LRA constraints is more visible
  23. va.mLRAType = i == 0? SoftBodySharedSettings::ELRAType::None : SoftBodySharedSettings::ELRAType::EuclideanDistance;
  24. Ref<SoftBodySharedSettings> cloth_settings = SoftBodyCreator::CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass, perturbation, SoftBodySharedSettings::EBendType::None, va);
  25. SoftBodyCreationSettings cloth(cloth_settings, RVec3(-10.0f + i * 20.0f, 25.0f, 0), Quat::sIdentity(), Layers::MOVING);
  26. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  27. }
  28. }
  29. void SoftBodyLRAConstraintTest::PrePhysicsUpdate(const PreUpdateParams &inParams)
  30. {
  31. mDebugRenderer->DrawText3D(RVec3(-10, 26, -0.5f * cNumVerticesZ * cVertexSpacing), "Without LRA constraints", Color::sWhite);
  32. mDebugRenderer->DrawText3D(RVec3(10, 26, -0.5f * cNumVerticesZ * cVertexSpacing), "With LRA constraints", Color::sWhite);
  33. }