rotate vec4 by qua

This commit is contained in:
BlackMATov
2021-01-26 02:26:48 +07:00
parent 1d5ee20967
commit c440789bee
4 changed files with 35 additions and 4 deletions

View File

@@ -646,13 +646,23 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, T angle, const vec<T, 3>& normal) {
return v * mat<T, 3>(rotate(angle, normal));
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, const qua<T>& q) {
return v * q;
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate(const vec<T, 4>& v, T angle, const vec<T, 3>& normal) {
return v * rotate(angle, normal);
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, T angle, const vec<T, 3>& axis) {
return v * qrotate(angle, axis);
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate(const vec<T, 4>& v, const qua<T>& q) {
return v * q;
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate(const vec<T, 4>& v, T angle, const vec<T, 3>& axis) {
return v * qrotate(angle, axis);
}
// project

View File

@@ -80,6 +80,11 @@ namespace vmath_hpp
return xs + qv2 * ys.s + cross(ys.v, qv2);
}
template < typename T >
[[nodiscard]] constexpr vec<T, 4> operator*(const vec<T, 4>& xs, const qua<T>& ys) {
return {vec<T, 3>{xs} * ys, xs.w};
}
template < typename T >
[[nodiscard]] constexpr qua<T> operator*(const qua<T>& xs, const qua<T>& ys) {
return {
@@ -99,6 +104,11 @@ namespace vmath_hpp
return (xs = (xs * ys));
}
template < typename T >
constexpr vec<T, 4>& operator*=(vec<T, 4>& xs, const qua<T>& ys) {
return (xs = (xs * ys));
}
template < typename T >
constexpr qua<T>& operator*=(qua<T>& xs, const qua<T>& ys) {
return (xs = (xs * ys));