vector: rotate_x, rotate_y, rotate_z ext functions

This commit is contained in:
BlackMATov
2021-01-26 21:41:01 +07:00
parent ecee465511
commit b5bf46606d
2 changed files with 40 additions and 2 deletions

View File

@@ -645,6 +645,21 @@ namespace vmath_hpp
v.x * s + v.y * c};
}
template < typename T >
[[nodiscard]] vec<T, 3> rotate_x(const vec<T, 3>& v, T angle) {
return v * qrotate(angle, unit3_x<T>);
}
template < typename T >
[[nodiscard]] vec<T, 3> rotate_y(const vec<T, 3>& v, T angle) {
return v * qrotate(angle, unit3_y<T>);
}
template < typename T >
[[nodiscard]] vec<T, 3> rotate_z(const vec<T, 3>& v, T angle) {
return v * qrotate(angle, unit3_z<T>);
}
template < typename T >
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, const qua<T>& q) {
return v * q;
@@ -655,6 +670,21 @@ namespace vmath_hpp
return v * qrotate(angle, axis);
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate_x(const vec<T, 4>& v, T angle) {
return v * qrotate(angle, unit3_x<T>);
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate_y(const vec<T, 4>& v, T angle) {
return v * qrotate(angle, unit3_y<T>);
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate_z(const vec<T, 4>& v, T angle) {
return v * qrotate(angle, unit3_z<T>);
}
template < typename T >
[[nodiscard]] vec<T, 4> rotate(const vec<T, 4>& v, const qua<T>& q) {
return v * q;

View File

@@ -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") {