PhysicsSettings.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. JPH_NAMESPACE_BEGIN
  5. /// If objects are closer than this distance, they are considered to be colliding (used for GJK) (unit: meter)
  6. constexpr float cDefaultCollisionTolerance = 1.0e-4f;
  7. /// A factor that determines the accuracy of the penetration depth calculation. If the change of the squared distance is less than tolerance * current_penetration_depth^2 the algorithm will terminate. (unit: dimensionless)
  8. constexpr float cDefaultPenetrationTolerance = 1.0e-4f; ///< Stop when there's less than 1% change
  9. /// How much padding to add around objects
  10. constexpr float cDefaultConvexRadius = 0.05f;
  11. /// Used by (Tapered)CapsuleShape to determine when supporting face is an edge rather than a point (unit: meter)
  12. static constexpr float cCapsuleProjectionSlop = 0.02f;
  13. /// Maximum amount of jobs to allow
  14. constexpr int cMaxPhysicsJobs = 2048;
  15. /// Maximum amount of barriers to allow
  16. constexpr int cMaxPhysicsBarriers = 8;
  17. struct PhysicsSettings
  18. {
  19. JPH_OVERRIDE_NEW_DELETE
  20. /// Size of body pairs array, corresponds to the maximum amount of potential body pairs that can be in flight at any time.
  21. /// Setting this to a low value will use less memory but slow down simulation as threads may run out of narrow phase work.
  22. int mMaxInFlightBodyPairs = 16384;
  23. /// How many PhysicsStepListeners to notify in 1 batch
  24. int mStepListenersBatchSize = 8;
  25. /// How many step listener batches are needed before spawning another job (set to INT_MAX if no parallelism is desired)
  26. int mStepListenerBatchesPerJob = 1;
  27. /// Baumgarte stabilization factor (how much of the position error to 'fix' in 1 update) (unit: dimensionless, 0 = nothing, 1 = 100%)
  28. float mBaumgarte = 0.2f;
  29. /// Radius around objects inside which speculative contact points will be detected. Note that if this is too big
  30. /// you will get ghost collisions as speculative contacts are based on the closest points during the collision detection
  31. /// step which may not be the actual closest points by the time the two objects hit (unit: meters)
  32. float mSpeculativeContactDistance = 0.02f;
  33. /// How much bodies are allowed to sink into eachother (unit: meters)
  34. float mPenetrationSlop = 0.02f;
  35. /// Fraction of its inner radius a body must move per step to enable casting for the LinearCast motion quality
  36. float mLinearCastThreshold = 0.75f;
  37. /// Fraction of its inner radius a body may penetrate another body for the LinearCast motion quality
  38. float mLinearCastMaxPenetration = 0.25f;
  39. /// Max squared distance to use to determine if two points are on the same plane for determining the contact manifold between two shape faces (unit: meter^2)
  40. float mManifoldToleranceSq = 1.0e-6f;
  41. /// Maximum distance to correct in a single iteration when solving position constraints (unit: meters)
  42. float mMaxPenetrationDistance = 0.2f;
  43. /// Maximum relative delta position for body pairs to be able to reuse collision results from last frame (units: meter^2)
  44. float mBodyPairCacheMaxDeltaPositionSq = Square(0.001f); ///< 1 mm
  45. /// Maximum relative delta orientation for body pairs to be able to reuse collision results from last frame, stored as cos(max angle / 2)
  46. float mBodyPairCacheCosMaxDeltaRotationDiv2 = 0.99984769515639123915701155881391f; ///< cos(2 degrees / 2)
  47. /// Maximum angle between normals that allows manifolds between different sub shapes of the same body pair to be combined
  48. float mContactNormalCosMaxDeltaRotation = 0.99619469809174553229501040247389f; ///< cos(5 degree)
  49. /// Maximum allowed distance between old and new contact point to preserve contact forces for warm start (units: meter^2)
  50. float mContactPointPreserveLambdaMaxDistSq = Square(0.01f); ///< 1 cm
  51. /// Number of solver velocity iterations to run
  52. /// Note that this needs to be >= 2 in order for friction to work (friction is applied using the non-penetration impulse from the previous iteration)
  53. int mNumVelocitySteps = 10;
  54. /// Number of solver position iterations to run
  55. int mNumPositionSteps = 2;
  56. /// Minimal velocity needed before a collision can be elastic (unit: m)
  57. float mMinVelocityForRestitution = 1.0f;
  58. /// Time before object is allowed to go to sleep (unit: seconds)
  59. float mTimeBeforeSleep = 0.5f;
  60. /// Velocity of points on bounding box of object below which an object can be considered sleeping (unit: m/s)
  61. float mPointVelocitySleepThreshold = 0.03f;
  62. ///@name These variables are mainly for debugging purposes, they allow turning on/off certain subsystems. You probably want to leave them alone.
  63. ///@{
  64. /// Whether or not to use warm starting for constraints (initially applying previous frames impulses)
  65. bool mConstraintWarmStart = true;
  66. /// Whether or not to use the body pair cache, which removes the need for narrow phase collision detection when orientation between two bodies didn't change
  67. bool mUseBodyPairContactCache = true;
  68. /// Whether or not to reduce manifolds with similar contact normals into one contact manifold
  69. bool mUseManifoldReduction = true;
  70. /// If objects can go to sleep or not
  71. bool mAllowSleeping = true;
  72. /// When false, we prevent collision against non-active (shared) edges. Mainly for debugging the algorithm.
  73. bool mCheckActiveEdges = true;
  74. ///@}
  75. };
  76. JPH_NAMESPACE_END