Show
Ignore:
Timestamp:
02/01/10 15:59:41 (6 months ago)
Author:
Azaezel
Message:

initialization and static setting expansion, ZenMotionState? becomes MotionState?, fixed method definition order for CustomMaterialCombinerCallback? in PhysicsService?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/branches/0185_GEN_PHYSICS_REFACTOR_2/ZBullet/src/PhysicsActor.cpp

    r3349 r3352  
    5959    m_name = ""; 
    6060    m_MotionState = NULL; 
     61    m_mass = 0.0f; 
    6162} 
    6263 
     
    7980{ 
    8081    m_CollisionShape = _pCollisionShape; 
     82    m_mass = 0.0f; 
    8183    attachBody(m_CollisionShape); 
    8284} 
     
    126128    //   TreeCollision (not impl yet), UserMesh (heightfield) 
    127129 
    128  
    129  
    130     m_pActor = NewtonCreateBody(dynamic_cast<PhysicsZone*>(m_pZone.get())->getZonePtr(), dynamic_cast<CollisionShape*>(_collision.get())->getShapePtr()); 
    131     NewtonReleaseCollision(dynamic_cast<PhysicsZone*>(m_pZone.get())->getZonePtr(), dynamic_cast<CollisionShape*>(_collision.get())->getShapePtr()); 
    132  
    133130    // set the transform call back function 
    134     m_MotionState = new PhysicsActor::ZenMotionState(this); 
    135  
     131    m_MotionState = new MotionState(this); 
     132    //mass, motionstate, collisionshape, and inertia are all necessary prior to creation for bullet 
     133    btRigidBody::btRigidBodyConstructionInfo rbInfo(m_mass,m_MotionState,dynamic_cast<CollisionShape*>(_collision.get())->getShapePtr(),btVector3(0.0f,0.0f,0.0f)); 
     134 
     135    m_pActor = new btRigidBody(rbInfo); 
    136136    m_pActor->setUserPointer(this); 
    137  
     137    m_pActor->setCollisionFlags(m_pActor->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); 
    138138    return true; 
    139139} 
     
    204204PhysicsActor::getMass() 
    205205{ 
    206     Zen::Math::Real mass; 
    207     Zen::Math::Real Ixx; 
    208     Zen::Math::Real Iyy; 
    209     Zen::Math::Real Izz; 
    210     btRigidBodyGetMassMatrix(m_pActor, &mass, &Ixx, &Iyy, &Izz); 
    211  
    212     return mass; 
    213 } 
    214  
    215 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     206    return m_mass; 
     207} 
     208 
     209//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     210//this gets a bit arcane since we're dealing with bit-flags. see http://www.cprogramming.com/tutorial/bitwise_operators.html for reference - bjr 
    216211void  
    217212PhysicsActor::SetStatic(bool _isStatic = false) 
     
    221216        { 
    222217                setMass(0); 
     218      m_pActor->setCollisionFlags(m_pActor->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); 
    223219        } 
    224220        else 
     221   { 
    225222                setMass(m_mass); 
     223      m_pActor->setCollisionFlags(m_pActor->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT); 
     224   } 
    226225} 
    227226 
     
    245244PhysicsActor::setMass(float _mass) 
    246245{ 
    247     // set the mass to zero to make this a static body. 
    248     // set the mass to any positive value to make this a dynamic body. 
    249     Zen::Math::Real Ixx = _mass * m_scaleX * m_scaleX; 
    250     Zen::Math::Real Iyy = _mass * m_scaleY * m_scaleY; 
    251     Zen::Math::Real Izz = _mass * m_scaleZ * m_scaleZ; 
    252     btRigidBodySetMassMatrix(m_pActor, _mass, Ixx, Iyy, Izz); 
     246    m_mass = _mass; 
    253247} 
    254248 
     
    425419//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    426420void 
    427 PhysicsActor::ZenMotionState::getWorldTransform(btTransform& _worldTrans) const 
    428 { 
    429  
    430 } 
    431  
    432 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
    433 void 
    434 PhysicsActor::ZenMotionState::setWorldTransform(const btTransform& _worldTrans) 
     421PhysicsActor::MotionState::getWorldTransform(btTransform& _worldTrans) const 
     422{ 
     423//don't belive we really need anything here since were updating visuals on the set end... might need to crosscheck later -bjr 
     424} 
     425 
     426//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 
     427void 
     428PhysicsActor::MotionState::setWorldTransform(const btTransform& _worldTrans) 
    435429{ 
    436430    if (m_userPointer == NULL) return;