Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h @ 2258

Last change on this file since 2258 was 2192, checked in by rgrieder, 16 years ago

Reverted all changes of attempt to update physics branch.

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