From eead925c5980ce2c7c829178de51083139f20cd4 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 4 Feb 2013 21:24:20 +0000 Subject: [PATCH] math: use "degrees" as the variable name for rotations for clarity. --- src/lol/math/vector.h | 42 ++++++++++++++++++------------------------ src/math/vector.cpp | 32 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index da90615c..d164b269 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -936,14 +936,14 @@ template struct Quat LOL_MEMBER_OPS(Quat, w) - //Angle in degree - static Quat rotate(T angle, T x, T y, T z); - static Quat rotate(T angle, Vec3 const &v); + /* Create a unit quaternion representing a rotation around an axis. */ + static Quat rotate(T degrees, T x, T y, T z); + static Quat rotate(T degrees, Vec3 const &v); /* Convert from Euler angles. The axes in fromeuler_xyx are * x, then y', then x", ie. the axes are attached to the model. * If you want to rotate around static axes, just reverse the order - * of the arguments. */ + * of the arguments. Angle values are in degrees. */ static Quat fromeuler_xyx(Vec3 const &v); static Quat fromeuler_xzx(Vec3 const &v); static Quat fromeuler_yxy(Vec3 const &v); @@ -961,7 +961,7 @@ template struct Quat * but since everyone does it…). The axes in fromeuler_xyz are * x, then y', then z", ie. the axes are attached to the model. * If you want to apply yaw around x, pitch around y, and roll - * around z, use fromeuler_xyz. + * around z, use fromeuler_xyz. Angle values are in degrees. * If you want to rotate around static axes, reverse the order in * the function name (_zyx instead of _xyz) AND reverse the order * of the arguments. */ @@ -1480,11 +1480,10 @@ template struct Mat2 inline Vec2 const& operator[](size_t n) const { return (&v0)[n]; } /* Helpers for transformation matrices */ - //Angle in degree - static Mat2 rotate(T angle); - static inline Mat2 rotate(Mat2 mat, T angle) + static Mat2 rotate(T degrees); + static inline Mat2 rotate(Mat2 mat, T degrees) { - return rotate(angle) * mat; + return rotate(degrees) * mat; } void printf() const; @@ -1577,9 +1576,8 @@ template struct Mat3 static Mat3 scale(T x); static Mat3 scale(T x, T y, T z); static Mat3 scale(Vec3 v); - //Angle in degree - static Mat3 rotate(T angle, T x, T y, T z); - static Mat3 rotate(T angle, Vec3 v); + static Mat3 rotate(T degrees, T x, T y, T z); + static Mat3 rotate(T degrees, Vec3 v); static Mat3 fromeuler_xyz(Vec3 const &v); static Mat3 fromeuler_xzy(Vec3 const &v); @@ -1607,10 +1605,9 @@ template struct Mat3 static Mat3 fromeuler_zxz(T phi, T theta, T psi); static Mat3 fromeuler_zyz(T phi, T theta, T psi); - //Angle in degree - static inline Mat3 rotate(Mat3 mat, T angle, Vec3 v) + static inline Mat3 rotate(Mat3 mat, T degrees, Vec3 v) { - return rotate(angle, v) * mat; + return rotate(degrees, v) * mat; } void printf() const; @@ -1733,22 +1730,19 @@ template struct Mat4 return translate(v) * mat; } - //Angle in degree - static inline Mat4 rotate(T angle, T x, T y, T z) + static inline Mat4 rotate(T degrees, T x, T y, T z) { - return Mat4(Mat3::rotate(angle, x, y, z), (T)1); + return Mat4(Mat3::rotate(degrees, x, y, z), (T)1); } - //Angle in degree - static inline Mat4 rotate(T angle, Vec3 v) + static inline Mat4 rotate(T degrees, Vec3 v) { - return Mat4(Mat3::rotate(angle, v), (T)1); + return Mat4(Mat3::rotate(degrees, v), (T)1); } - //Angle in degree - static inline Mat4 rotate(Mat4 &mat, T angle, Vec3 v) + static inline Mat4 rotate(Mat4 &mat, T degrees, Vec3 v) { - return rotate(angle, v) * mat; + return rotate(degrees, v) * mat; } static Mat4 fromeuler_xyz(Vec3 const &v); diff --git a/src/math/vector.cpp b/src/math/vector.cpp index 123df5ee..f0fd3856 100644 --- a/src/math/vector.cpp +++ b/src/math/vector.cpp @@ -346,12 +346,12 @@ template<> mat4 mat4::translate(vec3 v) return translate(v.x, v.y, v.z); } -template<> mat2 mat2::rotate(float angle) +template<> mat2 mat2::rotate(float degrees) { - angle *= (M_PI / 180.0f); + degrees *= (M_PI / 180.0f); - float st = sin(angle); - float ct = cos(angle); + float st = sin(degrees); + float ct = cos(degrees); mat2 ret; @@ -364,12 +364,12 @@ template<> mat2 mat2::rotate(float angle) return ret; } -template<> mat3 mat3::rotate(float angle, float x, float y, float z) +template<> mat3 mat3::rotate(float degrees, float x, float y, float z) { - angle *= (M_PI / 180.0f); + degrees *= (M_PI / 180.0f); - float st = sin(angle); - float ct = cos(angle); + float st = sin(degrees); + float ct = cos(degrees); float len = std::sqrt(x * x + y * y + z * z); float invlen = len ? 1.0f / len : 0.0f; @@ -398,9 +398,9 @@ template<> mat3 mat3::rotate(float angle, float x, float y, float z) return ret; } -template<> mat3 mat3::rotate(float angle, vec3 v) +template<> mat3 mat3::rotate(float degrees, vec3 v) { - return rotate(angle, v.x, v.y, v.z); + return rotate(degrees, v.x, v.y, v.z); } template<> mat3::Mat3(quat const &q) @@ -483,18 +483,18 @@ template<> quat::Quat(mat4 const &m) MatrixToQuat(*this, mat3(m)); } -template<> quat quat::rotate(float angle, vec3 const &v) +template<> quat quat::rotate(float degrees, vec3 const &v) { - angle *= (M_PI / 360.0f); + degrees *= (M_PI / 360.0f); - vec3 tmp = normalize(v) * sin(angle); + vec3 tmp = normalize(v) * sin(degrees); - return quat(cos(angle), tmp.x, tmp.y, tmp.z); + return quat(cos(degrees), tmp.x, tmp.y, tmp.z); } -template<> quat quat::rotate(float angle, float x, float y, float z) +template<> quat quat::rotate(float degrees, float x, float y, float z) { - return quat::rotate(angle, vec3(x, y, z)); + return quat::rotate(degrees, vec3(x, y, z)); } template<> quat slerp(quat const &qa, quat const &qb, float f)