Ignore:
Timestamp:
Apr 29, 2012, 8:41:43 PM (8 years ago)
Author:
touky
Message:

Added GetButtonState() in Input class.
Added Escape button in to quit Orbital.
Added Camera control with some little damping sweetness in Camera logic in main Tick.
First Commit \o/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1304 r1308  
    9292                          vec3(0, 1, 0));
    9393
    94     m_angle = 0;
     94        m_auto_cam_timer = 0.0f;
     95
     96        m_horizontal_angle = 0;
     97        m_vertical_angle = 0;
     98        m_roll_angle = 0;
     99
     100    m_horizontal_angle_speed = 0.0f;
     101    m_vertical_angle_speed = 0.0f;
     102    m_roll_angle_speed = 0.0f;
    95103
    96104    m_ready = false;
     
    104112    WorldEntity::TickGame(deltams);
    105113
    106     m_angle += deltams / 50.0f;
    107 
    108     mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
     114        //TEMP : Convert DT to seconds
     115        deltams /= 1000.0f;
     116
     117        if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
     118        Ticker::Shutdown();
     119
     120        if (m_auto_cam_timer > 0.0f)
     121                m_auto_cam_timer -= deltams;
     122
     123        //Doing the query with actual values, cause I want to stay SDL-free for now.
     124        int HMovement = Input::GetButtonState(276 /*SDLK_LEFT*/) - Input::GetButtonState(275 /*SDLK_RIGHT*/);
     125        int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
     126        int RMovement = Input::GetButtonState(256 /*SDLK_KP0*/) - Input::GetButtonState(305 /*SDLK_RCTRL*/);
     127
     128    float new_horizontal_angle_speed = 0.0f;
     129    float new_vertical_angle_speed = 0.0f;
     130    float new_roll_angle_speed = 0.0f;
     131
     132        if (HMovement != 0 || VMovement != 0 || RMovement != 0)
     133        {
     134                new_horizontal_angle_speed = ((float)HMovement) * 50.0f;
     135                new_vertical_angle_speed = ((float)VMovement) * 50.0f;
     136                new_roll_angle_speed = ((float)RMovement) * 50.0f;
     137                m_auto_cam_timer = 2.0f;
     138        }
     139        else if (m_auto_cam_timer <= 0.0f)
     140        {
     141                new_horizontal_angle_speed = 40.0f;
     142                new_vertical_angle_speed = max<float>(min<float>(-m_vertical_angle, 20.0f), -20.0f);
     143                new_roll_angle_speed = max<float>(min<float>(-m_roll_angle, 40.0f), -40.0f);
     144        }
     145
     146        m_horizontal_angle_speed += (new_horizontal_angle_speed - m_horizontal_angle_speed) * (deltams / (deltams + 0.3f));
     147        m_vertical_angle_speed += (new_vertical_angle_speed - m_vertical_angle_speed) * (deltams / (deltams + 0.3f));
     148        m_roll_angle_speed += (new_roll_angle_speed - m_roll_angle_speed) * (deltams / (deltams + 0.3f));
     149
     150        m_horizontal_angle += m_horizontal_angle_speed * deltams;
     151    m_vertical_angle += new_vertical_angle_speed * deltams;
     152    m_roll_angle += new_roll_angle_speed * deltams;
     153
     154        if (m_horizontal_angle > 180.0f)
     155                m_horizontal_angle -= 360.0f;
     156        else if (m_horizontal_angle < -180.0f)
     157                m_horizontal_angle += 360.0f;
     158        if (m_vertical_angle > 180.0f)
     159                m_vertical_angle -= 360.0f;
     160        else if (m_vertical_angle < -180.0f)
     161                m_vertical_angle += 360.0f;
     162        if (m_roll_angle > 180.0f)
     163                m_roll_angle -= 360.0f;
     164        else if (m_roll_angle < -180.0f)
     165                m_roll_angle += 360.0f;
     166
     167    mat4 animH = mat4::rotate(m_horizontal_angle, vec3(0, 1, 0));
     168    mat4 animV = mat4::rotate(m_vertical_angle, vec3(1, 0, 0));
     169    mat4 animR = mat4::rotate(m_roll_angle, vec3(0, 0, 1));
    109170    mat4 model = mat4::translate(vec3(0));
    110171
    111     m_modelview = m_camera->GetViewMatrix() * model * anim;
     172    m_modelview = m_camera->GetViewMatrix() * model * animV * animR * animH;
    112173    m_proj = m_camera->GetProjMatrix();
    113174    m_normalmat = transpose(inverse(mat3(m_modelview)));
Note: See TracChangeset for help on using the changeset viewer.