Debian Codegraph @

modules/godot_physics_3d/joints/godot_slider_joint_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* godot_slider_joint_3d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 /*
34 Adapted to Godot from the Bullet library.
35 */
36
37 #include "../godot_joint_3d.h"
38 #include "godot_jacobian_entry_3d.h"
39
40 /*
41 Bullet Continuous Collision Detection and Physics Library
42 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
43
44 This software is provided 'as-is', without any express or implied warranty.
45 In no event will the authors be held liable for any damages arising from the use of this software.
46 Permission is granted to anyone to use this software for any purpose,
47 including commercial applications, and to alter it and redistribute it freely,
48 subject to the following restrictions:
49
50 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.
51 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
52 3. This notice may not be removed or altered from any source distribution.
53 */
54
55 /*
56 Added by Roman Ponomarev ([email protected])
57 April 04, 2008
58
59 */
60
61 #define SLIDER_CONSTRAINT_DEF_SOFTNESS (real_t(1.0))
62 #define SLIDER_CONSTRAINT_DEF_DAMPING (real_t(1.0))
63 #define SLIDER_CONSTRAINT_DEF_RESTITUTION (real_t(0.7))
64
65 //-----------------------------------------------------------------------------
66
67 class GodotSliderJoint3D : public GodotJoint3D {
68 protected:
69 union {
70 struct {
71 GodotBody3D *A;
72 GodotBody3D *B;
73 };
74
75 GodotBody3D *_arr[2] = { nullptr, nullptr };
76 };
77
78 Transform3D m_frameInA;
79 Transform3D m_frameInB;
80
81 // linear limits
82 real_t m_lowerLinLimit = 1.0;
83 real_t m_upperLinLimit = -1.0;
84 // angular limits
85 real_t m_lowerAngLimit = 0.0;
86 real_t m_upperAngLimit = 0.0;
87 // softness, restitution and damping for different cases
88 // DirLin - moving inside linear limits
89 // LimLin - hitting linear limit
90 // DirAng - moving inside angular limits
91 // LimAng - hitting angular limit
92 // OrthoLin, OrthoAng - against constraint axis
93 real_t m_softnessDirLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
94 real_t m_restitutionDirLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
95 real_t m_dampingDirLin = 0.0;
96 real_t m_softnessDirAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
97 real_t m_restitutionDirAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
98 real_t m_dampingDirAng = 0.0;
99 real_t m_softnessLimLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
100 real_t m_restitutionLimLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
101 real_t m_dampingLimLin = SLIDER_CONSTRAINT_DEF_DAMPING;
102 real_t m_softnessLimAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
103 real_t m_restitutionLimAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
104 real_t m_dampingLimAng = SLIDER_CONSTRAINT_DEF_DAMPING;
105 real_t m_softnessOrthoLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
106 real_t m_restitutionOrthoLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
107 real_t m_dampingOrthoLin = SLIDER_CONSTRAINT_DEF_DAMPING;
108 real_t m_softnessOrthoAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
109 real_t m_restitutionOrthoAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
110 real_t m_dampingOrthoAng = SLIDER_CONSTRAINT_DEF_DAMPING;
111
112 // for interlal use
113 bool m_solveLinLim = false;
114 bool m_solveAngLim = false;
115
116 GodotJacobianEntry3D m_jacLin[3] = {};
117 real_t m_jacLinDiagABInv[3] = {};
118
119 GodotJacobianEntry3D m_jacAng[3] = {};
120
121 real_t m_timeStep = 0.0;
122 Transform3D m_calculatedTransformA;
123 Transform3D m_calculatedTransformB;
124
125 Vector3 m_sliderAxis;
126 Vector3 m_realPivotAInW;
127 Vector3 m_realPivotBInW;
128 Vector3 m_projPivotInW;
129 Vector3 m_delta;
130 Vector3 m_depth;
131 Vector3 m_relPosA;
132 Vector3 m_relPosB;
133
134 real_t m_linPos = 0.0;
135
136 real_t m_angDepth = 0.0;
137 real_t m_kAngle = 0.0;
138
139 bool m_poweredLinMotor = false;
140 real_t m_targetLinMotorVelocity = 0.0;
141 real_t m_maxLinMotorForce = 0.0;
142 real_t m_accumulatedLinMotorImpulse = 0.0;
143
144 bool m_poweredAngMotor = false;
145 real_t m_targetAngMotorVelocity = 0.0;
146 real_t m_maxAngMotorForce = 0.0;
147 real_t m_accumulatedAngMotorImpulse = 0.0;
148
149 public:
150 // constructors
151 GodotSliderJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Transform3D &frameInA, const Transform3D &frameInB);
152 //SliderJointSW();
153 // overrides
154
155 // access
156 const GodotBody3D *getRigidBodyA() const { return A; }
157 const GodotBody3D *getRigidBodyB() const { return B; }
158 const Transform3D &getCalculatedTransformA() const { return m_calculatedTransformA; }
159 const Transform3D &getCalculatedTransformB() const { return m_calculatedTransformB; }
160 const Transform3D &getFrameOffsetA() const { return m_frameInA; }
161 const Transform3D &getFrameOffsetB() const { return m_frameInB; }
162 Transform3D &getFrameOffsetA() { return m_frameInA; }
163 Transform3D &getFrameOffsetB() { return m_frameInB; }
164 real_t getLowerLinLimit() { return m_lowerLinLimit; }
165 void setLowerLinLimit(real_t lowerLimit) { m_lowerLinLimit = lowerLimit; }
166 real_t getUpperLinLimit() { return m_upperLinLimit; }
167 void setUpperLinLimit(real_t upperLimit) { m_upperLinLimit = upperLimit; }
168 real_t getLowerAngLimit() { return m_lowerAngLimit; }
169 void setLowerAngLimit(real_t lowerLimit) { m_lowerAngLimit = lowerLimit; }
170 real_t getUpperAngLimit() { return m_upperAngLimit; }
171 void setUpperAngLimit(real_t upperLimit) { m_upperAngLimit = upperLimit; }
172
173 real_t getSoftnessDirLin() { return m_softnessDirLin; }
174 real_t getRestitutionDirLin() { return m_restitutionDirLin; }
175 real_t getDampingDirLin() { return m_dampingDirLin; }
176 real_t getSoftnessDirAng() { return m_softnessDirAng; }
177 real_t getRestitutionDirAng() { return m_restitutionDirAng; }
178 real_t getDampingDirAng() { return m_dampingDirAng; }
179 real_t getSoftnessLimLin() { return m_softnessLimLin; }
180 real_t getRestitutionLimLin() { return m_restitutionLimLin; }
181 real_t getDampingLimLin() { return m_dampingLimLin; }
182 real_t getSoftnessLimAng() { return m_softnessLimAng; }
183 real_t getRestitutionLimAng() { return m_restitutionLimAng; }
184 real_t getDampingLimAng() { return m_dampingLimAng; }
185 real_t getSoftnessOrthoLin() { return m_softnessOrthoLin; }
186 real_t getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
187 real_t getDampingOrthoLin() { return m_dampingOrthoLin; }
188 real_t getSoftnessOrthoAng() { return m_softnessOrthoAng; }
189 real_t getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
190 real_t getDampingOrthoAng() { return m_dampingOrthoAng; }
191 void setSoftnessDirLin(real_t softnessDirLin) { m_softnessDirLin = softnessDirLin; }
192 void setRestitutionDirLin(real_t restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
193 void setDampingDirLin(real_t dampingDirLin) { m_dampingDirLin = dampingDirLin; }
194 void setSoftnessDirAng(real_t softnessDirAng) { m_softnessDirAng = softnessDirAng; }
195 void setRestitutionDirAng(real_t restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
196 void setDampingDirAng(real_t dampingDirAng) { m_dampingDirAng = dampingDirAng; }
197 void setSoftnessLimLin(real_t softnessLimLin) { m_softnessLimLin = softnessLimLin; }
198 void setRestitutionLimLin(real_t restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
199 void setDampingLimLin(real_t dampingLimLin) { m_dampingLimLin = dampingLimLin; }
200 void setSoftnessLimAng(real_t softnessLimAng) { m_softnessLimAng = softnessLimAng; }
201 void setRestitutionLimAng(real_t restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
202 void setDampingLimAng(real_t dampingLimAng) { m_dampingLimAng = dampingLimAng; }
203 void setSoftnessOrthoLin(real_t softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
204 void setRestitutionOrthoLin(real_t restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
205 void setDampingOrthoLin(real_t dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
206 void setSoftnessOrthoAng(real_t softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
207 void setRestitutionOrthoAng(real_t restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
208 void setDampingOrthoAng(real_t dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
209 void setPoweredLinMotor(bool onOff) { m_poweredLinMotor = onOff; }
210 bool getPoweredLinMotor() { return m_poweredLinMotor; }
211 void setTargetLinMotorVelocity(real_t targetLinMotorVelocity) { m_targetLinMotorVelocity = targetLinMotorVelocity; }
212 real_t getTargetLinMotorVelocity() { return m_targetLinMotorVelocity; }
213 void setMaxLinMotorForce(real_t maxLinMotorForce) { m_maxLinMotorForce = maxLinMotorForce; }
214 real_t getMaxLinMotorForce() { return m_maxLinMotorForce; }
215 void setPoweredAngMotor(bool onOff) { m_poweredAngMotor = onOff; }
216 bool getPoweredAngMotor() { return m_poweredAngMotor; }
217 void setTargetAngMotorVelocity(real_t targetAngMotorVelocity) { m_targetAngMotorVelocity = targetAngMotorVelocity; }
218 real_t getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; }
219 void setMaxAngMotorForce(real_t maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; }
220 real_t getMaxAngMotorForce() { return m_maxAngMotorForce; }
221 real_t getLinearPos() { return m_linPos; }
222
223 // access for ODE solver
224 bool getSolveLinLimit() { return m_solveLinLim; }
225 real_t getLinDepth() { return m_depth[0]; }
226 bool getSolveAngLimit() { return m_solveAngLim; }
227 real_t getAngDepth() { return m_angDepth; }
228 // shared code used by ODE solver
229 void calculateTransforms();
230 void testLinLimits();
231 void testAngLimits();
232 // access for PE Solver
233 Vector3 getAncorInA();
234 Vector3 getAncorInB();
235
236 void set_param(PhysicsServer3D::SliderJointParam p_param, real_t p_value);
237 real_t get_param(PhysicsServer3D::SliderJointParam p_param) const;
238
239 virtual bool setup(real_t p_step) override;
240 virtual void solve(real_t p_step) override;
241
242 virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_SLIDER; }
243 };