1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  https://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef B3_CONTACT_SOLVER_INFO
17 #define B3_CONTACT_SOLVER_INFO
18 
19 #include "Bullet3Common/b3Scalar.h"
20 
21 enum b3SolverMode
22 {
23 	B3_SOLVER_RANDMIZE_ORDER = 1,
24 	B3_SOLVER_FRICTION_SEPARATE = 2,
25 	B3_SOLVER_USE_WARMSTARTING = 4,
26 	B3_SOLVER_USE_2_FRICTION_DIRECTIONS = 16,
27 	B3_SOLVER_ENABLE_FRICTION_DIRECTION_CACHING = 32,
28 	B3_SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION = 64,
29 	B3_SOLVER_CACHE_FRIENDLY = 128,
30 	B3_SOLVER_SIMD = 256,
31 	B3_SOLVER_INTERLEAVE_CONTACT_AND_FRICTION_CONSTRAINTS = 512,
32 	B3_SOLVER_ALLOW_ZERO_LENGTH_FRICTION_DIRECTIONS = 1024
33 };
34 
35 struct b3ContactSolverInfoData
36 {
37 	b3Scalar m_tau;
38 	b3Scalar m_damping;  //global non-contact constraint damping, can be locally overridden by constraints during 'getInfo2'.
39 	b3Scalar m_friction;
40 	b3Scalar m_timeStep;
41 	b3Scalar m_restitution;
42 	int m_numIterations;
43 	b3Scalar m_maxErrorReduction;
44 	b3Scalar m_sor;
45 	b3Scalar m_erp;        //used as Baumgarte factor
46 	b3Scalar m_erp2;       //used in Split Impulse
47 	b3Scalar m_globalCfm;  //constraint force mixing
48 	int m_splitImpulse;
49 	b3Scalar m_splitImpulsePenetrationThreshold;
50 	b3Scalar m_splitImpulseTurnErp;
51 	b3Scalar m_linearSlop;
52 	b3Scalar m_warmstartingFactor;
53 
54 	int m_solverMode;
55 	int m_restingContactRestitutionThreshold;
56 	int m_minimumSolverBatchSize;
57 	b3Scalar m_maxGyroscopicForce;
58 	b3Scalar m_singleAxisRollingFrictionThreshold;
59 };
60 
61 struct b3ContactSolverInfo : public b3ContactSolverInfoData
62 {
b3ContactSolverInfob3ContactSolverInfo63 	inline b3ContactSolverInfo()
64 	{
65 		m_tau = b3Scalar(0.6);
66 		m_damping = b3Scalar(1.0);
67 		m_friction = b3Scalar(0.3);
68 		m_timeStep = b3Scalar(1.f / 60.f);
69 		m_restitution = b3Scalar(0.);
70 		m_maxErrorReduction = b3Scalar(20.);
71 		m_numIterations = 10;
72 		m_erp = b3Scalar(0.2);
73 		m_erp2 = b3Scalar(0.8);
74 		m_globalCfm = b3Scalar(0.);
75 		m_sor = b3Scalar(1.);
76 		m_splitImpulse = true;
77 		m_splitImpulsePenetrationThreshold = -.04f;
78 		m_splitImpulseTurnErp = 0.1f;
79 		m_linearSlop = b3Scalar(0.0);
80 		m_warmstartingFactor = b3Scalar(0.85);
81 		//m_solverMode =  B3_SOLVER_USE_WARMSTARTING |  B3_SOLVER_SIMD | B3_SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION|B3_SOLVER_USE_2_FRICTION_DIRECTIONS|B3_SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;// | B3_SOLVER_RANDMIZE_ORDER;
82 		m_solverMode = B3_SOLVER_USE_WARMSTARTING | B3_SOLVER_SIMD;  // | B3_SOLVER_RANDMIZE_ORDER;
83 		m_restingContactRestitutionThreshold = 2;                    //unused as of 2.81
84 		m_minimumSolverBatchSize = 128;                              //try to combine islands until the amount of constraints reaches this limit
85 		m_maxGyroscopicForce = 100.f;                                ///only used to clamp forces for bodies that have their B3_ENABLE_GYROPSCOPIC_FORCE flag set (using b3RigidBody::setFlag)
86 		m_singleAxisRollingFrictionThreshold = 1e30f;                ///if the velocity is above this threshold, it will use a single constraint row (axis), otherwise 3 rows.
87 	}
88 };
89 
90 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
91 struct b3ContactSolverInfoDoubleData
92 {
93 	double m_tau;
94 	double m_damping;  //global non-contact constraint damping, can be locally overridden by constraints during 'getInfo2'.
95 	double m_friction;
96 	double m_timeStep;
97 	double m_restitution;
98 	double m_maxErrorReduction;
99 	double m_sor;
100 	double m_erp;        //used as Baumgarte factor
101 	double m_erp2;       //used in Split Impulse
102 	double m_globalCfm;  //constraint force mixing
103 	double m_splitImpulsePenetrationThreshold;
104 	double m_splitImpulseTurnErp;
105 	double m_linearSlop;
106 	double m_warmstartingFactor;
107 	double m_maxGyroscopicForce;
108 	double m_singleAxisRollingFrictionThreshold;
109 
110 	int m_numIterations;
111 	int m_solverMode;
112 	int m_restingContactRestitutionThreshold;
113 	int m_minimumSolverBatchSize;
114 	int m_splitImpulse;
115 	char m_padding[4];
116 };
117 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
118 struct b3ContactSolverInfoFloatData
119 {
120 	float m_tau;
121 	float m_damping;  //global non-contact constraint damping, can be locally overridden by constraints during 'getInfo2'.
122 	float m_friction;
123 	float m_timeStep;
124 
125 	float m_restitution;
126 	float m_maxErrorReduction;
127 	float m_sor;
128 	float m_erp;  //used as Baumgarte factor
129 
130 	float m_erp2;       //used in Split Impulse
131 	float m_globalCfm;  //constraint force mixing
132 	float m_splitImpulsePenetrationThreshold;
133 	float m_splitImpulseTurnErp;
134 
135 	float m_linearSlop;
136 	float m_warmstartingFactor;
137 	float m_maxGyroscopicForce;
138 	float m_singleAxisRollingFrictionThreshold;
139 
140 	int m_numIterations;
141 	int m_solverMode;
142 	int m_restingContactRestitutionThreshold;
143 	int m_minimumSolverBatchSize;
144 
145 	int m_splitImpulse;
146 	char m_padding[4];
147 };
148 
149 #endif  //B3_CONTACT_SOLVER_INFO
150