Ver código fonte

math: allow quat * vec3 and quat * vec4 operations.

undefined
Sam Hocevar 11 anos atrás
pai
commit
e1d459ed75
1 arquivos alterados com 18 adições e 1 exclusões
  1. +18
    -1
      src/lol/math/vector.h

+ 18
- 1
src/lol/math/vector.h Ver arquivo

@@ -1035,13 +1035,30 @@ template <typename T> struct Quat
return Quat<T>(w, -x, -y, -z);
}

inline Vec3<T> transform(Vec3<T> const &v)
inline Vec3<T> transform(Vec3<T> const &v) const
{
Quat<T> p = Quat<T>(0, v.x, v.y, v.z);
Quat<T> q = *this * p / *this;
return Vec3<T>(q.x, q.y, q.z);
}

inline Vec4<T> transform(Vec4<T> const &v) const
{
Quat<T> p = Quat<T>(0, v.x, v.y, v.z);
Quat<T> q = *this * p / *this;
return Vec4<T>(q.x, q.y, q.z, v.w);
}

inline Vec3<T> operator *(Vec3<T> const &v) const
{
return transform(v);
}

inline Vec4<T> operator *(Vec4<T> const &v) const
{
return transform(v);
}

template<typename U>
friend std::ostream &operator<<(std::ostream &stream, Quat<U> const &v);



Carregando…
Cancelar
Salvar