Sfoglia il codice sorgente

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

legacy
Sam Hocevar sam 11 anni fa
parent
commit
eead925c59
2 ha cambiato i file con 34 aggiunte e 40 eliminazioni
  1. +18
    -24
      src/lol/math/vector.h
  2. +16
    -16
      src/math/vector.cpp

+ 18
- 24
src/lol/math/vector.h Vedi File

@@ -936,14 +936,14 @@ template <typename T> struct Quat

LOL_MEMBER_OPS(Quat, w)

//Angle in degree
static Quat<T> rotate(T angle, T x, T y, T z);
static Quat<T> rotate(T angle, Vec3<T> const &v);
/* Create a unit quaternion representing a rotation around an axis. */
static Quat<T> rotate(T degrees, T x, T y, T z);
static Quat<T> rotate(T degrees, Vec3<T> 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<T> fromeuler_xyx(Vec3<T> const &v);
static Quat<T> fromeuler_xzx(Vec3<T> const &v);
static Quat<T> fromeuler_yxy(Vec3<T> const &v);
@@ -961,7 +961,7 @@ template <typename T> 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 <typename T> struct Mat2
inline Vec2<T> const& operator[](size_t n) const { return (&v0)[n]; }

/* Helpers for transformation matrices */
//Angle in degree
static Mat2<T> rotate(T angle);
static inline Mat2<T> rotate(Mat2<T> mat, T angle)
static Mat2<T> rotate(T degrees);
static inline Mat2<T> rotate(Mat2<T> mat, T degrees)
{
return rotate(angle) * mat;
return rotate(degrees) * mat;
}

void printf() const;
@@ -1577,9 +1576,8 @@ template <typename T> struct Mat3
static Mat3<T> scale(T x);
static Mat3<T> scale(T x, T y, T z);
static Mat3<T> scale(Vec3<T> v);
//Angle in degree
static Mat3<T> rotate(T angle, T x, T y, T z);
static Mat3<T> rotate(T angle, Vec3<T> v);
static Mat3<T> rotate(T degrees, T x, T y, T z);
static Mat3<T> rotate(T degrees, Vec3<T> v);

static Mat3<T> fromeuler_xyz(Vec3<T> const &v);
static Mat3<T> fromeuler_xzy(Vec3<T> const &v);
@@ -1607,10 +1605,9 @@ template <typename T> struct Mat3
static Mat3<T> fromeuler_zxz(T phi, T theta, T psi);
static Mat3<T> fromeuler_zyz(T phi, T theta, T psi);

//Angle in degree
static inline Mat3<T> rotate(Mat3<T> mat, T angle, Vec3<T> v)
static inline Mat3<T> rotate(Mat3<T> mat, T degrees, Vec3<T> v)
{
return rotate(angle, v) * mat;
return rotate(degrees, v) * mat;
}

void printf() const;
@@ -1733,22 +1730,19 @@ template <typename T> struct Mat4
return translate(v) * mat;
}

//Angle in degree
static inline Mat4<T> rotate(T angle, T x, T y, T z)
static inline Mat4<T> rotate(T degrees, T x, T y, T z)
{
return Mat4<T>(Mat3<T>::rotate(angle, x, y, z), (T)1);
return Mat4<T>(Mat3<T>::rotate(degrees, x, y, z), (T)1);
}

//Angle in degree
static inline Mat4<T> rotate(T angle, Vec3<T> v)
static inline Mat4<T> rotate(T degrees, Vec3<T> v)
{
return Mat4<T>(Mat3<T>::rotate(angle, v), (T)1);
return Mat4<T>(Mat3<T>::rotate(degrees, v), (T)1);
}

//Angle in degree
static inline Mat4<T> rotate(Mat4<T> &mat, T angle, Vec3<T> v)
static inline Mat4<T> rotate(Mat4<T> &mat, T degrees, Vec3<T> v)
{
return rotate(angle, v) * mat;
return rotate(degrees, v) * mat;
}

static Mat4<T> fromeuler_xyz(Vec3<T> const &v);


+ 16
- 16
src/math/vector.cpp Vedi File

@@ -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)


Caricamento…
Annulla
Salva