Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 6:58:23 PM (13 years ago)
Author:
rgrieder
Message:

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/bullet/BulletDynamics/ConstraintSolver/btTypedConstraint.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2010 Erwin Coumans  http://continuousphysics.com/Bullet/
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2020#include "LinearMath/btScalar.h"
    2121#include "btSolverConstraint.h"
    22 struct  btSolverBody;
    23 
    24 
    25 
     22#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
     23
     24class btSerializer;
    2625
    2726enum btTypedConstraintType
    2827{
    29         POINT2POINT_CONSTRAINT_TYPE,
     28        POINT2POINT_CONSTRAINT_TYPE=MAX_CONTACT_MANIFOLD_TYPE+1,
    3029        HINGE_CONSTRAINT_TYPE,
    3130        CONETWIST_CONSTRAINT_TYPE,
    3231        D6_CONSTRAINT_TYPE,
    33         SLIDER_CONSTRAINT_TYPE
     32        SLIDER_CONSTRAINT_TYPE,
     33        CONTACT_CONSTRAINT_TYPE
    3434};
    3535
     36
     37enum btConstraintParams
     38{
     39        BT_CONSTRAINT_ERP=1,
     40        BT_CONSTRAINT_STOP_ERP,
     41        BT_CONSTRAINT_CFM,
     42        BT_CONSTRAINT_STOP_CFM
     43};
     44
     45#if 1
     46        #define btAssertConstrParams(_par) btAssert(_par)
     47#else
     48        #define btAssertConstrParams(_par)
     49#endif
     50
     51
    3652///TypedConstraint is the baseclass for Bullet constraints and vehicles
    37 class btTypedConstraint
     53class btTypedConstraint : public btTypedObject
    3854{
    3955        int     m_userConstraintType;
    40         int     m_userConstraintId;
    41 
    42         btTypedConstraintType m_constraintType;
     56
     57        union
     58        {
     59                int     m_userConstraintId;
     60                void* m_userConstraintPtr;
     61        };
     62
     63        bool m_needsFeedback;
    4364
    4465        btTypedConstraint&      operator=(btTypedConstraint&    other)
     
    5576        btScalar        m_dbgDrawSize;
    5677
     78        ///internal method used by the constraint solver, don't use them directly
     79        btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact);
     80       
     81        static btRigidBody& getFixedBody();
    5782
    5883public:
    5984
    60         btTypedConstraint(btTypedConstraintType type);
    6185        virtual ~btTypedConstraint() {};
    6286        btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA);
     
    94118                // the constraint.
    95119                int *findex;
     120                // number of solver iterations
     121                int m_numIterations;
     122
     123                //damping of the velocity
     124                btScalar        m_damping;
    96125        };
    97126
    98 
    99         virtual void    buildJacobian() = 0;
    100 
     127        ///internal method used by the constraint solver, don't use them directly
     128        virtual void    buildJacobian() {};
     129
     130        ///internal method used by the constraint solver, don't use them directly
    101131        virtual void    setupSolverConstraint(btConstraintArray& ca, int solverBodyA,int solverBodyB, btScalar timeStep)
    102132        {
    103         }
     133        (void)ca;
     134        (void)solverBodyA;
     135        (void)solverBodyB;
     136        (void)timeStep;
     137        }
     138       
     139        ///internal method used by the constraint solver, don't use them directly
    104140        virtual void getInfo1 (btConstraintInfo1* info)=0;
    105141
     142        ///internal method used by the constraint solver, don't use them directly
    106143        virtual void getInfo2 (btConstraintInfo2* info)=0;
    107144
    108         virtual void    solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar        timeStep) = 0;
    109 
    110         btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact);
     145        ///internal method used by the constraint solver, don't use them directly
     146        void    internalSetAppliedImpulse(btScalar appliedImpulse)
     147        {
     148                m_appliedImpulse = appliedImpulse;
     149        }
     150        ///internal method used by the constraint solver, don't use them directly
     151        btScalar        internalGetAppliedImpulse()
     152        {
     153                return m_appliedImpulse;
     154        }
     155
     156        ///internal method used by the constraint solver, don't use them directly
     157        virtual void    solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar  /*timeStep*/) {};
     158
    111159       
    112160        const btRigidBody& getRigidBodyA() const
     
    148196        }
    149197
     198        void    setUserConstraintPtr(void* ptr)
     199        {
     200                m_userConstraintPtr = ptr;
     201        }
     202
     203        void*   getUserConstraintPtr()
     204        {
     205                return m_userConstraintPtr;
     206        }
     207
    150208        int getUid() const
    151209        {
     
    153211        }
    154212
     213        bool    needsFeedback() const
     214        {
     215                return m_needsFeedback;
     216        }
     217
     218        ///enableFeedback will allow to read the applied linear and angular impulse
     219        ///use getAppliedImpulse, getAppliedLinearImpulse and getAppliedAngularImpulse to read feedback information
     220        void    enableFeedback(bool needsFeedback)
     221        {
     222                m_needsFeedback = needsFeedback;
     223        }
     224
     225        ///getAppliedImpulse is an estimated total applied impulse.
     226        ///This feedback could be used to determine breaking constraints or playing sounds.
    155227        btScalar        getAppliedImpulse() const
    156228        {
     229                btAssert(m_needsFeedback);
    157230                return m_appliedImpulse;
    158231        }
     
    160233        btTypedConstraintType getConstraintType () const
    161234        {
    162                 return m_constraintType;
     235                return btTypedConstraintType(m_objectType);
    163236        }
    164237       
     
    171244                return m_dbgDrawSize;
    172245        }
    173        
     246
     247        ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
     248        ///If no axis is provided, it uses the default axis for this constraint.
     249        virtual void    setParam(int num, btScalar value, int axis = -1) = 0;
     250
     251        ///return the local value of parameter
     252        virtual btScalar getParam(int num, int axis = -1) const = 0;
     253       
     254        virtual int     calculateSerializeBufferSize() const;
     255
     256        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     257        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     258
    174259};
    175260
     261// returns angle in range [-SIMD_2_PI, SIMD_2_PI], closest to one of the limits
     262// all arguments should be normalized angles (i.e. in range [-SIMD_PI, SIMD_PI])
     263SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians)
     264{
     265        if(angleLowerLimitInRadians >= angleUpperLimitInRadians)
     266        {
     267                return angleInRadians;
     268        }
     269        else if(angleInRadians < angleLowerLimitInRadians)
     270        {
     271                btScalar diffLo = btFabs(btNormalizeAngle(angleLowerLimitInRadians - angleInRadians));
     272                btScalar diffHi = btFabs(btNormalizeAngle(angleUpperLimitInRadians - angleInRadians));
     273                return (diffLo < diffHi) ? angleInRadians : (angleInRadians + SIMD_2_PI);
     274        }
     275        else if(angleInRadians > angleUpperLimitInRadians)
     276        {
     277                btScalar diffHi = btFabs(btNormalizeAngle(angleInRadians - angleUpperLimitInRadians));
     278                btScalar diffLo = btFabs(btNormalizeAngle(angleInRadians - angleLowerLimitInRadians));
     279                return (diffLo < diffHi) ? (angleInRadians - SIMD_2_PI) : angleInRadians;
     280        }
     281        else
     282        {
     283                return angleInRadians;
     284        }
     285}
     286
     287///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     288struct  btTypedConstraintData
     289{
     290        btRigidBodyData         *m_rbA;
     291        btRigidBodyData         *m_rbB;
     292        char    *m_name;
     293
     294        int     m_objectType;
     295        int     m_userConstraintType;
     296        int     m_userConstraintId;
     297        int     m_needsFeedback;
     298
     299        float   m_appliedImpulse;
     300        float   m_dbgDrawSize;
     301
     302        int     m_disableCollisionsBetweenLinkedBodies;
     303        char    m_pad4[4];
     304       
     305};
     306
     307SIMD_FORCE_INLINE       int     btTypedConstraint::calculateSerializeBufferSize() const
     308{
     309        return sizeof(btTypedConstraintData);
     310}
     311
     312
     313
     314
    176315#endif //TYPED_CONSTRAINT_H
Note: See TracChangeset for help on using the changeset viewer.