瀏覽代碼

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

legacy
Sam Hocevar sam 12 年之前
父節點
當前提交
fceeaf1c74
共有 2 個檔案被更改,包括 23 行新增0 行删除
  1. +2
    -0
      src/lol/math/vector.h
  2. +21
    -0
      src/math/vector.cpp

+ 2
- 0
src/lol/math/vector.h 查看文件

@@ -923,6 +923,8 @@ template <typename T> struct Quat

static Quat<T> rotate(T angle, T x, T y, T z);
static Quat<T> rotate(T angle, Vec3<T> const &v);
static Quat<T> fromeuler(T x, T y, T z);
static Quat<T> fromeuler(Vec3<T> const &v);

inline Quat<T> operator *(Quat<T> const &val) const
{


+ 21
- 0
src/math/vector.cpp 查看文件

@@ -470,6 +470,27 @@ template<> quat quat::rotate(float angle, float x, float y, float z)
return quat::rotate(angle, vec3(x, y, z));
}

template<> quat quat::fromeuler(vec3 const &v)
{
using std::sin;
using std::cos;

vec3 half_angles = (M_PI / 360.0f) * v;
float sx = sin(half_angles.x), cx = cos(half_angles.x);
float sy = sin(half_angles.y), cy = cos(half_angles.y);
float sz = sin(half_angles.z), cz = cos(half_angles.z);

return quat(cx * cy * cz + sx * sy * sz,
sx * cy * cz - cx * sy * sz,
cx * sy * cz + sx * cy * sz,
cx * cy * sz - sx * sy * cz);
}

template<> quat quat::fromeuler(float x, float y, float z)
{
return quat::fromeuler(vec3(x, y, z));
}

template<> mat4 mat4::lookat(vec3 eye, vec3 center, vec3 up)
{
vec3 v3 = normalize(eye - center);


Loading…
取消
儲存