1 /********************************************************************************
2 * ReactPhysics3D physics library, http://www.reactphysics3d.com *
3 * Copyright (c) 2010-2020 Daniel Chappuis *
4 *********************************************************************************
5 * *
6 * This software is provided 'as-is', without any express or implied warranty. *
7 * In no event will the authors be held liable for any damages arising from the *
8 * use of this software. *
9 * *
10 * Permission is granted to anyone to use this software for any purpose, *
11 * including commercial applications, and to alter it and redistribute it *
12 * freely, subject to the following restrictions: *
13 * *
14 * 1. The origin of this software must not be misrepresented; you must not claim *
15 * that you wrote the original software. If you use this software in a *
16 * product, an acknowledgment in the product documentation would be *
17 * appreciated but is not required. *
18 * *
19 * 2. Altered source versions must be plainly marked as such, and must not be *
20 * misrepresented as being the original software. *
21 * *
22 * 3. This notice may not be removed or altered from any source distribution. *
23 * *
24 ********************************************************************************/
25
26 #ifndef REACTPHYSICS3D_SOLVE_BALL_SOCKET_JOINT_SYSTEM_H
27 #define REACTPHYSICS3D_SOLVE_BALL_SOCKET_JOINT_SYSTEM_H
28
29 // Libraries
30 #include <reactphysics3d/utils/Profiler.h>
31 #include <reactphysics3d/components/RigidBodyComponents.h>
32 #include <reactphysics3d/components/JointComponents.h>
33 #include <reactphysics3d/components/BallAndSocketJointComponents.h>
34 #include <reactphysics3d/components/TransformComponents.h>
35
36 namespace reactphysics3d {
37
38 // Forward declarations
39 class PhysicsWorld;
40
41 // Class SolveBallAndSocketJointSystem
42 /**
43 * This class is responsible to solve the BallAndSocketJoint constraints
44 */
45 class SolveBallAndSocketJointSystem {
46
47 private :
48
49 // -------------------- Constants -------------------- //
50
51 // Beta value for the bias factor of position correction
52 static const decimal BETA;
53
54 // -------------------- Attributes -------------------- //
55
56 /// Physics world
57 PhysicsWorld& mWorld;
58
59 /// Reference to the rigid body components
60 RigidBodyComponents& mRigidBodyComponents;
61
62 /// Reference to transform components
63 TransformComponents& mTransformComponents;
64
65 /// Reference to the joint components
66 JointComponents& mJointComponents;
67
68 /// Reference to the ball-and-socket joint components
69 BallAndSocketJointComponents& mBallAndSocketJointComponents;
70
71 /// Current time step of the simulation
72 decimal mTimeStep;
73
74 /// True if warm starting of the solver is active
75 bool mIsWarmStartingActive;
76
77 #ifdef IS_RP3D_PROFILING_ENABLED
78
79 /// Pointer to the profiler
80 Profiler* mProfiler;
81 #endif
82
83 public :
84
85 // -------------------- Methods -------------------- //
86
87 /// Constructor
88 SolveBallAndSocketJointSystem(PhysicsWorld& world, RigidBodyComponents& rigidBodyComponents,
89 TransformComponents& transformComponents,
90 JointComponents& jointComponents,
91 BallAndSocketJointComponents& ballAndSocketJointComponents);
92
93 /// Destructor
94 ~SolveBallAndSocketJointSystem() = default;
95
96 /// Initialize before solving the constraint
97 void initBeforeSolve();
98
99 /// Warm start the constraint (apply the previous impulse at the beginning of the step)
100 void warmstart();
101
102 /// Solve the velocity constraint
103 void solveVelocityConstraint();
104
105 /// Solve the position constraint (for position error correction)
106 void solvePositionConstraint();
107
108 /// Set the time step
109 void setTimeStep(decimal timeStep);
110
111 /// Set to true to enable warm starting
112 void setIsWarmStartingActive(bool isWarmStartingActive);
113
114 #ifdef IS_RP3D_PROFILING_ENABLED
115
116 /// Set the profiler
117 void setProfiler(Profiler* profiler);
118
119 #endif
120
121 };
122
123 #ifdef IS_RP3D_PROFILING_ENABLED
124
125 // Set the profiler
setProfiler(Profiler * profiler)126 inline void SolveBallAndSocketJointSystem::setProfiler(Profiler* profiler) {
127 mProfiler = profiler;
128 }
129
130 #endif
131
132 // Set the time step
setTimeStep(decimal timeStep)133 inline void SolveBallAndSocketJointSystem::setTimeStep(decimal timeStep) {
134 assert(timeStep > decimal(0.0));
135 mTimeStep = timeStep;
136 }
137
138 // Set to true to enable warm starting
setIsWarmStartingActive(bool isWarmStartingActive)139 inline void SolveBallAndSocketJointSystem::setIsWarmStartingActive(bool isWarmStartingActive) {
140 mIsWarmStartingActive = isWarmStartingActive;
141 }
142
143
144 }
145
146 #endif
147