mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 12:15:56 +07:00
add rotate4, remove shear_x, shear_y
This commit is contained in:
54
README.md
54
README.md
@@ -1811,30 +1811,60 @@ mat<T, 3> rotate(const qua<T>& q);
|
||||
template < typename T >
|
||||
mat<T, 3> rotate(const mat<T, 3>& m, const qua<T>& q);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4(const qua<T>& q);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4(const mat<T, 4>& m, const qua<T>& q);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate(T angle, const vec<T, 3>& axis);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate(const mat<T, 3>& m, T angle, const vec<T, 3>& axis);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4(T angle, const vec<T, 3>& axis);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4(const mat<T, 4>& m, T angle, const vec<T, 3>& axis);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_x(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_x(const mat<T, 3>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_x(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_x(const mat<T, 4>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_y(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_y(const mat<T, 3>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_y(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_y(const mat<T, 4>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_z(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate_z(const mat<T, 3>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_z(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 4> rotate4_z(const mat<T, 4>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> scale(const vec<T, 3>& v);
|
||||
|
||||
@@ -1904,30 +1934,6 @@ mat<T, 3> shear3(const vec<T, 2>& v);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> shear3(const mat<T, 3>& m, const vec<T, 2>& v);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear_x(T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear_x(const mat<T, 2>& m, T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> shear3_x(T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> shear3_x(const mat<T, 3>& m, T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear_y(T x);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear_y(const mat<T, 2>& m, T x);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> shear3_y(T x);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> shear3_y(const mat<T, 3>& m, T x);
|
||||
```
|
||||
|
||||
### Matrix Projections
|
||||
|
||||
@@ -285,6 +285,16 @@ namespace vmath_hpp
|
||||
return m * rotate(q);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4(const qua<T>& q) {
|
||||
return mat<T, 4>(rotate(q));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4(const mat<T, 4>& m, const qua<T>& q) {
|
||||
return m * rotate4(q);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate(T angle, const vec<T, 3>& axis) {
|
||||
/// REFERENCE:
|
||||
@@ -322,6 +332,18 @@ namespace vmath_hpp
|
||||
return m * rotate(angle, axis);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4(T angle, const vec<T, 3>& axis) {
|
||||
return mat<T, 4>(rotate(angle, axis));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4(const mat<T, 4>& m, T angle, const vec<T, 3>& axis) {
|
||||
return m * rotate4(angle, axis);
|
||||
}
|
||||
|
||||
// rotate_x
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate_x(T angle) {
|
||||
/// REFERENCE:
|
||||
@@ -340,6 +362,18 @@ namespace vmath_hpp
|
||||
return m * rotate_x(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_x(T angle) {
|
||||
return mat<T, 4>(rotate_x(angle));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_x(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate4_x(angle);
|
||||
}
|
||||
|
||||
// rotate_y
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate_y(T angle) {
|
||||
/// REFERENCE:
|
||||
@@ -358,6 +392,18 @@ namespace vmath_hpp
|
||||
return m * rotate_y(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_y(T angle) {
|
||||
return mat<T, 4>(rotate_y(angle));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_y(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate4_y(angle);
|
||||
}
|
||||
|
||||
// rotate_z
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate_z(T angle) {
|
||||
/// REFERENCE:
|
||||
@@ -376,6 +422,16 @@ namespace vmath_hpp
|
||||
return m * rotate_z(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_z(T angle) {
|
||||
return mat<T, 4>(rotate_z(angle));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate4_z(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate4_z(angle);
|
||||
}
|
||||
|
||||
// scale
|
||||
|
||||
template < typename T >
|
||||
@@ -398,14 +454,7 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 4> scale4(const vec<T, 3>& v) {
|
||||
/// REFERENCE:
|
||||
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
|
||||
|
||||
return {
|
||||
{ v.x, T{0}, T{0}, T{0} },
|
||||
{ T{0}, v.y, T{0}, T{0} },
|
||||
{ T{0}, T{0}, v.z, T{0} },
|
||||
{ T{0}, T{0}, T{0}, T{1} }};
|
||||
return mat<T, 4>(scale(v));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
@@ -570,8 +619,6 @@ namespace vmath_hpp
|
||||
return m * scale(v);
|
||||
}
|
||||
|
||||
// scale3
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> scale3(const vec<T, 2>& v) {
|
||||
return mat<T, 3>(scale(v));
|
||||
@@ -608,60 +655,6 @@ namespace vmath_hpp
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3(const mat<T, 3>& m, const vec<T, 2>& v) {
|
||||
return m * shear3(v);
|
||||
}
|
||||
|
||||
// shear_x
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear_x(T x) {
|
||||
/// REFERENCE:
|
||||
/// https://en.wikipedia.org/wiki/Shear_matrix
|
||||
|
||||
return {
|
||||
{ T{1}, T{0} },
|
||||
{ x, T{1} }};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear_x(const mat<T, 2>& m, T x) {
|
||||
return m * shear_x(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3_x(T x) {
|
||||
return mat<T, 3>(shear_x(x));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3_x(const mat<T, 3>& m, T x) {
|
||||
return m * shear3_x(x);
|
||||
}
|
||||
|
||||
// shear_y
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear_y(T y) {
|
||||
/// REFERENCE:
|
||||
/// https://en.wikipedia.org/wiki/Shear_matrix
|
||||
|
||||
return {
|
||||
{ T{1}, y },
|
||||
{ T{0}, T{1} }};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear_y(const mat<T, 2>& m, T y) {
|
||||
return m * shear_y(y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3_y(T y) {
|
||||
return mat<T, 3>(shear_y(y));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3_y(const mat<T, 3>& m, T y) {
|
||||
return m * shear3_y(y);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -230,10 +230,16 @@ TEST_CASE("vmath/ext/matrix_transform") {
|
||||
CHECK(fvec3(0.f,1.f,0.f) * rotate_x(pi_2) == uapprox3(0.f,0.f,1.f));
|
||||
CHECK(fvec3(0.f,0.f,1.f) * rotate_y(pi_2) == uapprox3(1.f,0.f,0.f));
|
||||
CHECK(fvec3(1.f,0.f,0.f) * rotate_z(pi_2) == uapprox3(0.f,1.f,0.f));
|
||||
CHECK(fvec4(0.f,1.f,0.f,1.f) * rotate4_x(pi_2) == uapprox4(0.f,0.f,1.f,1.f));
|
||||
CHECK(fvec4(0.f,0.f,1.f,1.f) * rotate4_y(pi_2) == uapprox4(1.f,0.f,0.f,1.f));
|
||||
CHECK(fvec4(1.f,0.f,0.f,1.f) * rotate4_z(pi_2) == uapprox4(0.f,1.f,0.f,1.f));
|
||||
|
||||
CHECK(fvec3(0.f,1.f,0.f) * rotate_x(rotate_x(pi_4),pi_4) == uapprox3(0.f,0.f,1.f));
|
||||
CHECK(fvec3(0.f,0.f,1.f) * rotate_y(rotate_y(pi_4),pi_4) == uapprox3(1.f,0.f,0.f));
|
||||
CHECK(fvec3(1.f,0.f,0.f) * rotate_z(rotate_z(pi_4),pi_4) == uapprox3(0.f,1.f,0.f));
|
||||
CHECK(fvec4(0.f,1.f,0.f,1.f) * rotate4_x(rotate4_x(pi_4),pi_4) == uapprox4(0.f,0.f,1.f,1.f));
|
||||
CHECK(fvec4(0.f,0.f,1.f,1.f) * rotate4_y(rotate4_y(pi_4),pi_4) == uapprox4(1.f,0.f,0.f,1.f));
|
||||
CHECK(fvec4(1.f,0.f,0.f,1.f) * rotate4_z(rotate4_z(pi_4),pi_4) == uapprox4(0.f,1.f,0.f,1.f));
|
||||
|
||||
CHECK(fvec2(2.f,3.f) * rotate(pi) == uapprox2(-2.f,-3.f));
|
||||
CHECK(fvec2(2.f,3.f) * rotate(rotate(pi_2),pi_2) == uapprox2(-2.f,-3.f));
|
||||
@@ -243,10 +249,16 @@ TEST_CASE("vmath/ext/matrix_transform") {
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(pi,{0.f,0.f,1.f}) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(pi,fvec3{0.f,0.f,1.f}) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(qrotate(pi,fvec3{0.f,0.f,1.f})) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(pi,{0.f,0.f,1.f}) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(pi,fvec3{0.f,0.f,1.f}) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(qrotate(pi,fvec3{0.f,0.f,1.f})) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(rotate(pi_2,{0.f,0.f,1.f}),pi_2,{0.f,0.f,1.f}) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(rotate(pi_2,fvec3{0.f,0.f,1.f}),pi_2,fvec3{0.f,0.f,1.f}) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec3(2.f,3.f,4.f) * rotate(rotate(qrotate(pi_2,fvec3{0.f,0.f,1.f})),qrotate(pi_2,fvec3{0.f,0.f,1.f})) == uapprox3(-2.f,-3.f,4.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(rotate4(pi_2,{0.f,0.f,1.f}),pi_2,{0.f,0.f,1.f}) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(rotate4(pi_2,fvec3{0.f,0.f,1.f}),pi_2,fvec3{0.f,0.f,1.f}) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
CHECK(fvec4(2.f,3.f,4.f,1.f) * rotate4(rotate4(qrotate(pi_2,fvec3{0.f,0.f,1.f})),qrotate(pi_2,fvec3{0.f,0.f,1.f})) == uapprox4(-2.f,-3.f,4.f,1.f));
|
||||
}
|
||||
|
||||
SUBCASE("scale2d") {
|
||||
@@ -266,24 +278,6 @@ TEST_CASE("vmath/ext/matrix_transform") {
|
||||
}
|
||||
|
||||
SUBCASE("shear") {
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_x(0.f) == uapprox2(2.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_x(1.f) == uapprox2(5.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_x(2.f) == uapprox2(8.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_x(shear_x(1.f),1.f) == uapprox2(8.f,3.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_x(0.f) == uapprox3(2.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_x(1.f) == uapprox3(5.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_x(2.f) == uapprox3(8.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_x(shear3_x(1.f),1.f) == uapprox3(8.f,3.f,1.f));
|
||||
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_y(0.f) == uapprox2(2.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_y(1.f) == uapprox2(2.f,5.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_y(2.f) == uapprox2(2.f,7.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear_y(shear_y(1.f),1.f) == uapprox2(2.f,7.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_y(0.f) == uapprox3(2.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_y(1.f) == uapprox3(2.f,5.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_y(2.f) == uapprox3(2.f,7.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3_y(shear3_y(1.f),1.f) == uapprox3(2.f,7.f,1.f));
|
||||
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear(fvec2(0.f,0.f)) == uapprox2(2.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear(fvec2(2.f,0.f)) == uapprox2(8.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear(fvec2(0.f,2.f)) == uapprox2(2.f,7.f));
|
||||
|
||||
@@ -388,17 +388,28 @@ namespace vmath_hpp
|
||||
|
||||
template fix3x3f rotate(const qfix&);
|
||||
template fix3x3f rotate(const fix3x3f&, const qfix&);
|
||||
template fix4x4f rotate4(const qfix&);
|
||||
template fix4x4f rotate4(const fix4x4f&, const qfix&);
|
||||
|
||||
template fix3x3f rotate(fix<float>, const fix3f&);
|
||||
template fix3x3f rotate(const fix3x3f&, fix<float>, const fix3f&);
|
||||
template fix4x4f rotate4(fix<float>, const fix3f&);
|
||||
template fix4x4f rotate4(const fix4x4f&, fix<float>, const fix3f&);
|
||||
|
||||
template fix3x3f rotate_x(fix<float>);
|
||||
template fix3x3f rotate_x(const fix3x3f&, fix<float>);
|
||||
template fix4x4f rotate4_x(fix<float>);
|
||||
template fix4x4f rotate4_x(const fix4x4f&, fix<float>);
|
||||
|
||||
template fix3x3f rotate_y(fix<float>);
|
||||
template fix3x3f rotate_y(const fix3x3f&, fix<float>);
|
||||
template fix4x4f rotate4_y(fix<float>);
|
||||
template fix4x4f rotate4_y(const fix4x4f&, fix<float>);
|
||||
|
||||
template fix3x3f rotate_z(fix<float>);
|
||||
template fix3x3f rotate_z(const fix3x3f&, fix<float>);
|
||||
template fix4x4f rotate4_z(fix<float>);
|
||||
template fix4x4f rotate4_z(const fix4x4f&, fix<float>);
|
||||
|
||||
template fix3x3f scale(const fix3f&);
|
||||
template fix3x3f scale(const fix3x3f&, const fix3f&);
|
||||
@@ -435,16 +446,6 @@ namespace vmath_hpp
|
||||
template fix2x2f shear(const fix2x2f&, const fix2f&);
|
||||
template fix3x3f shear3(const fix2f&);
|
||||
template fix3x3f shear3(const fix3x3f&, const fix2f&);
|
||||
|
||||
template fix2x2f shear_x(fix<float>);
|
||||
template fix2x2f shear_x(const fix2x2f&, fix<float>);
|
||||
template fix3x3f shear3_x(fix<float>);
|
||||
template fix3x3f shear3_x(const fix3x3f&, fix<float>);
|
||||
|
||||
template fix2x2f shear_y(fix<float>);
|
||||
template fix2x2f shear_y(const fix2x2f&, fix<float>);
|
||||
template fix3x3f shear3_y(fix<float>);
|
||||
template fix3x3f shear3_y(const fix3x3f&, fix<float>);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user