Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h @ 12222

Last change on this file since 12222 was 8393, checked in by rgrieder, 14 years ago

Updated Bullet from v2.77 to v2.78.
(I'm not going to make a branch for that since the update from 2.74 to 2.77 hasn't been tested that much either).

You will HAVE to do a complete RECOMPILE! I tested with MSVC and MinGW and they both threw linker errors at me.

  • Property svn:eol-style set to native
File size: 12.8 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16/*
17Added by Roman Ponomarev (rponom@gmail.com)
18April 04, 2008
19
20TODO:
21 - add clamping od accumulated impulse to improve stability
22 - add conversion for ODE constraint solver
23*/
24
25#ifndef BT_SLIDER_CONSTRAINT_H
26#define BT_SLIDER_CONSTRAINT_H
27
28
29
30#include "LinearMath/btVector3.h"
31#include "btJacobianEntry.h"
32#include "btTypedConstraint.h"
33
34
35
36class btRigidBody;
37
38
39
40#define SLIDER_CONSTRAINT_DEF_SOFTNESS          (btScalar(1.0))
41#define SLIDER_CONSTRAINT_DEF_DAMPING           (btScalar(1.0))
42#define SLIDER_CONSTRAINT_DEF_RESTITUTION       (btScalar(0.7))
43#define SLIDER_CONSTRAINT_DEF_CFM                       (btScalar(0.f))
44
45
46enum btSliderFlags
47{
48        BT_SLIDER_FLAGS_CFM_DIRLIN = (1 << 0),
49        BT_SLIDER_FLAGS_ERP_DIRLIN = (1 << 1),
50        BT_SLIDER_FLAGS_CFM_DIRANG = (1 << 2),
51        BT_SLIDER_FLAGS_ERP_DIRANG = (1 << 3),
52        BT_SLIDER_FLAGS_CFM_ORTLIN = (1 << 4),
53        BT_SLIDER_FLAGS_ERP_ORTLIN = (1 << 5),
54        BT_SLIDER_FLAGS_CFM_ORTANG = (1 << 6),
55        BT_SLIDER_FLAGS_ERP_ORTANG = (1 << 7),
56        BT_SLIDER_FLAGS_CFM_LIMLIN = (1 << 8),
57        BT_SLIDER_FLAGS_ERP_LIMLIN = (1 << 9),
58        BT_SLIDER_FLAGS_CFM_LIMANG = (1 << 10),
59        BT_SLIDER_FLAGS_ERP_LIMANG = (1 << 11)
60};
61
62
63class btSliderConstraint : public btTypedConstraint
64{
65protected:
66        ///for backwards compatibility during the transition to 'getInfo/getInfo2'
67        bool            m_useSolveConstraintObsolete;
68        bool            m_useOffsetForConstraintFrame;
69        btTransform     m_frameInA;
70    btTransform m_frameInB;
71        // use frameA fo define limits, if true
72        bool m_useLinearReferenceFrameA;
73        // linear limits
74        btScalar m_lowerLinLimit;
75        btScalar m_upperLinLimit;
76        // angular limits
77        btScalar m_lowerAngLimit;
78        btScalar m_upperAngLimit;
79        // softness, restitution and damping for different cases
80        // DirLin - moving inside linear limits
81        // LimLin - hitting linear limit
82        // DirAng - moving inside angular limits
83        // LimAng - hitting angular limit
84        // OrthoLin, OrthoAng - against constraint axis
85        btScalar m_softnessDirLin;
86        btScalar m_restitutionDirLin;
87        btScalar m_dampingDirLin;
88        btScalar m_cfmDirLin;
89
90        btScalar m_softnessDirAng;
91        btScalar m_restitutionDirAng;
92        btScalar m_dampingDirAng;
93        btScalar m_cfmDirAng;
94
95        btScalar m_softnessLimLin;
96        btScalar m_restitutionLimLin;
97        btScalar m_dampingLimLin;
98        btScalar m_cfmLimLin;
99
100        btScalar m_softnessLimAng;
101        btScalar m_restitutionLimAng;
102        btScalar m_dampingLimAng;
103        btScalar m_cfmLimAng;
104
105        btScalar m_softnessOrthoLin;
106        btScalar m_restitutionOrthoLin;
107        btScalar m_dampingOrthoLin;
108        btScalar m_cfmOrthoLin;
109
110        btScalar m_softnessOrthoAng;
111        btScalar m_restitutionOrthoAng;
112        btScalar m_dampingOrthoAng;
113        btScalar m_cfmOrthoAng;
114       
115        // for interlal use
116        bool m_solveLinLim;
117        bool m_solveAngLim;
118
119        int m_flags;
120
121        btJacobianEntry m_jacLin[3];
122        btScalar                m_jacLinDiagABInv[3];
123
124    btJacobianEntry     m_jacAng[3];
125
126        btScalar m_timeStep;
127    btTransform m_calculatedTransformA;
128    btTransform m_calculatedTransformB;
129
130        btVector3 m_sliderAxis;
131        btVector3 m_realPivotAInW;
132        btVector3 m_realPivotBInW;
133        btVector3 m_projPivotInW;
134        btVector3 m_delta;
135        btVector3 m_depth;
136        btVector3 m_relPosA;
137        btVector3 m_relPosB;
138
139        btScalar m_linPos;
140        btScalar m_angPos;
141
142        btScalar m_angDepth;
143        btScalar m_kAngle;
144
145        bool     m_poweredLinMotor;
146    btScalar m_targetLinMotorVelocity;
147    btScalar m_maxLinMotorForce;
148    btScalar m_accumulatedLinMotorImpulse;
149       
150        bool     m_poweredAngMotor;
151    btScalar m_targetAngMotorVelocity;
152    btScalar m_maxAngMotorForce;
153    btScalar m_accumulatedAngMotorImpulse;
154
155        //------------------------   
156        void initParams();
157public:
158        // constructors
159    btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
160    btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
161
162        // overrides
163
164    virtual void getInfo1 (btConstraintInfo1* info);
165
166        void getInfo1NonVirtual(btConstraintInfo1* info);
167       
168        virtual void getInfo2 (btConstraintInfo2* info);
169
170        void getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA, const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass);
171
172
173        // access
174    const btRigidBody& getRigidBodyA() const { return m_rbA; }
175    const btRigidBody& getRigidBodyB() const { return m_rbB; }
176    const btTransform & getCalculatedTransformA() const { return m_calculatedTransformA; }
177    const btTransform & getCalculatedTransformB() const { return m_calculatedTransformB; }
178    const btTransform & getFrameOffsetA() const { return m_frameInA; }
179    const btTransform & getFrameOffsetB() const { return m_frameInB; }
180    btTransform & getFrameOffsetA() { return m_frameInA; }
181    btTransform & getFrameOffsetB() { return m_frameInB; }
182    btScalar getLowerLinLimit() { return m_lowerLinLimit; }
183    void setLowerLinLimit(btScalar lowerLimit) { m_lowerLinLimit = lowerLimit; }
184    btScalar getUpperLinLimit() { return m_upperLinLimit; }
185    void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; }
186    btScalar getLowerAngLimit() { return m_lowerAngLimit; }
187    void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = btNormalizeAngle(lowerLimit); }
188    btScalar getUpperAngLimit() { return m_upperAngLimit; }
189    void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = btNormalizeAngle(upperLimit); }
190        bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; }
191        btScalar getSoftnessDirLin() { return m_softnessDirLin; }
192        btScalar getRestitutionDirLin() { return m_restitutionDirLin; }
193        btScalar getDampingDirLin() { return m_dampingDirLin ; }
194        btScalar getSoftnessDirAng() { return m_softnessDirAng; }
195        btScalar getRestitutionDirAng() { return m_restitutionDirAng; }
196        btScalar getDampingDirAng() { return m_dampingDirAng; }
197        btScalar getSoftnessLimLin() { return m_softnessLimLin; }
198        btScalar getRestitutionLimLin() { return m_restitutionLimLin; }
199        btScalar getDampingLimLin() { return m_dampingLimLin; }
200        btScalar getSoftnessLimAng() { return m_softnessLimAng; }
201        btScalar getRestitutionLimAng() { return m_restitutionLimAng; }
202        btScalar getDampingLimAng() { return m_dampingLimAng; }
203        btScalar getSoftnessOrthoLin() { return m_softnessOrthoLin; }
204        btScalar getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
205        btScalar getDampingOrthoLin() { return m_dampingOrthoLin; }
206        btScalar getSoftnessOrthoAng() { return m_softnessOrthoAng; }
207        btScalar getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
208        btScalar getDampingOrthoAng() { return m_dampingOrthoAng; }
209        void setSoftnessDirLin(btScalar softnessDirLin) { m_softnessDirLin = softnessDirLin; }
210        void setRestitutionDirLin(btScalar restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
211        void setDampingDirLin(btScalar dampingDirLin) { m_dampingDirLin = dampingDirLin; }
212        void setSoftnessDirAng(btScalar softnessDirAng) { m_softnessDirAng = softnessDirAng; }
213        void setRestitutionDirAng(btScalar restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
214        void setDampingDirAng(btScalar dampingDirAng) { m_dampingDirAng = dampingDirAng; }
215        void setSoftnessLimLin(btScalar softnessLimLin) { m_softnessLimLin = softnessLimLin; }
216        void setRestitutionLimLin(btScalar restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
217        void setDampingLimLin(btScalar dampingLimLin) { m_dampingLimLin = dampingLimLin; }
218        void setSoftnessLimAng(btScalar softnessLimAng) { m_softnessLimAng = softnessLimAng; }
219        void setRestitutionLimAng(btScalar restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
220        void setDampingLimAng(btScalar dampingLimAng) { m_dampingLimAng = dampingLimAng; }
221        void setSoftnessOrthoLin(btScalar softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
222        void setRestitutionOrthoLin(btScalar restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
223        void setDampingOrthoLin(btScalar dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
224        void setSoftnessOrthoAng(btScalar softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
225        void setRestitutionOrthoAng(btScalar restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
226        void setDampingOrthoAng(btScalar dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
227        void setPoweredLinMotor(bool onOff) { m_poweredLinMotor = onOff; }
228        bool getPoweredLinMotor() { return m_poweredLinMotor; }
229        void setTargetLinMotorVelocity(btScalar targetLinMotorVelocity) { m_targetLinMotorVelocity = targetLinMotorVelocity; }
230        btScalar getTargetLinMotorVelocity() { return m_targetLinMotorVelocity; }
231        void setMaxLinMotorForce(btScalar maxLinMotorForce) { m_maxLinMotorForce = maxLinMotorForce; }
232        btScalar getMaxLinMotorForce() { return m_maxLinMotorForce; }
233        void setPoweredAngMotor(bool onOff) { m_poweredAngMotor = onOff; }
234        bool getPoweredAngMotor() { return m_poweredAngMotor; }
235        void setTargetAngMotorVelocity(btScalar targetAngMotorVelocity) { m_targetAngMotorVelocity = targetAngMotorVelocity; }
236        btScalar getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; }
237        void setMaxAngMotorForce(btScalar maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; }
238        btScalar getMaxAngMotorForce() { return m_maxAngMotorForce; }
239
240        btScalar getLinearPos() const { return m_linPos; }
241        btScalar getAngularPos() const { return m_angPos; }
242       
243       
244
245        // access for ODE solver
246        bool getSolveLinLimit() { return m_solveLinLim; }
247        btScalar getLinDepth() { return m_depth[0]; }
248        bool getSolveAngLimit() { return m_solveAngLim; }
249        btScalar getAngDepth() { return m_angDepth; }
250        // shared code used by ODE solver
251        void    calculateTransforms(const btTransform& transA,const btTransform& transB);
252        void    testLinLimits();
253        void    testAngLimits();
254        // access for PE Solver
255        btVector3 getAncorInA();
256        btVector3 getAncorInB();
257        // access for UseFrameOffset
258        bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; }
259        void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; }
260
261        void setFrames(const btTransform& frameA, const btTransform& frameB) 
262        { 
263                m_frameInA=frameA; 
264                m_frameInB=frameB;
265                calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform());
266                buildJacobian();
267        } 
268
269
270        ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
271        ///If no axis is provided, it uses the default axis for this constraint.
272        virtual void    setParam(int num, btScalar value, int axis = -1);
273        ///return the local value of parameter
274        virtual btScalar getParam(int num, int axis = -1) const;
275
276        virtual int     calculateSerializeBufferSize() const;
277
278        ///fills the dataBuffer and returns the struct name (and 0 on failure)
279        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
280
281
282};
283
284///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
285struct btSliderConstraintData
286{
287        btTypedConstraintData   m_typeConstraintData;
288        btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
289        btTransformFloatData m_rbBFrame;
290       
291        float   m_linearUpperLimit;
292        float   m_linearLowerLimit;
293
294        float   m_angularUpperLimit;
295        float   m_angularLowerLimit;
296
297        int     m_useLinearReferenceFrameA;
298        int m_useOffsetForConstraintFrame;
299
300};
301
302
303SIMD_FORCE_INLINE               int     btSliderConstraint::calculateSerializeBufferSize() const
304{
305        return sizeof(btSliderConstraintData);
306}
307
308        ///fills the dataBuffer and returns the struct name (and 0 on failure)
309SIMD_FORCE_INLINE       const char*     btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
310{
311
312        btSliderConstraintData* sliderData = (btSliderConstraintData*) dataBuffer;
313        btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer);
314
315        m_frameInA.serializeFloat(sliderData->m_rbAFrame);
316        m_frameInB.serializeFloat(sliderData->m_rbBFrame);
317
318        sliderData->m_linearUpperLimit = float(m_upperLinLimit);
319        sliderData->m_linearLowerLimit = float(m_lowerLinLimit);
320
321        sliderData->m_angularUpperLimit = float(m_upperAngLimit);
322        sliderData->m_angularLowerLimit = float(m_lowerAngLimit);
323
324        sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA;
325        sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame;
326
327        return "btSliderConstraintData";
328}
329
330
331
332#endif //BT_SLIDER_CONSTRAINT_H
333
Note: See TracBrowser for help on using the repository browser.