Changeset 3349

Show
Ignore:
Timestamp:
02/01/10 14:17:05 (6 weeks ago)
Author:
Azaezel
Message:

removed bullets TransformCallback? method for the CollisionShape?, instead using an overloaded btMotionState for the PhysicsActor?. as these are callbacks which call behaviors referencing instances, the net effect is the same, though admittedly somewhat hairy to read over. perhaps there's a cleaner method available we can implement later

Location:
plugins/branches/0185_GEN_PHYSICS_REFACTOR_2
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZBullet/src/CollisionShape.hpp

    r3294 r3349  
    7878    /// @{ 
    7979private: 
    80     static void TransformCallback(const btRigidBody* _body, const Zen::Math::Real* _matrix); 
    8180    static void ApplyForceAndTorqueCallback(const btRigidBody* _pBody); 
    8281    static void ActivationStateCallback(const btRigidBody* body, unsigned state); 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZBullet/src/PhysicsActor.cpp

    r3347 r3349  
    5858 
    5959    m_name = ""; 
     60    m_MotionState = NULL; 
    6061} 
    6162 
     
    6364PhysicsActor::~PhysicsActor() 
    6465{ 
    65     //NewtonDestroyBody(dynamic_cast<PhysicsZone*>(m_pZone.get())->getZonePtr(), m_pActor); 
     66    if (m_MotionState != NULL) delete m_MotionState; 
    6667} 
    6768 
     
    131132 
    132133    // set the transform call back function 
    133     btRigidBodySetTransformCallback(m_pActor, TransformCallback); 
    134      
     134    m_MotionState = new PhysicsActor::ZenMotionState(this); 
     135 
    135136    m_pActor->setUserPointer(this); 
    136137 
     
    423424 
    424425//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    425 // set the transformation of a rigid body 
    426 void  
    427 PhysicsActor::TransformCallback(const btRigidBody* _body, const Zen::Math::Real* _matrix) 
    428 { 
    429     void* pBody = _body->getUserPointer(); 
    430     if (pBody != NULL) 
     426void 
     427PhysicsActor::ZenMotionState::getWorldTransform(btTransform& _worldTrans) const 
     428{ 
     429 
     430} 
     431 
     432//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     433void 
     434PhysicsActor::ZenMotionState::setWorldTransform(const btTransform& _worldTrans) 
     435{ 
     436    if (m_userPointer == NULL) return; 
     437    PhysicsActor* pShape = static_cast<PhysicsActor*>(m_userPointer); 
     438 
     439    // Only use the transform callback if the state is active 
     440    if (pShape->getActivationState() == 1) 
    431441    { 
    432         PhysicsActor* pShape = static_cast<PhysicsActor*>(pBody); 
    433  
    434         // Only use the transform callback if the state is active 
    435         if (pShape->m_activationState != 0) 
    436         { 
    437             Math::Matrix4 transform; 
    438             for(int x = 0; x < 16; x++) 
    439             { 
    440                 transform.m_array[x] = _matrix[x]; 
    441             } 
    442             TransformEventData evenData(*pShape, transform); 
    443             pShape->onTransformEvent(evenData); 
    444         } 
     442        Math::Matrix4 transform; 
     443        _worldTrans.getOpenGLMatrix(transform.m_array); 
     444        TransformEventData evenData(*pShape, transform); 
     445        pShape->onTransformEvent(evenData); 
    445446    } 
    446447} 
     
    472473    return m_otherActor; 
    473474} 
    474 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    475 void  
    476 PhysicsActor::ZenMotionState::setWorldTransform(const btTransform &_worldTrans) 
    477 { 
    478  
    479 } 
     475 
    480476//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    481477Scripting::I_ObjectReference* 
     
    532528 
    533529//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     530int 
     531PhysicsActor::getActivationState() 
     532{ 
     533    m_activationState = m_pActor->getActivationState(); 
     534    return m_activationState; 
     535} 
     536 
     537//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    534538}   // namespace ZBullet 
    535539}   // namespace Zen 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZBullet/src/PhysicsActor.hpp

    r3347 r3349  
    9595    virtual void setSleepingThresholds(float _minLinearMotion, float _minAngularMotion); 
    9696    virtual void setActivationState(unsigned _state); 
     97    virtual int getActivationState(); 
    9798 
    9899    virtual void setAdvancedCollisionPrediction(bool _mode); 
     
    114115    /// @{ 
    115116private: 
    116     static void TransformCallback(const btRigidBody* _body, const Zen::Math::Real* _matrix); 
    117117    void applyForce(const Math::Vector3& _force); 
    118118    void applyImpulse(const Math::Vector3& _force, const Math::Vector3& _worldPos); 
     
    360360        { 
    361361        public: 
    362             ZenMotionState(); 
     362            ZenMotionState(void* _userData); 
    363363            virtual ~ZenMotionState(); 
    364364            virtual void getWorldTransform(btTransform& _worldTrans) const; 
    365365            //Bullet only calls the update of worldtransform for active objects 
    366366            virtual void setWorldTransform(const btTransform& _worldTrans); 
     367            void*               m_userPointer; 
    367368        }; 
    368369    /// @name Extended Member Variables 
     
    382383//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    383384inline 
    384 PhysicsActor::ZenMotionState::ZenMotionState() 
     385PhysicsActor::ZenMotionState::ZenMotionState(void* _userData) 
     386: m_userPointer(_userData) 
    385387{ 
    386388 
     
    392394 
    393395} 
     396 
    394397//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    395398inline 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZNewton/src/PhysicsActor.cpp

    r3347 r3349  
    643643 
    644644//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     645int 
     646PhysicsActor::getActivationState() 
     647{ 
     648    m_activationState = NewtonBodyGetSleepingState(m_pActor); 
     649    return m_activationState; 
     650} 
     651 
     652 
     653//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    645654}   // namespace ZNewton 
    646655}   // namespace Zen 
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZNewton/src/PhysicsActor.hpp

    r3347 r3349  
    9393    virtual void setSleepingThresholds(float _minLinearMotion, float _minAngularMotion); 
    9494    void setActivationState(unsigned _state); 
     95    virtual int getActivationState(); 
    9596 
    9697    virtual void setAdvancedCollisionPrediction(bool _mode);