SoftBodyVsFastMovingTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/SoftBodyVsFastMovingTest.h>
  6. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  7. #include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>
  8. #include <Jolt/Physics/Collision/Shape/SphereShape.h>
  9. #include <Utils/SoftBodyCreator.h>
  10. #include <Layers.h>
  11. JPH_IMPLEMENT_RTTI_VIRTUAL(SoftBodyVsFastMovingTest)
  12. {
  13. JPH_ADD_BASE_CLASS(SoftBodyVsFastMovingTest, Test)
  14. }
  15. void SoftBodyVsFastMovingTest::Initialize()
  16. {
  17. // Floor
  18. CreateFloor();
  19. // Create sphere moving towards the cloth
  20. BodyCreationSettings bcs(new SphereShape(1.0f), RVec3(-2, 20, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING);
  21. bcs.mMotionQuality = EMotionQuality::LinearCast;
  22. bcs.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia;
  23. bcs.mMassPropertiesOverride.mMass = 25.0f;
  24. bcs.mLinearVelocity = Vec3(0, -250, 0);
  25. mBodyInterface->CreateAndAddBody(bcs, EActivation::Activate);
  26. // Create cloth that's fixated at the corners
  27. SoftBodyCreationSettings cloth(SoftBodyCreator::CreateClothWithFixatedCorners(), RVec3(0, 15, 0), Quat::sRotation(Vec3::sAxisX(), 0.1f * JPH_PI) * Quat::sRotation(Vec3::sAxisY(), 0.25f * JPH_PI), Layers::MOVING);
  28. cloth.mUpdatePosition = false; // Don't update the position of the cloth as it is fixed to the world
  29. cloth.mMakeRotationIdentity = false; // Test explicitly checks if soft bodies with a rotation collide with shapes properly
  30. mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
  31. // Create another body with a higher ID than the cloth
  32. bcs.mPosition = RVec3(2, 20, 0);
  33. mBodyInterface->CreateAndAddBody(bcs, EActivation::Activate);
  34. }