SoftBodyBendConstraintTest.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/SoftBodyBendConstraintTest.h>
  6. #include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
  7. #include <Utils/SoftBodyCreator.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyBendConstraintTest)
  10. {
  11. JPH_ADD_BASE_CLASS(SoftBodyBendConstraintTest, Test)
  12. }
  13. void SoftBodyBendConstraintTest::Initialize()
  14. {
  15. CreateFloor();
  16. auto inv_mass = [](uint, uint inZ) { return inZ < 2? 0.0f : 1.0f; };
  17. {
  18. // Cloth without bend constraints
  19. Ref<SoftBodySharedSettings> cloth_settings = SoftBodyCreator::CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass, SoftBodySharedSettings::EBendType::None);
  20. SoftBodyCreationSettings cloth(cloth_settings, RVec3(-5.0f, 5.0f, 0), Quat::sIdentity(), Layers::MOVING);
  21. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  22. }
  23. {
  24. // Cloth with edge bend constraints
  25. Ref<SoftBodySharedSettings> cloth_settings = SoftBodyCreator::CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass, SoftBodySharedSettings::EBendType::Distance);
  26. SoftBodyCreationSettings cloth(cloth_settings, RVec3(0.0f, 5.0f, 0), Quat::sIdentity(), Layers::MOVING);
  27. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  28. }
  29. {
  30. // Cloth with isometric bend constraints
  31. Ref<SoftBodySharedSettings> cloth_settings = SoftBodyCreator::CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass, SoftBodySharedSettings::EBendType::Dihedral);
  32. SoftBodyCreationSettings cloth(cloth_settings, RVec3(5.0f, 5.0f, 0), Quat::sIdentity(), Layers::MOVING);
  33. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  34. }
  35. }