Ignore:
Timestamp:
Apr 30, 2012, 3:12:47 AM (9 years ago)
Author:
sam
Message:

orbital: use newly available vector operations for angular velocity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1310 r1312  
    9494    m_auto_cam_timer = 0.0f;
    9595
    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;
     96    m_angle = vec3(0.f);
     97    m_angular_velocity = vec3(0.f);
    10398
    10499    m_ready = false;
     
    123118    int RMovement = Input::GetButtonState(256 /*SDLK_KP0*/) - Input::GetButtonState(305 /*SDLK_RCTRL*/);
    124119
    125     float new_horizontal_angle_speed = 0.0f;
    126     float new_vertical_angle_speed = 0.0f;
    127     float new_roll_angle_speed = 0.0f;
     120    vec3 new_angular_velocity = vec3(0.0f);
    128121
    129122    if (HMovement != 0 || VMovement != 0 || RMovement != 0)
    130123    {
    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;
     124        new_angular_velocity = vec3(HMovement, VMovement, RMovement) * 50.0f;
    134125        m_auto_cam_timer = 2.0f;
    135126    }
    136127    else if (m_auto_cam_timer <= 0.0f)
    137128    {
    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);
     129        /* Order is yaw, pitch, roll */
     130        new_angular_velocity = clamp(-m_angle, vec3(40.f, -20.f, -40.f),
     131                                               vec3(40.f,  20.f,  40.f));
    141132    }
    142133
    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));
     134    m_angular_velocity += (new_angular_velocity - m_angular_velocity)
     135                          * (seconds / (seconds + 0.3f));
     136    m_angle += m_angular_velocity * seconds;
    146137
    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;
     138    /* TODO: implement "vec3 % float" or "fmod(vec3, float)" */
     139    for (int n = 0; n < 3; n++)
     140    {
     141        if (m_angle[n] > 180.f)
     142            m_angle[n] -= 360.f;
     143        else if (m_angle[n] < -180.f)
     144            m_angle[n] += 360.f;
     145    }
    150146
    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;
    163 
    164     mat4 animH = mat4::rotate(m_horizontal_angle, vec3(0, 1, 0));
    165     mat4 animV = mat4::rotate(m_vertical_angle, vec3(1, 0, 0));
    166     mat4 animR = mat4::rotate(m_roll_angle, vec3(0, 0, 1));
     147    mat4 animH = mat4::rotate(m_angle[0], vec3(0, 1, 0));
     148    mat4 animV = mat4::rotate(m_angle[1], vec3(1, 0, 0));
     149    mat4 animR = mat4::rotate(m_angle[2], vec3(0, 0, 1));
    167150    mat4 model = mat4::translate(vec3(0));
    168151
Note: See TracChangeset for help on using the changeset viewer.