Changeset 1724


Ignore:
Timestamp:
Aug 12, 2012, 11:07:23 PM (11 years ago)
Author:
touky
Message:

So Character Controller works with a lazy camera logic.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/camera.cpp

    r1442 r1724  
    7373    return m_target;
    7474}
     75vec3 Camera::GetPosition()
     76{
     77    return m_position;
     78}
    7579
    7680mat4 const &Camera::GetViewMatrix()
  • trunk/src/camera.h

    r1375 r1724  
    3737    void SetTarget(vec3 const &pos);
    3838    vec3 GetTarget();
     39    vec3 GetPosition();
    3940
    4041    mat4 const &GetViewMatrix();
  • trunk/test/BtPhysTest.cpp

    r1722 r1724  
    5252#define USE_WALL                1
    5353#define USE_PLATFORM    1
    54 #define USE_ROPE                0
    55 #define USE_BODIES              0
     54#define USE_ROPE                1
     55#define USE_BODIES              1
    5656#define USE_ROTATION    0
    5757#define USE_CHARACTER   1
     
    7171
    7272        m_simulation = new Simulation();
     73        m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f));
    7374        m_simulation->Init();
    7475        vec3 NewGravity = vec3(.0f, -10.0f, .0f);
     
    110111        {
    111112                quat NewRotation = quat::fromeuler_xyz(5.f, 0.f, 0.f);
    112                 vec3 NewPosition = pos_offset + vec3(5.0f, -20.0f, -15.0f);
     113                vec3 NewPosition = pos_offset + vec3(5.0f, -25.0f, -15.0f);
    113114
    114115                PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
     
    128129        {
    129130                quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
    130                 vec3 NewPosition = pos_offset + vec3(.0f, 40.0f, .0f);
     131                vec3 NewPosition = pos_offset + vec3(.0f, 20.0f, .0f);
    131132
    132133                PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2);
     
    410411                {
    411412                        PhysicsObject* PhysObj = m_character_list[i];
     413                        EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter();
     414
     415                        int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
     416                        int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
     417
     418                        Character->SetMovementForFrame(vec3((float)VMovement * seconds * 4.f, .0f, (float)HMovement * seconds * 4.f));
     419                }
     420        }
     421
     422        if (USE_CHARACTER)
     423        {
     424                PhysObjBarycenter = vec3(.0f);
     425                factor = .0f;
     426
     427                for (int i = 0; i < m_character_list.Count(); i++)
     428                {
     429                        PhysicsObject* PhysObj = m_character_list[i];
    412430                        mat4 GroundMat = PhysObj->GetTransform();
    413431
     
    418436                PhysObjBarycenter /= factor;
    419437
    420                 m_camera->SetTarget(PhysObjBarycenter);
    421                 m_camera->SetPosition(PhysObjBarycenter + vec3(-80.0f, 80.0f, .0f));
     438                m_camera->SetTarget(m_camera->GetTarget() + (seconds / (seconds + 0.18f)) * (PhysObjBarycenter - m_camera->GetTarget()));
     439                vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 20.0f, .0f);
     440                m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 5.0f);
    422441        }
    423442        else
  • trunk/test/PhysicObject.h

    r1722 r1724  
    4141                {
    4242                        m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]");
    43                         //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]");
    44 
    4543                        vec3 BoxSize = vec3(20.f, 1.f, 20.f);
    4644                        m_physics.SetCollisionChannel(0, 0xFF);
     
    5452                {
    5553                        m_is_character = true;
    56                         m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]");
    57                         //m_mesh.Compile("[sc#fff scb#fff ac1 2 2 2 0 0]");
    58                         vec3 BoxSize = vec3(2.f, 2.f, 2.f);
     54                        //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]");
     55                        m_mesh.Compile(
     56                                "[sc#000 scb#000"
     57                                //"[sc#aaa scb#aaa"
     58                                "[ad8 2 0 rx180 ty-1]"
     59                                "[asph8 .5 .5 .5 ty1]"
     60                                "[ac32 2 .5 .5 0 0]"
     61                                "[asph6 .1 .1 .1 ty.9 tx.5 tz.15]"
     62                                "[asph6 .1 .1 .1 ty.9 tx.5 tz-.15]"
     63                                "[asph8 .05 .5 .05 ty.6 tz.5]"
     64                                "[asph8 .05 .5 .05 ty.6 tz-.5]"
     65                                "]"
     66                                "[sc#fd0 scb#fd0"
     67                                "[ac8 .4 .1 0 0 0 ty.25 rz-90 ty.7 tx.5]"
     68                                "]"
     69                                "["
     70                                "[sc#fff scb#fff"
     71                                "[ad8 2 0 rx180 ty-1]"
     72                                "[asph8 .5 .5 .5 ty1]"
     73                                "[ac32 1.9 .5 .5 0 0]"
     74                                "]"
     75                                " ty-.1 tx.05]"
     76                                );
     77                        vec3 BoxSize = vec3(.5f, 2.f, .5f);
    5978                        m_character.SetCollisionChannel(0, 0xFF);
    6079                        m_character.SetShapeToCapsule(BoxSize.x, BoxSize.y);
     
    89108                int ConeLimit = MeshRand.Count();
    90109
    91                 MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
    92                 MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
    93                 MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
    94                 MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
    95                 MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
    96                 MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]";
     110                MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
     111                MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
     112                MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
     113                MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
     114                MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
     115                MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]";
    97116
    98117                int CylLimit = MeshRand.Count();
    99118
    100                 MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
    101                 MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
    102                 MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
    103                 MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
    104                 MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
    105                 MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]";
     119                MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
     120                MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
     121                MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
     122                MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
     123                MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
     124                MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]";
    106125
    107126                int CapsLimit = MeshRand.Count();
  • trunk/test/Physics/EasyPhysics.cpp

    r1722 r1724  
    308308}
    309309
     310//Set movement for this frame
     311void EasyCharacterController::SetMovementForFrame(vec3 &MoveQuantity)
     312{
     313        m_character->setWalkDirection(LOL2BT_VEC3(MoveQuantity));
     314}
     315
     316
    310317//-------------------------------------------------------------------------
    311318//EASY_CONSTRAINT
  • trunk/test/Physics/EasyPhysics.h

    r1722 r1724  
    143143        virtual void AddToSimulation(class Simulation* current_simulation);
    144144        virtual void RemoveFromSimulation(class Simulation* current_simulation);
     145        virtual void SetMovementForFrame(vec3 &MoveQuantity);
    145146
    146147protected:
  • trunk/test/Physics/LolPhysics.h

    r1698 r1724  
    4646        {
    4747                // Build the broadphase
    48                 m_broadphase = new btDbvtBroadphase();
     48                if (1)
     49                {
     50                        m_Sweep_broadphase = new btAxisSweep3(LOL2BT_VEC3(m_world_min), LOL2BT_VEC3(m_world_max));
     51                        m_Sweep_broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
     52                        m_broadphase = m_Sweep_broadphase;
     53                }
     54                else
     55                        m_broadphase = new btDbvtBroadphase();
    4956 
    5057                // Set up the collision configuration and dispatcher
     
    99106        }
    100107
     108        void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax)
     109        {
     110        }
     111
    101112        void CustomSetTimestep(float NewTimestep) { }
    102113
    103114        //broadphase
    104115        btBroadphaseInterface*                                  m_broadphase;
     116        btAxisSweep3*                                                   m_Sweep_broadphase;
    105117        // Set up the collision configuration and dispatc
    106118        btDefaultCollisionConfiguration*                m_collision_configuration;
     
    120132        void CustomSetContinuousDetection(bool ShouldUseCCD) { }
    121133        void CustomSetGravity(vec3 &NewGravity) { }
     134        void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax) { }
    122135        void CustomSetTimestep(float NewTimestep) { }
    123136
     
    141154                m_gravity = NewGravity;
    142155                CustomSetGravity(NewGravity);
     156        }
     157
     158        //Sets the simulation gravity.
     159        void SetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax)
     160        {
     161                m_world_min = NewWorldMin;
     162                m_world_max = NewWorldMax;
     163                CustomSetWorldLimit(NewWorldMin, NewWorldMax);
    143164        }
    144165
     
    173194        bool                                                                    m_using_CCD;
    174195        vec3                                                                    m_gravity;
     196        vec3                                                                    m_world_min;
     197        vec3                                                                    m_world_max;
    175198};
    176199
Note: See TracChangeset for help on using the changeset viewer.