Back to index

supertuxkart  0.5+dfsg1
btHingeConstraint.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 /* Hinge Constraint by Dirk Gregorius. Limits added by Marcus Hennix at Starbreeze Studios */
00017 
00018 #ifndef HINGECONSTRAINT_H
00019 #define HINGECONSTRAINT_H
00020 
00021 #include "LinearMath/btVector3.h"
00022 #include "btJacobianEntry.h"
00023 #include "btTypedConstraint.h"
00024 
00025 class btRigidBody;
00026 
00029 class btHingeConstraint : public btTypedConstraint
00030 {
00031 #ifdef IN_PARALLELL_SOLVER
00032 public:
00033 #endif
00034        btJacobianEntry      m_jac[3]; //3 orthogonal linear constraints
00035        btJacobianEntry      m_jacAng[3]; //2 orthogonal angular constraints+ 1 for limit/motor
00036 
00037        btTransform m_rbAFrame; // constraint axii. Assumes z is hinge axis.
00038        btTransform m_rbBFrame;
00039 
00040        btScalar      m_motorTargetVelocity;
00041        btScalar      m_maxMotorImpulse;
00042 
00043        btScalar      m_limitSoftness; 
00044        btScalar      m_biasFactor; 
00045        btScalar    m_relaxationFactor; 
00046 
00047        btScalar    m_lowerLimit;   
00048        btScalar    m_upperLimit;   
00049        
00050        btScalar      m_kHinge;
00051 
00052        btScalar      m_limitSign;
00053        btScalar      m_correction;
00054 
00055        btScalar      m_accLimitImpulse;
00056 
00057        bool          m_angularOnly;
00058        bool          m_enableAngularMotor;
00059        bool          m_solveLimit;
00060 
00061        
00062 public:
00063 
00064        btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, btVector3& axisInA,btVector3& axisInB);
00065 
00066        btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA,btVector3& axisInA);
00067        
00068        btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame);
00069 
00070        btHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame);
00071 
00072        btHingeConstraint();
00073 
00074        virtual void  buildJacobian();
00075 
00076        virtual       void   solveConstraint(btScalar    timeStep);
00077 
00078        void   updateRHS(btScalar   timeStep);
00079 
00080        const btRigidBody& getRigidBodyA() const
00081        {
00082               return m_rbA;
00083        }
00084        const btRigidBody& getRigidBodyB() const
00085        {
00086               return m_rbB;
00087        }
00088 
00089        void   setAngularOnly(bool angularOnly)
00090        {
00091               m_angularOnly = angularOnly;
00092        }
00093 
00094        void   enableAngularMotor(bool enableMotor,btScalar targetVelocity,btScalar maxMotorImpulse)
00095        {
00096               m_enableAngularMotor  = enableMotor;
00097               m_motorTargetVelocity = targetVelocity;
00098               m_maxMotorImpulse = maxMotorImpulse;
00099        }
00100 
00101        void   setLimit(btScalar low,btScalar high,btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f)
00102        {
00103               m_lowerLimit = low;
00104               m_upperLimit = high;
00105 
00106               m_limitSoftness =  _softness;
00107               m_biasFactor = _biasFactor;
00108               m_relaxationFactor = _relaxationFactor;
00109 
00110        }
00111 
00112        btScalar      getLowerLimit() const
00113        {
00114               return m_lowerLimit;
00115        }
00116 
00117        btScalar      getUpperLimit() const
00118        {
00119               return m_upperLimit;
00120        }
00121 
00122 
00123        btScalar getHingeAngle();
00124 
00125 
00126        const btTransform& getAFrame() { return m_rbAFrame; };  
00127        const btTransform& getBFrame() { return m_rbBFrame; };
00128 
00129        inline int getSolveLimit()
00130        {
00131               return m_solveLimit;
00132        }
00133 
00134        inline btScalar getLimitSign()
00135        {
00136               return m_limitSign;
00137        }
00138               
00139 };
00140 
00141 #endif //HINGECONSTRAINT_H