- Timestamp:
- Feb 4, 2013, 10:24:20 PM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lol/math/vector.h
r2346 r2348 937 937 LOL_MEMBER_OPS(Quat, w) 938 938 939 / /Angle in degree940 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); 942 942 943 943 /* Convert from Euler angles. The axes in fromeuler_xyx are 944 944 * x, then y', then x", ie. the axes are attached to the model. 945 945 * 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. */ 947 947 static Quat<T> fromeuler_xyx(Vec3<T> const &v); 948 948 static Quat<T> fromeuler_xzx(Vec3<T> const &v); … … 962 962 * x, then y', then z", ie. the axes are attached to the model. 963 963 * 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. 965 965 * If you want to rotate around static axes, reverse the order in 966 966 * the function name (_zyx instead of _xyz) AND reverse the order … … 1481 1481 1482 1482 /* 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; 1488 1487 } 1489 1488 … … 1578 1577 static Mat3<T> scale(T x, T y, T z); 1579 1578 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); 1583 1581 1584 1582 static Mat3<T> fromeuler_xyz(Vec3<T> const &v); … … 1608 1606 static Mat3<T> fromeuler_zyz(T phi, T theta, T psi); 1609 1607 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; 1614 1611 } 1615 1612 … … 1734 1731 } 1735 1732 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; 1752 1746 } 1753 1747 -
trunk/src/math/vector.cpp
r2317 r2348 347 347 } 348 348 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);349 template<> mat2 mat2::rotate(float degrees) 350 { 351 degrees *= (M_PI / 180.0f); 352 353 float st = sin(degrees); 354 float ct = cos(degrees); 355 355 356 356 mat2 ret; … … 365 365 } 366 366 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);367 template<> 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); 373 373 374 374 float len = std::sqrt(x * x + y * y + z * z); … … 399 399 } 400 400 401 template<> mat3 mat3::rotate(float angle, vec3 v)402 { 403 return rotate( angle, v.x, v.y, v.z);401 template<> mat3 mat3::rotate(float degrees, vec3 v) 402 { 403 return rotate(degrees, v.x, v.y, v.z); 404 404 } 405 405 … … 484 484 } 485 485 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));486 template<> 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 495 template<> quat quat::rotate(float degrees, float x, float y, float z) 496 { 497 return quat::rotate(degrees, vec3(x, y, z)); 498 498 } 499 499
Note: See TracChangeset
for help on using the changeset viewer.