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/btConeTwistConstraint.h

    r5781 r8284  
    1818
    1919
     20/*
     21Overview:
     22
     23btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc).
     24It is a fixed translation, 3 degree-of-freedom (DOF) rotational "joint".
     25It divides the 3 rotational DOFs into swing (movement within a cone) and twist.
     26Swing is divided into swing1 and swing2 which can have different limits, giving an elliptical shape.
     27(Note: the cone's base isn't flat, so this ellipse is "embedded" on the surface of a sphere.)
     28
     29In the contraint's frame of reference:
     30twist is along the x-axis,
     31and swing 1 and 2 are along the z and y axes respectively.
     32*/
     33
     34
     35
    2036#ifndef CONETWISTCONSTRAINT_H
    2137#define CONETWISTCONSTRAINT_H
     
    2743class btRigidBody;
    2844
     45enum btConeTwistFlags
     46{
     47        BT_CONETWIST_FLAGS_LIN_CFM = 1,
     48        BT_CONETWIST_FLAGS_LIN_ERP = 2,
     49        BT_CONETWIST_FLAGS_ANG_CFM = 4
     50};
    2951
    3052///btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc)
     
    84106        btVector3        m_accMotorImpulse;
    85107       
     108        // parameters
     109        int                     m_flags;
     110        btScalar        m_linCFM;
     111        btScalar        m_linERP;
     112        btScalar        m_angCFM;
     113       
     114protected:
     115
     116        void init();
     117
     118        void computeConeLimitInfo(const btQuaternion& qCone, // in
     119                btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs
     120
     121        void computeTwistLimitInfo(const btQuaternion& qTwist, // in
     122                btScalar& twistAngle, btVector3& vTwistAxis); // all outs
     123
     124        void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const;
     125
     126
    86127public:
    87128
     
    90131        btConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame);
    91132
    92         btConeTwistConstraint();
    93 
    94133        virtual void    buildJacobian();
    95134
    96135        virtual void getInfo1 (btConstraintInfo1* info);
     136
     137        void    getInfo1NonVirtual(btConstraintInfo1* info);
    97138       
    98139        virtual void getInfo2 (btConstraintInfo2* info);
    99140       
    100 
    101         virtual void    solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar        timeStep);
     141        void    getInfo2NonVirtual(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB);
     142
     143        virtual void    solveConstraintObsolete(btRigidBody& bodyA,btRigidBody& bodyB,btScalar  timeStep);
    102144
    103145        void    updateRHS(btScalar      timeStep);
     
    142184        }
    143185
    144         void    setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan,  btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f)
     186        // setLimit(), a few notes:
     187        // _softness:
     188        //              0->1, recommend ~0.8->1.
     189        //              describes % of limits where movement is free.
     190        //              beyond this softness %, the limit is gradually enforced until the "hard" (1.0) limit is reached.
     191        // _biasFactor:
     192        //              0->1?, recommend 0.3 +/-0.3 or so.
     193        //              strength with which constraint resists zeroth order (angular, not angular velocity) limit violation.
     194        // __relaxationFactor:
     195        //              0->1, recommend to stay near 1.
     196        //              the lower the value, the less the constraint will fight velocities which violate the angular limits.
     197        void    setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan, btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f)
    145198        {
    146199                m_swingSpan1 = _swingSpan1;
     
    172225
    173226        void calcAngleInfo();
    174         void calcAngleInfo2();
     227        void calcAngleInfo2(const btTransform& transA, const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB);
    175228
    176229        inline btScalar getSwingSpan1()
     
    213266        btVector3 GetPointForAngle(btScalar fAngleInRadians, btScalar fLength) const;
    214267
    215 
    216 
    217 protected:
    218         void init();
    219 
    220         void computeConeLimitInfo(const btQuaternion& qCone, // in
    221                 btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs
    222 
    223         void computeTwistLimitInfo(const btQuaternion& qTwist, // in
    224                 btScalar& twistAngle, btVector3& vTwistAxis); // all outs
    225 
    226         void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const;
     268        ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
     269        ///If no axis is provided, it uses the default axis for this constraint.
     270        virtual void setParam(int num, btScalar value, int axis = -1);
     271        ///return the local value of parameter
     272        virtual btScalar getParam(int num, int axis = -1) const;
     273
     274        virtual int     calculateSerializeBufferSize() const;
     275
     276        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     277        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     278
    227279};
    228280
     281///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     282struct  btConeTwistConstraintData
     283{
     284        btTypedConstraintData   m_typeConstraintData;
     285        btTransformFloatData m_rbAFrame;
     286        btTransformFloatData m_rbBFrame;
     287
     288        //limits
     289        float   m_swingSpan1;
     290        float   m_swingSpan2;
     291        float   m_twistSpan;
     292        float   m_limitSoftness;
     293        float   m_biasFactor;
     294        float   m_relaxationFactor;
     295
     296        float   m_damping;
     297               
     298        char m_pad[4];
     299
     300};
     301       
     302
     303
     304SIMD_FORCE_INLINE int   btConeTwistConstraint::calculateSerializeBufferSize() const
     305{
     306        return sizeof(btConeTwistConstraintData);
     307
     308}
     309
     310
     311        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     312SIMD_FORCE_INLINE const char*   btConeTwistConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
     313{
     314        btConeTwistConstraintData* cone = (btConeTwistConstraintData*) dataBuffer;
     315        btTypedConstraint::serialize(&cone->m_typeConstraintData,serializer);
     316
     317        m_rbAFrame.serializeFloat(cone->m_rbAFrame);
     318        m_rbBFrame.serializeFloat(cone->m_rbBFrame);
     319       
     320        cone->m_swingSpan1 = float(m_swingSpan1);
     321        cone->m_swingSpan2 = float(m_swingSpan2);
     322        cone->m_twistSpan = float(m_twistSpan);
     323        cone->m_limitSoftness = float(m_limitSoftness);
     324        cone->m_biasFactor = float(m_biasFactor);
     325        cone->m_relaxationFactor = float(m_relaxationFactor);
     326        cone->m_damping = float(m_damping);
     327
     328        return "btConeTwistConstraintData";
     329}
     330
     331
    229332#endif //CONETWISTCONSTRAINT_H
Note: See TracChangeset for help on using the changeset viewer.