Quellcode durchsuchen

math: create a quaternion from two vectors.

undefined
Sam Hocevar vor 11 Jahren
Ursprung
Commit
af6deb15a2
2 geänderte Dateien mit 12 neuen und 0 gelöschten Zeilen
  1. +4
    -0
      src/lol/math/vector.h
  2. +8
    -0
      src/math/vector.cpp

+ 4
- 0
src/lol/math/vector.h Datei anzeigen

@@ -939,6 +939,10 @@ template <typename T> struct Quat
static Quat<T> rotate(T degrees, T x, T y, T z);
static Quat<T> rotate(T degrees, Vec3<T> const &v);

/* Create a unit quaternion representing a rotation between two vectors.
* Input vectors need not be normalised. */
static Quat<T> rotate(Vec3<T> const &src, Vec3<T> const &dst);

/* 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


+ 8
- 0
src/math/vector.cpp Datei anzeigen

@@ -501,6 +501,14 @@ template<> quat quat::rotate(float degrees, float x, float y, float z)
return quat::rotate(degrees, vec3(x, y, z));
}

template<> quat quat::rotate(vec3 const &src, vec3 const &dst)
{
vec3 v = cross(src, dst);
float d = dot(src, dst) + lol::sqrt(sqlength(src) * sqlength(dst));

return normalize(quat(d, v.x, v.y, v.z));
}

template<> quat slerp(quat const &qa, quat const &qb, float f)
{
float const magnitude = lol::sqrt(sqlength(qa) * sqlength(qb));


Laden…
Abbrechen
Speichern