Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/PhysicsSettings.h
9906 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
JPH_NAMESPACE_BEGIN
8
9
/// If objects are closer than this distance, they are considered to be colliding (used for GJK) (unit: meter)
10
constexpr float cDefaultCollisionTolerance = 1.0e-4f;
11
12
/// 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)
13
constexpr float cDefaultPenetrationTolerance = 1.0e-4f; ///< Stop when there's less than 1% change
14
15
/// How much padding to add around objects
16
constexpr float cDefaultConvexRadius = 0.05f;
17
18
/// Used by (Tapered)CapsuleShape to determine when supporting face is an edge rather than a point (unit: meter)
19
static constexpr float cCapsuleProjectionSlop = 0.02f;
20
21
/// Maximum amount of jobs to allow
22
constexpr int cMaxPhysicsJobs = 2048;
23
24
/// Maximum amount of barriers to allow
25
constexpr int cMaxPhysicsBarriers = 8;
26
27
struct PhysicsSettings
28
{
29
JPH_OVERRIDE_NEW_DELETE
30
31
/// Size of body pairs array, corresponds to the maximum amount of potential body pairs that can be in flight at any time.
32
/// Setting this to a low value will use less memory but slow down simulation as threads may run out of narrow phase work.
33
int mMaxInFlightBodyPairs = 16384;
34
35
/// How many PhysicsStepListeners to notify in 1 batch
36
int mStepListenersBatchSize = 8;
37
38
/// How many step listener batches are needed before spawning another job (set to INT_MAX if no parallelism is desired)
39
int mStepListenerBatchesPerJob = 1;
40
41
/// Baumgarte stabilization factor (how much of the position error to 'fix' in 1 update) (unit: dimensionless, 0 = nothing, 1 = 100%)
42
float mBaumgarte = 0.2f;
43
44
/// Radius around objects inside which speculative contact points will be detected. Note that if this is too big
45
/// you will get ghost collisions as speculative contacts are based on the closest points during the collision detection
46
/// step which may not be the actual closest points by the time the two objects hit (unit: meters)
47
float mSpeculativeContactDistance = 0.02f;
48
49
/// How much bodies are allowed to sink into each other (unit: meters)
50
float mPenetrationSlop = 0.02f;
51
52
/// Fraction of its inner radius a body must move per step to enable casting for the LinearCast motion quality
53
float mLinearCastThreshold = 0.75f;
54
55
/// Fraction of its inner radius a body may penetrate another body for the LinearCast motion quality
56
float mLinearCastMaxPenetration = 0.25f;
57
58
/// Max distance to use to determine if two points are on the same plane for determining the contact manifold between two shape faces (unit: meter)
59
float mManifoldTolerance = 1.0e-3f;
60
61
/// Maximum distance to correct in a single iteration when solving position constraints (unit: meters)
62
float mMaxPenetrationDistance = 0.2f;
63
64
/// Maximum relative delta position for body pairs to be able to reuse collision results from last frame (units: meter^2)
65
float mBodyPairCacheMaxDeltaPositionSq = Square(0.001f); ///< 1 mm
66
67
/// Maximum relative delta orientation for body pairs to be able to reuse collision results from last frame, stored as cos(max angle / 2)
68
float mBodyPairCacheCosMaxDeltaRotationDiv2 = 0.99984769515639123915701155881391f; ///< cos(2 degrees / 2)
69
70
/// Maximum angle between normals that allows manifolds between different sub shapes of the same body pair to be combined
71
float mContactNormalCosMaxDeltaRotation = 0.99619469809174553229501040247389f; ///< cos(5 degree)
72
73
/// Maximum allowed distance between old and new contact point to preserve contact forces for warm start (units: meter^2)
74
float mContactPointPreserveLambdaMaxDistSq = Square(0.01f); ///< 1 cm
75
76
/// Number of solver velocity iterations to run
77
/// 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)
78
uint mNumVelocitySteps = 10;
79
80
/// Number of solver position iterations to run
81
uint mNumPositionSteps = 2;
82
83
/// Minimal velocity needed before a collision can be elastic. If the relative velocity between colliding objects
84
/// in the direction of the contact normal is lower than this, the restitution will be zero regardless of the configured
85
/// value. This lets an object settle sooner. Must be a positive number. (unit: m)
86
float mMinVelocityForRestitution = 1.0f;
87
88
/// Time before object is allowed to go to sleep (unit: seconds)
89
float mTimeBeforeSleep = 0.5f;
90
91
/// To detect if an object is sleeping, we use 3 points:
92
/// - The center of mass.
93
/// - The centers of the faces of the bounding box that are furthest away from the center.
94
/// The movement of these points is tracked and if the velocity of all 3 points is lower than this value,
95
/// the object is allowed to go to sleep. Must be a positive number. (unit: m/s)
96
float mPointVelocitySleepThreshold = 0.03f;
97
98
/// By default the simulation is deterministic, it is possible to turn this off by setting this setting to false. This will make the simulation run faster but it will no longer be deterministic.
99
bool mDeterministicSimulation = true;
100
101
///@name These variables are mainly for debugging purposes, they allow turning on/off certain subsystems. You probably want to leave them alone.
102
///@{
103
104
/// Whether or not to use warm starting for constraints (initially applying previous frames impulses)
105
bool mConstraintWarmStart = true;
106
107
/// 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
108
bool mUseBodyPairContactCache = true;
109
110
/// Whether or not to reduce manifolds with similar contact normals into one contact manifold (see description at Body::SetUseManifoldReduction)
111
bool mUseManifoldReduction = true;
112
113
/// If we split up large islands into smaller parallel batches of work (to improve performance)
114
bool mUseLargeIslandSplitter = true;
115
116
/// If objects can go to sleep or not
117
bool mAllowSleeping = true;
118
119
/// When false, we prevent collision against non-active (shared) edges. Mainly for debugging the algorithm.
120
bool mCheckActiveEdges = true;
121
122
///@}
123
};
124
125
JPH_NAMESPACE_END
126
127