Ignore:
Timestamp:
Aug 17, 2012, 7:41:36 PM (8 years ago)
Author:
touky
Message:

Added Attachment/base logic with working attachment with EasyCharacterController.
Added RayCastResult & a naïve integration for EasyCharacterController.
Enjoy !

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Physics/Src/EasyCharacterController.cpp

    r1749 r1768  
    3737
    3838//Return correct Ghost Object
    39 btGhostObject* EasyCharacterController::GetGhostObject()
     39btGhostObject* EasyCharacterController::GetGhostObjectInstance()
    4040{
    4141        return new btPairCachingGhostObject();
     
    6464                m_character = new btKinematicCharacterController(m_pair_caching_object, m_convex_shape, m_step_height, m_up_axis);
    6565                dynamics_world->addAction(m_character);
     66                Ticker::Ref(this);
    6667        }
    6768}
     
    7677        {
    7778                if (m_character)
     79                {
    7880                        dynamics_world->removeAction(m_character);
     81                        Ticker::Unref(this);
     82                }
    7983        }
    8084}
     
    8387void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity)
    8488{
    85         m_character->setWalkDirection(LOL2BT_VEC3(MoveQuantity));
     89        m_frame_cached_movement = MoveQuantity;
     90}
     91
     92//-------------------------------------------------------------------------
     93//Base Location/Rotation setup
     94//--
     95void EasyCharacterController::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
     96{
     97        if (m_base_is_updating)
     98        {
     99                m_base_cached_movement = base_location - m_local_to_world.v3.xyz;
     100                m_local_to_world = lol::mat4::translate(m_local_to_world.v3.xyz) * lol::mat4(base_rotation);
     101                if (m_ghost_object)
     102                        m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(LOL2BT_UNIT * m_local_to_world.v3.xyz)));
     103        }
     104        else
     105                EasyPhysic::SetTransform(base_location, base_rotation);
     106}
     107
     108//Internal callback when Base transform has changed.
     109void EasyCharacterController::BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix)
     110{
     111        m_base_is_updating = true;
     112        EasyPhysic::BaseTransformChanged(PreviousMatrix, NewMatrix);
     113        m_base_is_updating = false;
     114}
     115
     116//Physic Tick
     117void EasyCharacterController::TickGame(float seconds)
     118{
     119        Entity::TickGame(seconds);
     120
     121        m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * /*0.1f **/ (m_base_cached_movement + m_frame_cached_movement)) / seconds, seconds);
     122        //m_character->setWalkDirection();
    86123}
    87124
Note: See TracChangeset for help on using the changeset viewer.