Changeset 1768


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

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

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/entity.h

    r1325 r1768  
    4646        GAMEGROUP_BEFORE = 0,
    4747        GAMEGROUP_DEFAULT,
    48         GAMEGROUP_AFTER,
    49         // Must be the last element
     48                GAMEGROUP_AFTER,
     49                GAMEGROUP_AFTER_POST,
     50
     51                // Must be the last element
    5052        GAMEGROUP_END
    5153    }
  • trunk/src/input/input.h

    r1752 r1768  
    1717#define __LOL_INPUT_INPUT_H__
    1818
     19#include <cstring>
    1920#include "lol/math/vector.h"
    2021#include "input/stick.h"
     
    109110        ActionSetting(int NewActionId)
    110111        {
    111                 //memset(this, 0, sizeof(ActionSetting));
     112                memset(this, 0, sizeof(ActionSetting));
    112113                ActionId = NewActionId;
    113114        }
     
    123124        ButtonSetting(int NewRawButtonId)
    124125        {
    125                 //memset(this, 0, sizeof(ButtonSetting));
     126                memset(this, 0, sizeof(ButtonSetting));
    126127                RawButtonId = NewRawButtonId;
    127128        }
  • trunk/test/BtPhysTest.cpp

    r1764 r1768  
    5252#define USE_WALL                1
    5353#define USE_PLATFORM    1
    54 #define USE_ROPE                1
    55 #define USE_BODIES              1
     54#define USE_ROPE                0
     55#define USE_BODIES              0
    5656#define USE_ROTATION    0
    5757#define USE_CHARACTER   1
     
    5959BtPhysTest::BtPhysTest(bool editor)
    6060{
     61        m_loop_value = .0f;
     62
    6163    /* Create a camera that matches the settings of XNA BtPhysTest */
    6264    m_camera = new Camera(vec3(0.f, 600.f, 0.f),
     
    108110        }
    109111
     112        PhysicsObject* BasePhyobj = NULL;
    110113        if (USE_PLATFORM)
    111114        {
     
    118121                Ticker::Ref(NewPhyobj);
    119122
    120                 NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f);
     123                NewPosition = pos_offset + vec3(-15.0f, -25.0f, 5.0f);
    121124
    122125                NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
    123                 PhysicsObject* BasePhyobj = NewPhyobj;
     126                BasePhyobj = NewPhyobj;
    124127
    125128                m_platform_list << NewPhyobj;
     
    127130
    128131                NewRotation = quat::fromeuler_xyz(0.f, 0.f, 90.f);
    129                 NewPosition = pos_offset + vec3(-25.0f, -25.0f, 5.0f);
     132                NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f);
    130133
    131134                NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
     
    135138                Ticker::Ref(NewPhyobj);
    136139
    137                 NewPosition += vec3(-0.0f, .0f, .0f);
    138                 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
    139 
    140                 NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false);
    141                 m_platform_list << NewPhyobj;
    142                 Ticker::Ref(NewPhyobj);
    143 
    144                 NewPosition += vec3(-2.0f, .0f, .0f);
    145                 NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
    146 
    147                 NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false);
    148                 m_platform_list << NewPhyobj;
    149                 Ticker::Ref(NewPhyobj);
     140                //NewPosition += vec3(-0.0f, .0f, .0f);
     141                //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
     142
     143                //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false);
     144                //m_platform_list << NewPhyobj;
     145                //Ticker::Ref(NewPhyobj);
     146
     147                //NewPosition += vec3(-2.0f, .0f, .0f);
     148                //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
     149
     150                //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false);
     151                //m_platform_list << NewPhyobj;
     152                //Ticker::Ref(NewPhyobj);
    150153        }
    151154
     
    153156        {
    154157                quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
    155                 vec3 NewPosition = pos_offset + vec3(-15.0f, 20.0f, .0f);
     158                vec3 NewPosition = pos_offset + vec3(-15.0f, -10.0f, .0f);
    156159
    157160                PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2);
     
    159162                m_character_list << NewPhyobj;
    160163                Ticker::Ref(NewPhyobj);
     164
     165                //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true);
    161166        }
    162167
     
    281286                        else if (i == 1)
    282287                        {
    283                                 GroundMat = mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) *
    284                                                         mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f)));
     288                                GroundMat =
     289                                        mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) *
     290                                        mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f)));
    285291                                PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
    286292                        }
     
    294300                        PhysicsObject* PhysObj = m_character_list[i];
    295301                        EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter();
     302                        mat4 CtlrMx = Character->GetTransform();
    296303
    297304                        int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
    298305                        int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
    299306                        int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);
    300 
    301                         Character->SetMovementForFrame(vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f));
     307                        vec3 CharMove = vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f);
     308
     309                        Character->SetMovementForFrame(CharMove);
     310
     311                        RayCastResult HitResult;
     312                        if (m_simulation->RayHits(HitResult, ERT_Closest, Character->GetTransform().v3.xyz, (Character->GetTransform().v3.xyz + vec3(.0f, -1.f, .0f)), Character))
     313                                Character->AttachTo(HitResult.m_collider_list[0], true, true);
     314                        else
     315                                Character->AttachTo(NULL);
    302316                }
    303317        }
     
    320334
    321335                m_camera->SetTarget(m_camera->GetTarget() + (seconds / (seconds + 0.18f)) * (PhysObjBarycenter - m_camera->GetTarget()));
    322                 vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 20.0f, .0f);
    323                 m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 5.0f);
     336                vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 5.0f, .0f);
     337                m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 20.0f);
    324338        }
    325339        else
  • trunk/test/PhysicObject.h

    r1764 r1768  
    220220        }
    221221
    222         void SetLinearVelocity(const lol::vec3& NewVelocity, bool bIsLocal=false)
    223         {
    224                 //if (m_is_character)
    225                 //      m_character->SetLinearVelocity(NewVelocity);
    226                 //else
    227                 //      m_physics->SetLinearVelocity(NewVelocity);
    228         }
    229 
    230222        lol::mat4 GetTransform()
    231223        {
  • trunk/test/Physics/Include/EasyCharacterController.h

    r1764 r1768  
    3030{
    3131
    32 class EasyCharacterController : public EasyPhysic
     32class EasyCharacterController : public EasyPhysic,
     33                                                                public Entity
    3334{
    3435
     
    3839        EasyCharacterController(WorldEntity* NewOwnerEntity) :
    3940                EasyPhysic(NewOwnerEntity),
    40                 m_character(NULL)
     41                m_pair_caching_object(NULL),
     42                m_character(NULL),
     43                m_step_height(.0f),
     44                m_base_is_updating(false),
     45                m_base_cached_movement(vec3(0.f)),
     46                m_frame_cached_movement(vec3(0.f))
    4147        {
     48                m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
    4249                m_up_axis = 1;
    4350        }
     
    5360        virtual void SetMovementForFrame(vec3 const &MoveQuantity);
    5461
     62        virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
     63protected:
     64        virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
     65public:
     66        virtual void TickGame(float seconds);
     67
    5568protected:
    5669
    57         virtual btGhostObject* GetGhostObject();
     70        virtual btGhostObject* GetGhostObjectInstance();
    5871
    5972        btPairCachingGhostObject*               m_pair_caching_object;
     
    6275        float                                                   m_step_height;
    6376        int                                                             m_up_axis;
     77        bool                                                    m_base_is_updating;
     78        vec3                                                    m_base_cached_movement;
     79        vec3                                                    m_frame_cached_movement;
    6480
    6581#else  // NO PHYSIC IMPLEMENTATION
  • trunk/test/Physics/Include/EasyPhysics.h

    r1764 r1768  
    3535
    3636        friend class EasyConstraint;
     37        friend class Simulation;
    3738
    3839#ifdef HAVE_PHYS_USE_BULLET
     
    4950
    5051        virtual bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); }
     52        virtual mat4 GetTransform();
    5153        virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
    52 private:
     54protected:
    5355        virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
    5456public:
     
    5860        virtual void AddToSimulation(class Simulation* current_simulation);
    5961        virtual void RemoveFromSimulation(class Simulation* current_simulation);
    60         virtual mat4 GetTransform();
    6162
    6263protected:
     
    6465        virtual void SetShapeTo(btCollisionShape* collision_shape);
    6566
    66         virtual btGhostObject* GetGhostObject();
     67        virtual btGhostObject* GetGhostObjectInstance();
    6768
    6869        btCollisionObject*                                                      m_collision_object;
     
    8990
    9091        virtual bool CanChangeCollisionChannel() { return true; }
     92        virtual mat4 GetTransform() { return mat4(1.0f); }
    9193        virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
    9294private:
     
    98100        virtual void AddToSimulation(class Simulation* current_simulation) { }
    99101        virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
    100         virtual mat4 GetTransform() { return mat4(1.0f); }
    101102
    102103        virtual void InitBodyToGhost() { }
     
    123124        virtual void AttachTo(EasyPhysic* NewBase, bool NewBaseLockLocation = true, bool NewBaseLockRotation = true)
    124125        {
    125                 if (NewBase == this || NewBase->m_base_physic == this)
     126                if (NewBase == this || (NewBase && NewBase->m_base_physic == this))
    126127                        return;
    127128
     
    138139                        m_base_lock_rotation = NewBaseLockRotation;
    139140                }
    140                 else
     141                else if (m_base_physic)
    141142                {
    142                         for (int i = 0; i < NewBase->m_based_physic_list.Count(); ++i)
    143                                 if (NewBase->m_based_physic_list[i] == this)
    144                                         NewBase->m_based_physic_list.Remove(i--);
     143                        for (int i = 0; i < m_base_physic->m_based_physic_list.Count(); ++i)
     144                                if (m_base_physic->m_based_physic_list[i] == this)
     145                                        m_base_physic->m_based_physic_list.Remove(i--);
    145146                        m_base_physic = NULL;
    146147                }
  • trunk/test/Physics/Include/LolBtPhysicsIntegration.h

    r1747 r1768  
    2020namespace lol
    2121{
     22        //Override Gamegroups names for Physic-useage
     23        //"_ENT_" means that this is a group for Entities that use EasyPhysic primitives.
     24        //"_EZP_" means that this is a group for EasyPhysic primitives.
     25#define GAMEGROUP_ENT_PLATFORM          GAMEGROUP_BEFORE
     26#define GAMEGROUP_ENT_MAIN                      GAMEGROUP_DEFAULT
     27#define GAMEGROUP_EZP_CHAR_CTRLR        GAMEGROUP_AFTER
     28#define GAMEGROUP_SIMULATION            GAMEGROUP_AFTER_POST
    2229
    2330#ifdef HAVE_PHYS_USE_BULLET
     
    3239#define BT2LOL_VEC3(ELEMENT)    (*(lol::vec3*)(&(ELEMENT)))
    3340
     41//Same as above with Unit taken into account
     42#define LOL2BTU_VEC3(ELEMENT)   btVector3((ELEMENT).x * LOL2BT_UNIT, (ELEMENT).y * LOL2BT_UNIT, (ELEMENT).z * LOL2BT_UNIT)
     43#define BT2LOLU_VEC3(ELEMENT)   (*(lol::vec3*)(&(ELEMENT))) * BT2LOL_UNIT
     44
    3445#define LOL2BT_QUAT(ELEMENT)    btQuaternion((ELEMENT).x, (ELEMENT).y, (ELEMENT).z, (ELEMENT).w)
    3546#define BT2LOL_QUAT(ELEMENT)    lol::quat((ELEMENT).getW(), BT2LOL_VEC3((ELEMENT).getAxis())
  • trunk/test/Physics/Include/LolPhysics.h

    r1758 r1768  
    1010
    1111#ifdef HAVE_PHYS_USE_BULLET
     12#include <cstring>
    1213#include <bullet/btBulletDynamicsCommon.h>
    1314#include <bullet/btBulletCollisionCommon.h>
     15#include <BulletDynamics/Character/btKinematicCharacterController.h>
    1416#include "LolBtPhysicsIntegration.h"
    1517#include "EasyPhysics.h"
     
    2224namespace phys
    2325{
     26
     27enum eRaycastType
     28{
     29        ERT_Closest,
     30        ERT_AllHit,
     31        ERT_AnyHit, //Will stop at the first hit. Hit data are supposed to be irrelevant
     32
     33        ERT_MAX
     34};
     35
     36struct RayCastResult
     37{
     38        RayCastResult(int CollisionFilterGroup=1, int CollisionFilterMask=(0xFF))
     39        {
     40                memset(this, 0, sizeof(RayCastResult));
     41
     42                m_collision_filter_group = CollisionFilterGroup;
     43                m_collision_filter_mask = CollisionFilterMask;
     44        }
     45        void Reset()
     46        {
     47                m_collider_list.Empty();
     48                m_hit_normal_list.Empty();
     49                m_hit_point_list.Empty();
     50                m_hit_fraction_list.Empty();
     51        }
     52
     53        Array<EasyPhysic*>              m_collider_list;
     54        Array<vec3>                             m_hit_normal_list;
     55        Array<vec3>                             m_hit_point_list;
     56        Array<float>                    m_hit_fraction_list;
     57
     58        short int                               m_collision_filter_group;
     59        short int                               m_collision_filter_mask;
     60        unsigned int                    m_flags; //???
     61};
    2462
    2563class Simulation : public Entity
     
    3472                m_timestep(1.f/60.f)
    3573        {
     74                m_gamegroup = GAMEGROUP_SIMULATION;
    3675        }
    3776        ~Simulation()
     
    80119        }
    81120
     121        //Reap-Off of the btKinematicClosestNotMeRayResultCallback
     122        class LolClosestNotMeRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
     123        {
     124        public:
     125                LolClosestNotMeRayResultCallback(btCollisionObject* Me, const btVector3& rayFromWorld, const btVector3& rayToWorld) :
     126                  btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld)
     127                {
     128                        m_me = Me;
     129                }
     130
     131                virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
     132                {
     133                        if (rayResult.m_collisionObject == m_me)
     134                                return 1.0;
     135
     136                        return ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
     137                }
     138        protected:
     139                btCollisionObject* m_me;
     140        };
     141
     142        //Will stop at the first hit. Hit data are supposed to be irrelevant
     143        class AnyHitRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
     144        {
     145        public:
     146                AnyHitRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld) :
     147                  btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld)
     148                {
     149                }
     150
     151                virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
     152                {
     153                        return .0f;
     154                }
     155        };
     156
     157        //Returns true when hitting something. If SourceCaster is set, it will be ignored by Raycast.
     158        bool RayHits(RayCastResult& HitResult, eRaycastType RaycastType, const vec3& RayFrom, const vec3& RayTo, EasyPhysic* SourceCaster=NULL)
     159        {
     160                bool bResult = false;
     161
     162                btCollisionWorld::RayResultCallback* BtRayResult = NULL;
     163                btCollisionWorld::ClosestRayResultCallback* BtRayResult_Closest;
     164                btCollisionWorld::AllHitsRayResultCallback* BtRayResult_AllHits;
     165
     166                switch (RaycastType)
     167                {
     168                        case ERT_Closest:
     169                        {
     170                                if (SourceCaster)
     171                                        BtRayResult_Closest = new LolClosestNotMeRayResultCallback(SourceCaster->m_collision_object, LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo));
     172                                else
     173                                        BtRayResult_Closest = new btCollisionWorld::ClosestRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo));
     174                                BtRayResult = BtRayResult_Closest;
     175                                break;
     176                        }
     177                        case ERT_AllHit:
     178                        {
     179                                BtRayResult_AllHits = new btCollisionWorld::AllHitsRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo));
     180                                BtRayResult = BtRayResult_AllHits;
     181                                break;
     182                        }
     183                        case ERT_AnyHit:
     184                        {
     185                                BtRayResult_Closest = new AnyHitRayResultCallback(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo));
     186                                BtRayResult = BtRayResult_Closest;
     187                                break;
     188                        }
     189                }
     190
     191                m_dynamics_world->rayTest(LOL2BTU_VEC3(RayFrom), LOL2BTU_VEC3(RayTo), *BtRayResult);
     192                if (BtRayResult->hasHit())
     193                {
     194                        bResult = true;
     195
     196                        switch (RaycastType)
     197                        {
     198                                case ERT_Closest:
     199                                {
     200                                        HitResult.m_collider_list               << (EasyPhysic*)BtRayResult_Closest->m_collisionObject->getUserPointer();
     201                                        HitResult.m_hit_normal_list             << BT2LOLU_VEC3(BtRayResult_Closest->m_hitNormalWorld);
     202                                        HitResult.m_hit_point_list              << BT2LOLU_VEC3(BtRayResult_Closest->m_hitPointWorld);
     203                                        HitResult.m_hit_fraction_list   << BtRayResult_Closest->m_closestHitFraction;
     204                                        break;
     205                                }
     206                                case ERT_AllHit:
     207                                {
     208                                        for (int i = 0; i < BtRayResult_AllHits->m_collisionObjects.size(); i++)
     209                                        {
     210                                                HitResult.m_collider_list               << (EasyPhysic*)BtRayResult_AllHits->m_collisionObjects[i]->getUserPointer();
     211                                                HitResult.m_hit_normal_list             << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitNormalWorld[i]);
     212                                                HitResult.m_hit_point_list              << BT2LOLU_VEC3(BtRayResult_AllHits->m_hitPointWorld[i]);
     213                                                HitResult.m_hit_fraction_list   << BtRayResult_AllHits->m_hitFractions[i];
     214                                        }
     215                                        break;
     216                                }
     217                        }
     218                }
     219
     220                delete BtRayResult;
     221
     222                return bResult;
     223        }
     224
     225
    82226        void Exit()
    83227        {
     
    129273        void Init() { }
    130274        void TickGame(float seconds) { }
     275        bool RayHits(RayCastResult& HitResult, eRaycastType RaycastType, const vec3& RayFrom, const vec3& RayTo, EasyPhysic* SourceCaster=NULL) { return false; }
    131276        void Exit() { }
    132277private:
  • 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
  • trunk/test/Physics/Src/EasyPhysics.cpp

    r1764 r1768  
    4141        m_collision_group(1),
    4242        m_collision_mask(1),
    43         m_owner_entity(NewOwnerEntity)
     43        m_owner_entity(NewOwnerEntity),
     44        m_base_physic(NULL)
    4445{
    4546}
     
    113114//Base Location/Rotation setup
    114115//--
     116
     117//Getter
     118mat4 EasyPhysic::GetTransform()
     119{
     120        m_local_to_world = lol::mat4(1.0f);
     121        if (m_rigid_body && m_motion_state)
     122        {
     123                btTransform CurTransform;
     124                m_motion_state->getWorldTransform(CurTransform);
     125                CurTransform.getOpenGLMatrix(&m_local_to_world[0][0]);
     126        }
     127        else if (m_collision_object)
     128                m_collision_object->getWorldTransform().getOpenGLMatrix(&m_local_to_world[0][0]);
     129        return m_local_to_world;
     130}
     131
     132//Setter
    115133void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
    116134{
     
    119137
    120138        if (m_ghost_object)
    121                 m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
     139                m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(LOL2BT_UNIT * base_location)));
    122140        else
    123141        {
    124142                if (m_motion_state)
    125                         m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
     143                        m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(LOL2BT_UNIT * base_location)));
    126144                else
    127                         m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
     145                        m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(LOL2BT_UNIT * base_location)));
    128146        }
    129147
    130148        for (int i = 0; i < m_based_physic_list.Count(); i++)
     149        {
    131150                if (m_based_physic_list[i])
    132151                        m_based_physic_list[i]->BaseTransformChanged(PreviousMatrix, m_local_to_world);
    133152                else
    134153                        m_based_physic_list.Remove(i--);
     154        }
    135155}
    136156
     
    197217
    198218//Return correct Ghost Object
    199 btGhostObject* EasyPhysic::GetGhostObject()
     219btGhostObject* EasyPhysic::GetGhostObjectInstance()
    200220{
    201221        return new btGhostObject();
     
    208228                delete m_collision_object;
    209229
    210         m_ghost_object = GetGhostObject();
     230        m_ghost_object = GetGhostObjectInstance();
    211231        m_ghost_object->setCollisionShape(m_collision_shape);
    212232        m_collision_object = m_ghost_object;
     
    295315}
    296316
    297 //-------------------------------------------------------------------------
    298 //Getter functons
    299 //--
    300 
    301 mat4 EasyPhysic::GetTransform()
    302 {
    303         m_local_to_world = lol::mat4(1.0f);
    304         if (m_rigid_body && m_motion_state)
    305         {
    306                 btTransform CurTransform;
    307                 m_motion_state->getWorldTransform(CurTransform);
    308                 CurTransform.getOpenGLMatrix(&m_local_to_world[0][0]);
    309         }
    310         else if (m_collision_object)
    311                 m_collision_object->getWorldTransform().getOpenGLMatrix(&m_local_to_world[0][0]);
    312         return m_local_to_world;
    313 }
    314 
    315317//Set Local Inertia
    316318void EasyPhysic::SetLocalInertia(float mass)
Note: See TracChangeset for help on using the changeset viewer.