Changeset 2348


Ignore:
Timestamp:
Feb 4, 2013, 10:24:20 PM (6 years ago)
Author:
sam
Message:

math: use "degrees" as the variable name for rotations for clarity.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r2346 r2348  
    937937    LOL_MEMBER_OPS(Quat, w)
    938938
    939     //Angle in degree
    940     static Quat<T> rotate(T angle, T x, T y, T z);
    941     static Quat<T> rotate(T angle, Vec3<T> const &v);
     939    /* Create a unit quaternion representing a rotation around an axis. */
     940    static Quat<T> rotate(T degrees, T x, T y, T z);
     941    static Quat<T> rotate(T degrees, Vec3<T> const &v);
    942942
    943943    /* Convert from Euler angles. The axes in fromeuler_xyx are
    944944     * x, then y', then x", ie. the axes are attached to the model.
    945945     * If you want to rotate around static axes, just reverse the order
    946      * of the arguments. */
     946     * of the arguments. Angle values are in degrees. */
    947947    static Quat<T> fromeuler_xyx(Vec3<T> const &v);
    948948    static Quat<T> fromeuler_xzx(Vec3<T> const &v);
     
    962962     * x, then y', then z", ie. the axes are attached to the model.
    963963     * If you want to apply yaw around x, pitch around y, and roll
    964      * around z, use fromeuler_xyz.
     964     * around z, use fromeuler_xyz. Angle values are in degrees.
    965965     * If you want to rotate around static axes, reverse the order in
    966966     * the function name (_zyx instead of _xyz) AND reverse the order
     
    14811481
    14821482    /* Helpers for transformation matrices */
    1483     //Angle in degree
    1484     static Mat2<T> rotate(T angle);
    1485     static inline Mat2<T> rotate(Mat2<T> mat, T angle)
    1486     {
    1487         return rotate(angle) * mat;
     1483    static Mat2<T> rotate(T degrees);
     1484    static inline Mat2<T> rotate(Mat2<T> mat, T degrees)
     1485    {
     1486        return rotate(degrees) * mat;
    14881487    }
    14891488
     
    15781577    static Mat3<T> scale(T x, T y, T z);
    15791578    static Mat3<T> scale(Vec3<T> v);
    1580     //Angle in degree
    1581     static Mat3<T> rotate(T angle, T x, T y, T z);
    1582     static Mat3<T> rotate(T angle, Vec3<T> v);
     1579    static Mat3<T> rotate(T degrees, T x, T y, T z);
     1580    static Mat3<T> rotate(T degrees, Vec3<T> v);
    15831581
    15841582    static Mat3<T> fromeuler_xyz(Vec3<T> const &v);
     
    16081606    static Mat3<T> fromeuler_zyz(T phi, T theta, T psi);
    16091607
    1610     //Angle in degree
    1611     static inline Mat3<T> rotate(Mat3<T> mat, T angle, Vec3<T> v)
    1612     {
    1613         return rotate(angle, v) * mat;
     1608    static inline Mat3<T> rotate(Mat3<T> mat, T degrees, Vec3<T> v)
     1609    {
     1610        return rotate(degrees, v) * mat;
    16141611    }
    16151612
     
    17341731    }
    17351732
    1736     //Angle in degree
    1737     static inline Mat4<T> rotate(T angle, T x, T y, T z)
    1738     {
    1739         return Mat4<T>(Mat3<T>::rotate(angle, x, y, z), (T)1);
    1740     }
    1741 
    1742     //Angle in degree
    1743     static inline Mat4<T> rotate(T angle, Vec3<T> v)
    1744     {
    1745         return Mat4<T>(Mat3<T>::rotate(angle, v), (T)1);
    1746     }
    1747 
    1748     //Angle in degree
    1749     static inline Mat4<T> rotate(Mat4<T> &mat, T angle, Vec3<T> v)
    1750     {
    1751         return rotate(angle, v) * mat;
     1733    static inline Mat4<T> rotate(T degrees, T x, T y, T z)
     1734    {
     1735        return Mat4<T>(Mat3<T>::rotate(degrees, x, y, z), (T)1);
     1736    }
     1737
     1738    static inline Mat4<T> rotate(T degrees, Vec3<T> v)
     1739    {
     1740        return Mat4<T>(Mat3<T>::rotate(degrees, v), (T)1);
     1741    }
     1742
     1743    static inline Mat4<T> rotate(Mat4<T> &mat, T degrees, Vec3<T> v)
     1744    {
     1745        return rotate(degrees, v) * mat;
    17521746    }
    17531747
  • trunk/src/math/vector.cpp

    r2317 r2348  
    347347}
    348348
    349 template<> mat2 mat2::rotate(float angle)
    350 {
    351     angle *= (M_PI / 180.0f);
    352 
    353     float st = sin(angle);
    354     float ct = cos(angle);
     349template<> mat2 mat2::rotate(float degrees)
     350{
     351    degrees *= (M_PI / 180.0f);
     352
     353    float st = sin(degrees);
     354    float ct = cos(degrees);
    355355
    356356    mat2 ret;
     
    365365}
    366366
    367 template<> mat3 mat3::rotate(float angle, float x, float y, float z)
    368 {
    369     angle *= (M_PI / 180.0f);
    370 
    371     float st = sin(angle);
    372     float ct = cos(angle);
     367template<> mat3 mat3::rotate(float degrees, float x, float y, float z)
     368{
     369    degrees *= (M_PI / 180.0f);
     370
     371    float st = sin(degrees);
     372    float ct = cos(degrees);
    373373
    374374    float len = std::sqrt(x * x + y * y + z * z);
     
    399399}
    400400
    401 template<> mat3 mat3::rotate(float angle, vec3 v)
    402 {
    403     return rotate(angle, v.x, v.y, v.z);
     401template<> mat3 mat3::rotate(float degrees, vec3 v)
     402{
     403    return rotate(degrees, v.x, v.y, v.z);
    404404}
    405405
     
    484484}
    485485
    486 template<> quat quat::rotate(float angle, vec3 const &v)
    487 {
    488     angle *= (M_PI / 360.0f);
    489 
    490     vec3 tmp = normalize(v) * sin(angle);
    491 
    492     return quat(cos(angle), tmp.x, tmp.y, tmp.z);
    493 }
    494 
    495 template<> quat quat::rotate(float angle, float x, float y, float z)
    496 {
    497     return quat::rotate(angle, vec3(x, y, z));
     486template<> quat quat::rotate(float degrees, vec3 const &v)
     487{
     488    degrees *= (M_PI / 360.0f);
     489
     490    vec3 tmp = normalize(v) * sin(degrees);
     491
     492    return quat(cos(degrees), tmp.x, tmp.y, tmp.z);
     493}
     494
     495template<> quat quat::rotate(float degrees, float x, float y, float z)
     496{
     497    return quat::rotate(degrees, vec3(x, y, z));
    498498}
    499499
Note: See TracChangeset for help on using the changeset viewer.