Back to index

supertuxkart  0.5+dfsg1
btSliderConstraint.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose,
00008 including commercial applications, and to alter it and redistribute it freely,
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 /*
00017 Added by Roman Ponomarev (rponom@gmail.com)
00018 April 04, 2008
00019 
00020 TODO:
00021  - add clamping od accumulated impulse to improve stability
00022  - add conversion for ODE constraint solver
00023 */
00024 
00025 #ifndef SLIDER_CONSTRAINT_H
00026 #define SLIDER_CONSTRAINT_H
00027 
00028 //-----------------------------------------------------------------------------
00029 
00030 #include "LinearMath/btVector3.h"
00031 #include "btJacobianEntry.h"
00032 #include "btTypedConstraint.h"
00033 
00034 //-----------------------------------------------------------------------------
00035 
00036 class btRigidBody;
00037 
00038 //-----------------------------------------------------------------------------
00039 
00040 #define SLIDER_CONSTRAINT_DEF_SOFTNESS           (btScalar(1.0))
00041 #define SLIDER_CONSTRAINT_DEF_DAMPING            (btScalar(1.0))
00042 #define SLIDER_CONSTRAINT_DEF_RESTITUTION (btScalar(0.7))
00043 
00044 //-----------------------------------------------------------------------------
00045 
00046 class btSliderConstraint : public btTypedConstraint
00047 {
00048 protected:
00049        btTransform   m_frameInA;
00050     btTransform      m_frameInB;
00051        // use frameA fo define limits, if true
00052        bool m_useLinearReferenceFrameA;
00053        // linear limits
00054        btScalar m_lowerLinLimit;
00055        btScalar m_upperLinLimit;
00056        // angular limits
00057        btScalar m_lowerAngLimit;
00058        btScalar m_upperAngLimit;
00059        // softness, restitution and damping for different cases
00060        // DirLin - moving inside linear limits
00061        // LimLin - hitting linear limit
00062        // DirAng - moving inside angular limits
00063        // LimAng - hitting angular limit
00064        // OrthoLin, OrthoAng - against constraint axis
00065        btScalar m_softnessDirLin;
00066        btScalar m_restitutionDirLin;
00067        btScalar m_dampingDirLin;
00068        btScalar m_softnessDirAng;
00069        btScalar m_restitutionDirAng;
00070        btScalar m_dampingDirAng;
00071        btScalar m_softnessLimLin;
00072        btScalar m_restitutionLimLin;
00073        btScalar m_dampingLimLin;
00074        btScalar m_softnessLimAng;
00075        btScalar m_restitutionLimAng;
00076        btScalar m_dampingLimAng;
00077        btScalar m_softnessOrthoLin;
00078        btScalar m_restitutionOrthoLin;
00079        btScalar m_dampingOrthoLin;
00080        btScalar m_softnessOrthoAng;
00081        btScalar m_restitutionOrthoAng;
00082        btScalar m_dampingOrthoAng;
00083        
00084        // for interlal use
00085        bool m_solveLinLim;
00086        bool m_solveAngLim;
00087 
00088        btJacobianEntry      m_jacLin[3];
00089        btScalar             m_jacLinDiagABInv[3];
00090 
00091     btJacobianEntry  m_jacAng[3];
00092 
00093        btScalar m_timeStep;
00094     btTransform m_calculatedTransformA;
00095     btTransform m_calculatedTransformB;
00096 
00097        btVector3 m_sliderAxis;
00098        btVector3 m_realPivotAInW;
00099        btVector3 m_realPivotBInW;
00100        btVector3 m_projPivotInW;
00101        btVector3 m_delta;
00102        btVector3 m_depth;
00103        btVector3 m_relPosA;
00104        btVector3 m_relPosB;
00105 
00106        btScalar m_angDepth;
00107        btScalar m_kAngle;
00108 
00109        
00110        //------------------------    
00111        void initParams();
00112 public:
00113        // constructors
00114     btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
00115     btSliderConstraint();
00116        // overrides
00117     virtual void     buildJacobian();
00118     virtual   void   solveConstraint(btScalar    timeStep);
00119        // access
00120     const btRigidBody& getRigidBodyA() const { return m_rbA; }
00121     const btRigidBody& getRigidBodyB() const { return m_rbB; }
00122     const btTransform & getCalculatedTransformA() const { return m_calculatedTransformA; }
00123     const btTransform & getCalculatedTransformB() const { return m_calculatedTransformB; }
00124     const btTransform & getFrameOffsetA() const { return m_frameInA; }
00125     const btTransform & getFrameOffsetB() const { return m_frameInB; }
00126     btTransform & getFrameOffsetA() { return m_frameInA; }
00127     btTransform & getFrameOffsetB() { return m_frameInB; }
00128     btScalar getLowerLinLimit() { return m_lowerLinLimit; }
00129     void setLowerLinLimit(btScalar lowerLimit) { m_lowerLinLimit = lowerLimit; }
00130     btScalar getUpperLinLimit() { return m_upperLinLimit; }
00131     void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; }
00132     btScalar getLowerAngLimit() { return m_lowerAngLimit; }
00133     void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = lowerLimit; }
00134     btScalar getUpperAngLimit() { return m_upperAngLimit; }
00135     void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = upperLimit; }
00136        bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; }
00137        btScalar getSoftnessDirLin() { return m_softnessDirLin; }
00138        btScalar getRestitutionDirLin() { return m_restitutionDirLin; }
00139        btScalar getDampingDirLin() { return m_dampingDirLin ; }
00140        btScalar getSoftnessDirAng() { return m_softnessDirAng; }
00141        btScalar getRestitutionDirAng() { return m_restitutionDirAng; }
00142        btScalar getDampingDirAng() { return m_dampingDirAng; }
00143        btScalar getSoftnessLimLin() { return m_softnessLimLin; }
00144        btScalar getRestitutionLimLin() { return m_restitutionLimLin; }
00145        btScalar getDampingLimLin() { return m_dampingLimLin; }
00146        btScalar getSoftnessLimAng() { return m_softnessLimAng; }
00147        btScalar getRestitutionLimAng() { return m_restitutionLimAng; }
00148        btScalar getDampingLimAng() { return m_dampingLimAng; }
00149        btScalar getSoftnessOrthoLin() { return m_softnessOrthoLin; }
00150        btScalar getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
00151        btScalar getDampingOrthoLin() { return m_dampingOrthoLin; }
00152        btScalar getSoftnessOrthoAng() { return m_softnessOrthoAng; }
00153        btScalar getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
00154        btScalar getDampingOrthoAng() { return m_dampingOrthoAng; }
00155        void setSoftnessDirLin(btScalar softnessDirLin) { m_softnessDirLin = softnessDirLin; }
00156        void setRestitutionDirLin(btScalar restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
00157        void setDampingDirLin(btScalar dampingDirLin) { m_dampingDirLin = dampingDirLin; }
00158        void setSoftnessDirAng(btScalar softnessDirAng) { m_softnessDirAng = softnessDirAng; }
00159        void setRestitutionDirAng(btScalar restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
00160        void setDampingDirAng(btScalar dampingDirAng) { m_dampingDirAng = dampingDirAng; }
00161        void setSoftnessLimLin(btScalar softnessLimLin) { m_softnessLimLin = softnessLimLin; }
00162        void setRestitutionLimLin(btScalar restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
00163        void setDampingLimLin(btScalar dampingLimLin) { m_dampingLimLin = dampingLimLin; }
00164        void setSoftnessLimAng(btScalar softnessLimAng) { m_softnessLimAng = softnessLimAng; }
00165        void setRestitutionLimAng(btScalar restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
00166        void setDampingLimAng(btScalar dampingLimAng) { m_dampingLimAng = dampingLimAng; }
00167        void setSoftnessOrthoLin(btScalar softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
00168        void setRestitutionOrthoLin(btScalar restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
00169        void setDampingOrthoLin(btScalar dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
00170        void setSoftnessOrthoAng(btScalar softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
00171        void setRestitutionOrthoAng(btScalar restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
00172        void setDampingOrthoAng(btScalar dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
00173        // internal
00174     void      buildJacobianInt(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB);
00175     void      solveConstraintInt(btRigidBody& rbA, btRigidBody& rbB);
00176 };
00177 
00178 //-----------------------------------------------------------------------------
00179 
00180 #endif //SLIDER_CONSTRAINT_H
00181