Ignore:
Timestamp:
Apr 29, 2012, 11:55:32 PM (9 years ago)
Author:
sam
Message:

core: tick methods now use seconds, like any sane system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1308 r1310  
    9292                          vec3(0, 1, 0));
    9393
    94         m_auto_cam_timer = 0.0f;
    95 
    96         m_horizontal_angle = 0;
    97         m_vertical_angle = 0;
    98         m_roll_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;
    9999
    100100    m_horizontal_angle_speed = 0.0f;
     
    108108}
    109109
    110 void Orbital::TickGame(float deltams)
    111 {
    112     WorldEntity::TickGame(deltams);
    113 
    114         //TEMP : Convert DT to seconds
    115         deltams /= 1000.0f;
    116 
    117         if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
     110void Orbital::TickGame(float seconds)
     111{
     112    WorldEntity::TickGame(seconds);
     113
     114    if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
    118115        Ticker::Shutdown();
    119116
    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*/);
     117    if (m_auto_cam_timer > 0.0f)
     118        m_auto_cam_timer -= seconds;
     119
     120    //Doing the query with actual values, cause I want to stay SDL-free for now.
     121    int HMovement = Input::GetButtonState(276 /*SDLK_LEFT*/) - Input::GetButtonState(275 /*SDLK_RIGHT*/);
     122    int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
     123    int RMovement = Input::GetButtonState(256 /*SDLK_KP0*/) - Input::GetButtonState(305 /*SDLK_RCTRL*/);
    127124
    128125    float new_horizontal_angle_speed = 0.0f;
     
    130127    float new_roll_angle_speed = 0.0f;
    131128
    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;
     129    if (HMovement != 0 || VMovement != 0 || RMovement != 0)
     130    {
     131        new_horizontal_angle_speed = ((float)HMovement) * 50.0f;
     132        new_vertical_angle_speed = ((float)VMovement) * 50.0f;
     133        new_roll_angle_speed = ((float)RMovement) * 50.0f;
     134        m_auto_cam_timer = 2.0f;
     135    }
     136    else if (m_auto_cam_timer <= 0.0f)
     137    {
     138        new_horizontal_angle_speed = 40.0f;
     139        new_vertical_angle_speed = max<float>(min<float>(-m_vertical_angle, 20.0f), -20.0f);
     140        new_roll_angle_speed = max<float>(min<float>(-m_roll_angle, 40.0f), -40.0f);
     141    }
     142
     143    m_horizontal_angle_speed += (new_horizontal_angle_speed - m_horizontal_angle_speed) * (seconds / (seconds + 0.3f));
     144    m_vertical_angle_speed += (new_vertical_angle_speed - m_vertical_angle_speed) * (seconds / (seconds + 0.3f));
     145    m_roll_angle_speed += (new_roll_angle_speed - m_roll_angle_speed) * (seconds / (seconds + 0.3f));
     146
     147    m_horizontal_angle += m_horizontal_angle_speed * seconds;
     148    m_vertical_angle += new_vertical_angle_speed * seconds;
     149    m_roll_angle += new_roll_angle_speed * seconds;
     150
     151    if (m_horizontal_angle > 180.0f)
     152        m_horizontal_angle -= 360.0f;
     153    else if (m_horizontal_angle < -180.0f)
     154        m_horizontal_angle += 360.0f;
     155    if (m_vertical_angle > 180.0f)
     156        m_vertical_angle -= 360.0f;
     157    else if (m_vertical_angle < -180.0f)
     158        m_vertical_angle += 360.0f;
     159    if (m_roll_angle > 180.0f)
     160        m_roll_angle -= 360.0f;
     161    else if (m_roll_angle < -180.0f)
     162        m_roll_angle += 360.0f;
    166163
    167164    mat4 animH = mat4::rotate(m_horizontal_angle, vec3(0, 1, 0));
     
    175172}
    176173
    177 void Orbital::TickDraw(float deltams)
    178 {
    179     WorldEntity::TickDraw(deltams);
     174void Orbital::TickDraw(float seconds)
     175{
     176    WorldEntity::TickDraw(seconds);
    180177
    181178    if (!m_ready)
Note: See TracChangeset for help on using the changeset viewer.