Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2974 was 2882, checked in by rgrieder, 16 years ago

Update from Bullet 2.73 to 2.74.

  • Property svn:eol-style set to native
File size: 10.0 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 SLIDER_CONSTRAINT_H
26#define 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
44//-----------------------------------------------------------------------------
45
46class btSliderConstraint : public btTypedConstraint
47{
48protected:
49        ///for backwards compatibility during the transition to 'getInfo/getInfo2'
50        bool            m_useSolveConstraintObsolete;
51        btTransform     m_frameInA;
52    btTransform m_frameInB;
53        // use frameA fo define limits, if true
54        bool m_useLinearReferenceFrameA;
55        // linear limits
56        btScalar m_lowerLinLimit;
57        btScalar m_upperLinLimit;
58        // angular limits
59        btScalar m_lowerAngLimit;
60        btScalar m_upperAngLimit;
61        // softness, restitution and damping for different cases
62        // DirLin - moving inside linear limits
63        // LimLin - hitting linear limit
64        // DirAng - moving inside angular limits
65        // LimAng - hitting angular limit
66        // OrthoLin, OrthoAng - against constraint axis
67        btScalar m_softnessDirLin;
68        btScalar m_restitutionDirLin;
69        btScalar m_dampingDirLin;
70        btScalar m_softnessDirAng;
71        btScalar m_restitutionDirAng;
72        btScalar m_dampingDirAng;
73        btScalar m_softnessLimLin;
74        btScalar m_restitutionLimLin;
75        btScalar m_dampingLimLin;
76        btScalar m_softnessLimAng;
77        btScalar m_restitutionLimAng;
78        btScalar m_dampingLimAng;
79        btScalar m_softnessOrthoLin;
80        btScalar m_restitutionOrthoLin;
81        btScalar m_dampingOrthoLin;
82        btScalar m_softnessOrthoAng;
83        btScalar m_restitutionOrthoAng;
84        btScalar m_dampingOrthoAng;
85       
86        // for interlal use
87        bool m_solveLinLim;
88        bool m_solveAngLim;
89
90        btJacobianEntry m_jacLin[3];
91        btScalar                m_jacLinDiagABInv[3];
92
93    btJacobianEntry     m_jacAng[3];
94
95        btScalar m_timeStep;
96    btTransform m_calculatedTransformA;
97    btTransform m_calculatedTransformB;
98
99        btVector3 m_sliderAxis;
100        btVector3 m_realPivotAInW;
101        btVector3 m_realPivotBInW;
102        btVector3 m_projPivotInW;
103        btVector3 m_delta;
104        btVector3 m_depth;
105        btVector3 m_relPosA;
106        btVector3 m_relPosB;
107
108        btScalar m_linPos;
109        btScalar m_angPos;
110
111        btScalar m_angDepth;
112        btScalar m_kAngle;
113
114        bool     m_poweredLinMotor;
115    btScalar m_targetLinMotorVelocity;
116    btScalar m_maxLinMotorForce;
117    btScalar m_accumulatedLinMotorImpulse;
118       
119        bool     m_poweredAngMotor;
120    btScalar m_targetAngMotorVelocity;
121    btScalar m_maxAngMotorForce;
122    btScalar m_accumulatedAngMotorImpulse;
123
124        //------------------------   
125        void initParams();
126public:
127        // constructors
128    btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
129    btSliderConstraint();
130        // overrides
131    virtual void        buildJacobian();
132    virtual void getInfo1 (btConstraintInfo1* info);
133       
134        virtual void getInfo2 (btConstraintInfo2* info);
135
136    virtual     void    solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar        timeStep);
137       
138
139        // access
140    const btRigidBody& getRigidBodyA() const { return m_rbA; }
141    const btRigidBody& getRigidBodyB() const { return m_rbB; }
142    const btTransform & getCalculatedTransformA() const { return m_calculatedTransformA; }
143    const btTransform & getCalculatedTransformB() const { return m_calculatedTransformB; }
144    const btTransform & getFrameOffsetA() const { return m_frameInA; }
145    const btTransform & getFrameOffsetB() const { return m_frameInB; }
146    btTransform & getFrameOffsetA() { return m_frameInA; }
147    btTransform & getFrameOffsetB() { return m_frameInB; }
148    btScalar getLowerLinLimit() { return m_lowerLinLimit; }
149    void setLowerLinLimit(btScalar lowerLimit) { m_lowerLinLimit = lowerLimit; }
150    btScalar getUpperLinLimit() { return m_upperLinLimit; }
151    void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; }
152    btScalar getLowerAngLimit() { return m_lowerAngLimit; }
153    void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = lowerLimit; }
154    btScalar getUpperAngLimit() { return m_upperAngLimit; }
155    void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = upperLimit; }
156        bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; }
157        btScalar getSoftnessDirLin() { return m_softnessDirLin; }
158        btScalar getRestitutionDirLin() { return m_restitutionDirLin; }
159        btScalar getDampingDirLin() { return m_dampingDirLin ; }
160        btScalar getSoftnessDirAng() { return m_softnessDirAng; }
161        btScalar getRestitutionDirAng() { return m_restitutionDirAng; }
162        btScalar getDampingDirAng() { return m_dampingDirAng; }
163        btScalar getSoftnessLimLin() { return m_softnessLimLin; }
164        btScalar getRestitutionLimLin() { return m_restitutionLimLin; }
165        btScalar getDampingLimLin() { return m_dampingLimLin; }
166        btScalar getSoftnessLimAng() { return m_softnessLimAng; }
167        btScalar getRestitutionLimAng() { return m_restitutionLimAng; }
168        btScalar getDampingLimAng() { return m_dampingLimAng; }
169        btScalar getSoftnessOrthoLin() { return m_softnessOrthoLin; }
170        btScalar getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
171        btScalar getDampingOrthoLin() { return m_dampingOrthoLin; }
172        btScalar getSoftnessOrthoAng() { return m_softnessOrthoAng; }
173        btScalar getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
174        btScalar getDampingOrthoAng() { return m_dampingOrthoAng; }
175        void setSoftnessDirLin(btScalar softnessDirLin) { m_softnessDirLin = softnessDirLin; }
176        void setRestitutionDirLin(btScalar restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
177        void setDampingDirLin(btScalar dampingDirLin) { m_dampingDirLin = dampingDirLin; }
178        void setSoftnessDirAng(btScalar softnessDirAng) { m_softnessDirAng = softnessDirAng; }
179        void setRestitutionDirAng(btScalar restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
180        void setDampingDirAng(btScalar dampingDirAng) { m_dampingDirAng = dampingDirAng; }
181        void setSoftnessLimLin(btScalar softnessLimLin) { m_softnessLimLin = softnessLimLin; }
182        void setRestitutionLimLin(btScalar restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
183        void setDampingLimLin(btScalar dampingLimLin) { m_dampingLimLin = dampingLimLin; }
184        void setSoftnessLimAng(btScalar softnessLimAng) { m_softnessLimAng = softnessLimAng; }
185        void setRestitutionLimAng(btScalar restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
186        void setDampingLimAng(btScalar dampingLimAng) { m_dampingLimAng = dampingLimAng; }
187        void setSoftnessOrthoLin(btScalar softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
188        void setRestitutionOrthoLin(btScalar restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
189        void setDampingOrthoLin(btScalar dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
190        void setSoftnessOrthoAng(btScalar softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
191        void setRestitutionOrthoAng(btScalar restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
192        void setDampingOrthoAng(btScalar dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
193        void setPoweredLinMotor(bool onOff) { m_poweredLinMotor = onOff; }
194        bool getPoweredLinMotor() { return m_poweredLinMotor; }
195        void setTargetLinMotorVelocity(btScalar targetLinMotorVelocity) { m_targetLinMotorVelocity = targetLinMotorVelocity; }
196        btScalar getTargetLinMotorVelocity() { return m_targetLinMotorVelocity; }
197        void setMaxLinMotorForce(btScalar maxLinMotorForce) { m_maxLinMotorForce = maxLinMotorForce; }
198        btScalar getMaxLinMotorForce() { return m_maxLinMotorForce; }
199        void setPoweredAngMotor(bool onOff) { m_poweredAngMotor = onOff; }
200        bool getPoweredAngMotor() { return m_poweredAngMotor; }
201        void setTargetAngMotorVelocity(btScalar targetAngMotorVelocity) { m_targetAngMotorVelocity = targetAngMotorVelocity; }
202        btScalar getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; }
203        void setMaxAngMotorForce(btScalar maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; }
204        btScalar getMaxAngMotorForce() { return m_maxAngMotorForce; }
205        btScalar getLinearPos() { return m_linPos; }
206       
207
208        // access for ODE solver
209        bool getSolveLinLimit() { return m_solveLinLim; }
210        btScalar getLinDepth() { return m_depth[0]; }
211        bool getSolveAngLimit() { return m_solveAngLim; }
212        btScalar getAngDepth() { return m_angDepth; }
213        // internal
214    void        buildJacobianInt(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB);
215    void        solveConstraintInt(btRigidBody& rbA, btSolverBody& bodyA,btRigidBody& rbB, btSolverBody& bodyB);
216        // shared code used by ODE solver
217        void    calculateTransforms(void);
218        void    testLinLimits(void);
219        void    testLinLimits2(btConstraintInfo2* info);
220        void    testAngLimits(void);
221        // access for PE Solver
222        btVector3 getAncorInA(void);
223        btVector3 getAncorInB(void);
224};
225
226//-----------------------------------------------------------------------------
227
228#endif //SLIDER_CONSTRAINT_H
229
Note: See TracBrowser for help on using the repository browser.