Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/src/external/bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h @ 8633

Last change on this file since 8633 was 7983, checked in by rgrieder, 14 years ago

Updated Bullet Physics Engine from v2.74 to v2.77

  • Property svn:eol-style set to native
File size: 12.5 KB
RevLine 
[1963]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 SLIDER_CONSTRAINT_H
26#define SLIDER_CONSTRAINT_H
27
28
[7983]29
[1963]30#include "LinearMath/btVector3.h"
31#include "btJacobianEntry.h"
32#include "btTypedConstraint.h"
33
34
[7983]35
[1963]36class btRigidBody;
37
38
[7983]39
[1963]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))
[7983]43#define SLIDER_CONSTRAINT_DEF_CFM                       (btScalar(0.f))
[1963]44
45
[7983]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
[1963]63class btSliderConstraint : public btTypedConstraint
64{
65protected:
[2882]66        ///for backwards compatibility during the transition to 'getInfo/getInfo2'
67        bool            m_useSolveConstraintObsolete;
[7983]68        bool            m_useOffsetForConstraintFrame;
[1963]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;
[7983]88        btScalar m_cfmDirLin;
89
[1963]90        btScalar m_softnessDirAng;
91        btScalar m_restitutionDirAng;
92        btScalar m_dampingDirAng;
[7983]93        btScalar m_cfmDirAng;
94
[1963]95        btScalar m_softnessLimLin;
96        btScalar m_restitutionLimLin;
97        btScalar m_dampingLimLin;
[7983]98        btScalar m_cfmLimLin;
99
[1963]100        btScalar m_softnessLimAng;
101        btScalar m_restitutionLimAng;
102        btScalar m_dampingLimAng;
[7983]103        btScalar m_cfmLimAng;
104
[1963]105        btScalar m_softnessOrthoLin;
106        btScalar m_restitutionOrthoLin;
107        btScalar m_dampingOrthoLin;
[7983]108        btScalar m_cfmOrthoLin;
109
[1963]110        btScalar m_softnessOrthoAng;
111        btScalar m_restitutionOrthoAng;
112        btScalar m_dampingOrthoAng;
[7983]113        btScalar m_cfmOrthoAng;
[1963]114       
115        // for interlal use
116        bool m_solveLinLim;
117        bool m_solveAngLim;
118
[7983]119        int m_flags;
120
[1963]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;
[2882]140        btScalar m_angPos;
[1963]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);
[7983]160    btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
161
[1963]162        // overrides
[7983]163
[2882]164    virtual void getInfo1 (btConstraintInfo1* info);
[7983]165
166        void getInfo1NonVirtual(btConstraintInfo1* info);
[2882]167       
168        virtual void getInfo2 (btConstraintInfo2* info);
169
[7983]170        void getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA, const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass);
[2882]171
[7983]172
[1963]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; }
[7983]187    void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = btNormalizeAngle(lowerLimit); }
[1963]188    btScalar getUpperAngLimit() { return m_upperAngLimit; }
[7983]189    void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = btNormalizeAngle(upperLimit); }
[1963]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        btScalar getLinearPos() { return m_linPos; }
[2882]240       
[1963]241
242        // access for ODE solver
243        bool getSolveLinLimit() { return m_solveLinLim; }
244        btScalar getLinDepth() { return m_depth[0]; }
245        bool getSolveAngLimit() { return m_solveAngLim; }
246        btScalar getAngDepth() { return m_angDepth; }
247        // shared code used by ODE solver
[7983]248        void    calculateTransforms(const btTransform& transA,const btTransform& transB);
249        void    testLinLimits();
250        void    testAngLimits();
[1963]251        // access for PE Solver
[7983]252        btVector3 getAncorInA();
253        btVector3 getAncorInB();
254        // access for UseFrameOffset
255        bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; }
256        void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; }
257
258        ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
259        ///If no axis is provided, it uses the default axis for this constraint.
260        virtual void    setParam(int num, btScalar value, int axis = -1);
261        ///return the local value of parameter
262        virtual btScalar getParam(int num, int axis = -1) const;
263
264        virtual int     calculateSerializeBufferSize() const;
265
266        ///fills the dataBuffer and returns the struct name (and 0 on failure)
267        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
268
269
[1963]270};
271
[7983]272///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
273struct btSliderConstraintData
274{
275        btTypedConstraintData   m_typeConstraintData;
276        btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
277        btTransformFloatData m_rbBFrame;
278       
279        float   m_linearUpperLimit;
280        float   m_linearLowerLimit;
[1963]281
[7983]282        float   m_angularUpperLimit;
283        float   m_angularLowerLimit;
284
285        int     m_useLinearReferenceFrameA;
286        int m_useOffsetForConstraintFrame;
287
288};
289
290
291SIMD_FORCE_INLINE               int     btSliderConstraint::calculateSerializeBufferSize() const
292{
293        return sizeof(btSliderConstraintData);
294}
295
296        ///fills the dataBuffer and returns the struct name (and 0 on failure)
297SIMD_FORCE_INLINE       const char*     btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
298{
299
300        btSliderConstraintData* sliderData = (btSliderConstraintData*) dataBuffer;
301        btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer);
302
303        m_frameInA.serializeFloat(sliderData->m_rbAFrame);
304        m_frameInB.serializeFloat(sliderData->m_rbBFrame);
305
306        sliderData->m_linearUpperLimit = float(m_upperLinLimit);
307        sliderData->m_linearLowerLimit = float(m_lowerLinLimit);
308
309        sliderData->m_angularUpperLimit = float(m_upperAngLimit);
310        sliderData->m_angularLowerLimit = float(m_lowerAngLimit);
311
312        sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA;
313        sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame;
314
315        return "btSliderConstraintData";
316}
317
318
319
[1963]320#endif //SLIDER_CONSTRAINT_H
321
Note: See TracBrowser for help on using the repository browser.