SoftBodyUpdateContext.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Core/NonCopyable.h>
  6. #include <Jolt/Physics/Body/MotionProperties.h>
  7. JPH_NAMESPACE_BEGIN
  8. class Body;
  9. class SoftBodyMotionProperties;
  10. class SoftBodyContactListener;
  11. /// Temporary data used by the update of a soft body
  12. class SoftBodyUpdateContext : public NonCopyable
  13. {
  14. public:
  15. static constexpr uint cVertexCollisionBatch = 64; ///< Number of vertices to process in a batch in DetermineCollisionPlanes
  16. static constexpr uint cVertexConstraintBatch = 256; ///< Number of vertices to group for processing batches of constraints in ApplyEdgeConstraints
  17. // Input
  18. Body * mBody; ///< Body that is being updated
  19. SoftBodyMotionProperties * mMotionProperties; ///< Motion properties of that body
  20. SoftBodyContactListener * mContactListener; ///< Contact listener to fire callbacks to
  21. RMat44 mCenterOfMassTransform; ///< Transform of the body relative to the soft body
  22. Vec3 mGravity; ///< Gravity vector in local space of the soft body
  23. Vec3 mDisplacementDueToGravity; ///< Displacement of the center of mass due to gravity in the current time step
  24. float mDeltaTime; ///< Delta time for the current time step
  25. float mSubStepDeltaTime; ///< Delta time for each sub step
  26. /// Describes progress in the current update
  27. enum class EState
  28. {
  29. DetermineCollisionPlanes, ///< Determine collision planes for vertices in parallel
  30. ApplyConstraints, ///< Apply constraints in parallel
  31. Done ///< Update is finished
  32. };
  33. // State of the update
  34. atomic<EState> mState { EState::DetermineCollisionPlanes };///< Current state of the update
  35. atomic<uint> mNextCollisionVertex { 0 }; ///< Next vertex to process for DetermineCollisionPlanes
  36. atomic<uint> mNumCollisionVerticesProcessed { 0 }; ///< Number of vertices processed by DetermineCollisionPlanes, used to determine if we can start simulating
  37. atomic<uint> mNextIteration { 0 }; ///< Next simulation iteration to process
  38. atomic<uint> mNextConstraintGroup { 0 }; ///< Next constraint group to process
  39. atomic<uint> mNumConstraintGroupsProcessed { 0 }; ///< Number of groups processed, used to determine if we can go to the next iteration
  40. // Output
  41. Vec3 mDeltaPosition; ///< Delta position of the body in the current time step, should be applied after the update
  42. ECanSleep mCanSleep; ///< Can the body sleep? Should be applied after the update
  43. };
  44. JPH_NAMESPACE_END