diff --git a/headers/vmath.hpp/vmath_ext.hpp b/headers/vmath.hpp/vmath_ext.hpp index dce10f1..f8068bd 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -645,6 +645,21 @@ namespace vmath_hpp v.x * s + v.y * c}; } + template < typename T > + [[nodiscard]] vec rotate_x(const vec& v, T angle) { + return v * qrotate(angle, unit3_x); + } + + template < typename T > + [[nodiscard]] vec rotate_y(const vec& v, T angle) { + return v * qrotate(angle, unit3_y); + } + + template < typename T > + [[nodiscard]] vec rotate_z(const vec& v, T angle) { + return v * qrotate(angle, unit3_z); + } + template < typename T > [[nodiscard]] vec rotate(const vec& v, const qua& q) { return v * q; @@ -655,6 +670,21 @@ namespace vmath_hpp return v * qrotate(angle, axis); } + template < typename T > + [[nodiscard]] vec rotate_x(const vec& v, T angle) { + return v * qrotate(angle, unit3_x); + } + + template < typename T > + [[nodiscard]] vec rotate_y(const vec& v, T angle) { + return v * qrotate(angle, unit3_y); + } + + template < typename T > + [[nodiscard]] vec rotate_z(const vec& v, T angle) { + return v * qrotate(angle, unit3_z); + } + template < typename T > [[nodiscard]] vec rotate(const vec& v, const qua& q) { return v * q; diff --git a/untests/vmath_ext_tests.cpp b/untests/vmath_ext_tests.cpp index bb84c97..83a7eb3 100644 --- a/untests/vmath_ext_tests.cpp +++ b/untests/vmath_ext_tests.cpp @@ -285,11 +285,19 @@ 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_x(float3(0.f,1.5f,0.f), radians(90.f)) == uapprox3(0.f,0.f,1.5f)); + REQUIRE(rotate_y(float3(0.f,0.f,1.5f), radians(90.f)) == uapprox3(1.5f,0.f,0.f)); + REQUIRE(rotate_z(float3(1.5f,0.f,0.f), radians(90.f)) == uapprox3(0.f,1.5f,0.f)); + 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)); + REQUIRE(rotate_x(float4(0.f,1.5f,0.f,2.f), radians(90.f)) == uapprox4(0.f,0.f,1.5f,2.f)); + REQUIRE(rotate_y(float4(0.f,0.f,1.5f,2.f), radians(90.f)) == uapprox4(1.5f,0.f,0.f,2.f)); + REQUIRE(rotate_z(float4(1.5f,0.f,0.f,2.f), radians(90.f)) == uapprox4(0.f,1.5f,0.f,2.f)); + + REQUIRE(rotate(float4(1.5f,0.f,0.f,2.f), qrotate_z(radians(90.f))) == uapprox4(0.f,1.5f,0.f,2.f)); + REQUIRE(rotate(float4(1.5f,0.f,0.f,2.f), radians(90.f), float3(0,0,1)) == uapprox4(0.f,1.5f,0.f,2.f)); } SECTION("vector project") {