Ignore:
Timestamp:
Aug 12, 2012, 5:23:25 PM (9 years ago)
Author:
touky
Message:

LocalInertia error FIX.
Character integration better but still not working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Physics/EasyPhysics.cpp

    r1708 r1722  
    7676{
    7777        vec3 new_box_size = box_size * LOL2BT_UNIT * LOL2BT_SIZE;
    78         SetShapeTo(new btBoxShape(LOL2BT_VEC3(new_box_size)));
     78        m_convex_shape = new btBoxShape(LOL2BT_VEC3(new_box_size));
     79        SetShapeTo(m_convex_shape);
    7980}
    8081
    8182void EasyPhysic::SetShapeToSphere(float radius)
    8283{
    83         SetShapeTo(new btSphereShape(radius * LOL2BT_UNIT * LOL2BT_SIZE));
     84        m_convex_shape = new btSphereShape(radius * LOL2BT_UNIT * LOL2BT_SIZE);
     85        SetShapeTo(m_convex_shape);
    8486}
    8587
    8688void EasyPhysic::SetShapeToCone(float radius, float height)
    8789{
    88         SetShapeTo(new btConeShape(     radius * LOL2BT_UNIT,
    89                                                                 height * LOL2BT_UNIT));
     90        m_convex_shape = new btConeShape(       radius * LOL2BT_UNIT,
     91                                                                                height * LOL2BT_UNIT);
     92        SetShapeTo(m_convex_shape);
    9093}
    9194
     
    9497        vec3 new_cyl_size = cyl_size * LOL2BT_UNIT;
    9598        new_cyl_size.y *= LOL2BT_SIZE;
    96         SetShapeTo(new btCylinderShape(LOL2BT_VEC3(new_cyl_size)));
     99        m_convex_shape = new btCylinderShape(LOL2BT_VEC3(new_cyl_size));
     100        SetShapeTo(m_convex_shape);
    97101}
    98102
    99103void EasyPhysic::SetShapeToCapsule(float radius, float height)
    100104{
    101         SetShapeTo(new btCapsuleShape(  radius * LOL2BT_UNIT * LOL2BT_SIZE,
    102                                                                         height * LOL2BT_UNIT * LOL2BT_SIZE));
     105        m_convex_shape = new btCapsuleShape(radius * LOL2BT_UNIT * LOL2BT_SIZE,
     106                                                                                height * LOL2BT_UNIT * LOL2BT_SIZE);
     107        SetShapeTo(m_convex_shape);
    103108}
    104109
     
    108113void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
    109114{
     115        m_local_to_world = lol::mat4::translate(base_location) * mat4(base_rotation);
     116
    110117        if (m_ghost_object)
    111118                m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
     
    151158        m_collision_object = m_rigid_body;
    152159
    153         if (m_mass == .0f && SetToKinematic)
    154         {
    155                 m_rigid_body->setActivationState(DISABLE_DEACTIVATION);
    156                 m_rigid_body->setCollisionFlags(m_rigid_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
    157         }
     160        if (m_mass == .0f)
     161        {
     162                if (SetToKinematic)
     163                {
     164                        m_rigid_body->setActivationState(DISABLE_DEACTIVATION);
     165                        m_rigid_body->setCollisionFlags(m_rigid_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
     166                }
     167        }
     168        else
     169                SetMass(m_mass);
     170}
     171
     172//Return correct Ghost Object
     173btGhostObject* EasyPhysic::GetGhostObject()
     174{
     175        return new btGhostObject();
    158176}
    159177
     
    164182                delete m_collision_object;
    165183
    166         m_ghost_object = new btGhostObject();
     184        m_ghost_object = GetGhostObject();
    167185        m_ghost_object->setCollisionShape(m_collision_shape);
    168186        m_collision_object = m_ghost_object;
    169187
    170         SetTransform(vec3(.0f));
     188        SetTransform(m_local_to_world.v3.xyz, lol::quat(m_local_to_world));
    171189
    172190        m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags());
    173         //btCollisionObject::CF_CHARACTER_OBJECT
    174191}
    175192
     
    206223                if (m_rigid_body)
    207224                        dynamics_world->removeRigidBody(m_rigid_body);
    208                 else
     225                else if (m_collision_object)
    209226                        dynamics_world->removeCollisionObject(m_collision_object);
    210227        }
     
    242259//--
    243260
    244 void EasyCharacterController::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
    245 {
    246 
    247 }
    248 void EasyCharacterController::SetMass(float mass)
    249 {
    250 
    251 }
     261//Deactivated for Character controller
    252262void EasyCharacterController::InitBodyToRigid(bool ZeroMassIsKinematic)
    253263{
    254 
    255 }
     264}
     265
     266//Return correct Ghost Object
     267btGhostObject* EasyCharacterController::GetGhostObject()
     268{
     269        return new btPairCachingGhostObject();
     270}
     271
     272//Init to Pair caching ghost object, since Character uses that one.
    256273void EasyCharacterController::InitBodyToGhost()
    257274{
    258         //btCollisionObject::CF_CHARACTER_OBJECT
    259 }
     275        EasyPhysic::InitBodyToGhost();
     276
     277        m_pair_caching_object = (btPairCachingGhostObject*)m_ghost_object;
     278        m_ghost_object->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT | m_ghost_object->getCollisionFlags());
     279}
     280
     281//Add Physic object to the simulation
    260282void EasyCharacterController::AddToSimulation(class Simulation* current_simulation)
    261283{
    262 
    263 }
     284        EasyPhysic::AddToSimulation(current_simulation);
     285
     286        btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
     287        if (dynamics_world)
     288        {
     289                if (m_character)
     290                        delete m_character;
     291
     292                m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis);
     293                dynamics_world->addAction(m_character);
     294        }
     295}
     296
     297//Remove Physic object to the simulation
    264298void EasyCharacterController::RemoveFromSimulation(class Simulation* current_simulation)
    265299{
    266 
    267 }
    268 mat4 EasyCharacterController::GetTransform()
    269 {
    270         return mat4(1.f);
     300        EasyPhysic::RemoveFromSimulation(current_simulation);
     301
     302        btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
     303        if (dynamics_world)
     304        {
     305                if (m_character)
     306                        dynamics_world->removeAction(m_character);
     307        }
    271308}
    272309
Note: See TracChangeset for help on using the changeset viewer.