Changeset 1314


Ignore:
Timestamp:
Apr 30, 2012, 12:23:11 PM (9 years ago)
Author:
sam
Message:

math: add quat::fromeuler static constructor for quaternions.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1312 r1314  
    114114
    115115    //Doing the query with actual values, cause I want to stay SDL-free for now.
    116     int HMovement = Input::GetButtonState(276 /*SDLK_LEFT*/) - Input::GetButtonState(275 /*SDLK_RIGHT*/);
    117     int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
    118     int RMovement = Input::GetButtonState(256 /*SDLK_KP0*/) - Input::GetButtonState(305 /*SDLK_RCTRL*/);
     116    int VMovement = Input::GetButtonState(274 /*SDLK_DOWN*/) - Input::GetButtonState(273 /*SDLK_UP*/);
     117    int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
     118    int RMovement = Input::GetButtonState(305 /*SDLK_RCTRL*/) - Input::GetButtonState(256 /*SDLK_KP0*/);
    119119
    120120    vec3 new_angular_velocity = vec3(0.0f);
    121121
    122     if (HMovement != 0 || VMovement != 0 || RMovement != 0)
     122    if (VMovement != 0 || HMovement != 0 || RMovement != 0)
    123123    {
    124         new_angular_velocity = vec3(HMovement, VMovement, RMovement) * 50.0f;
     124        new_angular_velocity = vec3(VMovement, HMovement, RMovement) * 50.0f;
    125125        m_auto_cam_timer = 2.0f;
    126126    }
     
    128128    {
    129129        /* 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));
     130        new_angular_velocity = clamp(-m_angle, vec3(-20.f, 40.f, -40.f),
     131                                               vec3( 20.f, 40.f,  40.f));
    132132    }
    133133
     
    145145    }
    146146
    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));
     147    mat4 anim = mat4::rotate(quat::fromeuler(m_angle));
    150148    mat4 model = mat4::translate(vec3(0));
    151149
    152     m_modelview = m_camera->GetViewMatrix() * model * animV * animR * animH;
     150    m_modelview = m_camera->GetViewMatrix() * model * anim;
    153151    m_proj = m_camera->GetProjMatrix();
    154152    m_normalmat = transpose(inverse(mat3(m_modelview)));
  • trunk/src/lol/math/vector.h

    r1313 r1314  
    924924    static Quat<T> rotate(T angle, T x, T y, T z);
    925925    static Quat<T> rotate(T angle, Vec3<T> const &v);
     926    static Quat<T> fromeuler(T x, T y, T z);
     927    static Quat<T> fromeuler(Vec3<T> const &v);
    926928
    927929    inline Quat<T> operator *(Quat<T> const &val) const
  • trunk/src/math/vector.cpp

    r1305 r1314  
    471471}
    472472
     473template<> quat quat::fromeuler(vec3 const &v)
     474{
     475    using std::sin;
     476    using std::cos;
     477
     478    vec3 half_angles = (M_PI / 360.0f) * v;
     479    float sx = sin(half_angles.x), cx = cos(half_angles.x);
     480    float sy = sin(half_angles.y), cy = cos(half_angles.y);
     481    float sz = sin(half_angles.z), cz = cos(half_angles.z);
     482
     483    return quat(cx * cy * cz + sx * sy * sz,
     484                sx * cy * cz - cx * sy * sz,
     485                cx * sy * cz + sx * cy * sz,
     486                cx * cy * sz - sx * sy * cz);
     487}
     488
     489template<> quat quat::fromeuler(float x, float y, float z)
     490{
     491    return quat::fromeuler(vec3(x, y, z));
     492}
     493
    473494template<> mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up)
    474495{
Note: See TracChangeset for help on using the changeset viewer.