diff --git a/headers/vmath.hpp/vmath_ext.hpp b/headers/vmath.hpp/vmath_ext.hpp index aeae410..dce10f1 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -646,13 +646,23 @@ namespace vmath_hpp } template < typename T > - [[nodiscard]] vec rotate(const vec& v, T angle, const vec& normal) { - return v * mat(rotate(angle, normal)); + [[nodiscard]] vec rotate(const vec& v, const qua& q) { + return v * q; } template < typename T > - [[nodiscard]] vec rotate(const vec& v, T angle, const vec& normal) { - return v * rotate(angle, normal); + [[nodiscard]] vec rotate(const vec& v, T angle, const vec& axis) { + return v * qrotate(angle, axis); + } + + template < typename T > + [[nodiscard]] vec rotate(const vec& v, const qua& q) { + return v * q; + } + + template < typename T > + [[nodiscard]] vec rotate(const vec& v, T angle, const vec& axis) { + return v * qrotate(angle, axis); } // project diff --git a/headers/vmath.hpp/vmath_qua_fun.hpp b/headers/vmath.hpp/vmath_qua_fun.hpp index cc679f3..f57650d 100644 --- a/headers/vmath.hpp/vmath_qua_fun.hpp +++ b/headers/vmath.hpp/vmath_qua_fun.hpp @@ -80,6 +80,11 @@ namespace vmath_hpp return xs + qv2 * ys.s + cross(ys.v, qv2); } + template < typename T > + [[nodiscard]] constexpr vec operator*(const vec& xs, const qua& ys) { + return {vec{xs} * ys, xs.w}; + } + template < typename T > [[nodiscard]] constexpr qua operator*(const qua& xs, const qua& ys) { return { @@ -99,6 +104,11 @@ namespace vmath_hpp return (xs = (xs * ys)); } + template < typename T > + constexpr vec& operator*=(vec& xs, const qua& ys) { + return (xs = (xs * ys)); + } + template < typename T > constexpr qua& operator*=(qua& xs, const qua& ys) { return (xs = (xs * ys)); diff --git a/untests/vmath_ext_tests.cpp b/untests/vmath_ext_tests.cpp index 8a98209..974b538 100644 --- a/untests/vmath_ext_tests.cpp +++ b/untests/vmath_ext_tests.cpp @@ -285,7 +285,10 @@ TEST_CASE("vmath/ext") { REQUIRE(rotate(float2(2.f,0.f), radians(90.f)) == uapprox2(0.f,2.f)); REQUIRE(rotate(float2(1.5f,0.f), radians(-90.f)) == uapprox2(0.f,-1.5f)); + REQUIRE(rotate(float3(1.5f,0.f,0.f), qrotate_z(radians(90.f))) == uapprox3(0.f,1.5f,0.f)); REQUIRE(rotate(float3(1.5f,0.f,0.f), radians(90.f), float3(0,0,1)) == uapprox3(0.f,1.5f,0.f)); + + REQUIRE(rotate(float4(1.5f,0.f,0.f,1.f), qrotate_z(radians(90.f))) == uapprox4(0.f,1.5f,0.f,1.f)); REQUIRE(rotate(float4(1.5f,0.f,0.f,1.f), radians(90.f), float3(0,0,1)) == uapprox4(0.f,1.5f,0.f,1.f)); } diff --git a/untests/vmath_qua_fun_tests.cpp b/untests/vmath_qua_fun_tests.cpp index 4036ee2..c0b83f3 100644 --- a/untests/vmath_qua_fun_tests.cpp +++ b/untests/vmath_qua_fun_tests.cpp @@ -59,9 +59,17 @@ TEST_CASE("vmath/qua_fun") { REQUIRE(v == uapprox3(0.f,1.f,0.f)); } + { + float4 v{1,0,0,2}; + REQUIRE(&v == &(v *= fqua{0,0,0.7071067812f,0.7071067812f})); + REQUIRE(v == uapprox4(0.f,1.f,0.f,2.f)); + } + STATIC_REQUIRE(fqua{} * fqua{} == fqua{}); STATIC_REQUIRE(float3{1,2,3} * fqua{} == uapprox3(1.f,2.f,3.f)); + STATIC_REQUIRE(float4{1,2,3,4} * fqua{} == uapprox4(1.f,2.f,3.f,4.f)); STATIC_REQUIRE(float3{1,0,0} * fqua{0,0,0.7071067812f,0.7071067812f} == uapprox3(0.f,1.f,0.f)); + STATIC_REQUIRE(float4{1,0,0,2} * fqua{0,0,0.7071067812f,0.7071067812f} == uapprox4(0.f,1.f,0.f,2.f)); } SUBCASE("Common Functions") {