mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 12:15:56 +07:00
add rotate3, shear3
This commit is contained in:
30
README.md
30
README.md
@@ -1875,6 +1875,12 @@ mat<T, 2> rotate(T angle);
|
||||
template < typename T >
|
||||
mat<T, 2> rotate(const mat<T, 2>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate3(T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 3> rotate3(const mat<T, 3>& m, T angle);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> scale(const vec<T, 2>& v);
|
||||
|
||||
@@ -1887,29 +1893,41 @@ mat<T, 3> scale3(const vec<T, 2>& v);
|
||||
template < typename T >
|
||||
mat<T, 3> scale3(const mat<T, 3>& m, const vec<T, 2>& v);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear(T x, T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear(const mat<T, 2>& m, T x, T y);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear(const vec<T, 2>& v);
|
||||
|
||||
template < typename T >
|
||||
mat<T, 2> shear(const mat<T, 2>& m, const vec<T, 2>& v);
|
||||
|
||||
template < typename T >
|
||||
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
|
||||
|
||||
@@ -543,6 +543,16 @@ namespace vmath_hpp
|
||||
return m * rotate(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate3(T angle) {
|
||||
return mat<T, 3>(rotate(angle));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate3(const mat<T, 3>& m, T angle) {
|
||||
return m * rotate3(angle);
|
||||
}
|
||||
|
||||
// scale
|
||||
|
||||
template < typename T >
|
||||
@@ -564,13 +574,7 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> scale3(const vec<T, 2>& v) {
|
||||
/// REFERENCE:
|
||||
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
|
||||
|
||||
return {
|
||||
{ v.x, T{0}, T{0} },
|
||||
{ T{0}, v.y, T{0} },
|
||||
{ T{0}, T{0}, T{1} }};
|
||||
return mat<T, 3>(scale(v));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
@@ -581,23 +585,13 @@ namespace vmath_hpp
|
||||
// shear
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear(T x, T y) {
|
||||
[[nodiscard]] constexpr mat<T, 2> shear(const vec<T, 2>& v) {
|
||||
/// REFERENCE:
|
||||
/// https://en.wikipedia.org/wiki/Shear_matrix
|
||||
|
||||
return {
|
||||
{ T{1}, y },
|
||||
{ x, T{1} }};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear(const mat<T, 2>& m, T x, T y) {
|
||||
return m * shear(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 2> shear(const vec<T, 2>& v) {
|
||||
return shear(v.x, v.y);
|
||||
{ T{1}, v.y },
|
||||
{ v.x, T{1} }};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
@@ -605,6 +599,18 @@ namespace vmath_hpp
|
||||
return m * shear(v);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] constexpr mat<T, 3> shear3(const vec<T, 2>& v) {
|
||||
return mat<T, 3>(shear(v));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[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:
|
||||
@@ -620,6 +626,18 @@ namespace vmath_hpp
|
||||
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:
|
||||
@@ -634,6 +652,16 @@ namespace vmath_hpp
|
||||
[[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);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -236,11 +236,14 @@ TEST_CASE("vmath/ext/matrix_transform") {
|
||||
CHECK(fvec3(1.f,0.f,0.f) * rotate_z(rotate_z(pi_4),pi_4) == uapprox3(0.f,1.f,0.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));
|
||||
CHECK(fvec3(2.f,3.f,1) * rotate3(pi) == uapprox3(-2.f,-3.f,1.f));
|
||||
CHECK(fvec3(2.f,3.f,1) * rotate3(rotate3(pi_2),pi_2) == uapprox3(-2.f,-3.f,1.f));
|
||||
|
||||
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(fvec2(2.f,3.f) * rotate(rotate(pi_2),pi_2) == uapprox2(-2.f,-3.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));
|
||||
@@ -267,17 +270,31 @@ TEST_CASE("vmath/ext/matrix_transform") {
|
||||
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));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3(fvec2(0.f,0.f)) == uapprox3(2.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3(fvec2(2.f,0.f)) == uapprox3(8.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3(fvec2(0.f,2.f)) == uapprox3(2.f,7.f,1.f));
|
||||
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear(shear(fvec2(1.f,0.f)),fvec2(1.f,0.f)) == uapprox2(8.f,3.f));
|
||||
STATIC_CHECK(fvec2(2.f,3.f) * shear(shear(fvec2(0.f,1.f)),fvec2(0.f,1.f)) == uapprox2(2.f,7.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3(shear3(fvec2(1.f,0.f)),fvec2(1.f,0.f)) == uapprox3(8.f,3.f,1.f));
|
||||
STATIC_CHECK(fvec3(2.f,3.f,1.f) * shear3(shear3(fvec2(0.f,1.f)),fvec2(0.f,1.f)) == uapprox3(2.f,7.f,1.f));
|
||||
}
|
||||
|
||||
SUBCASE("matrix look_at") {
|
||||
|
||||
@@ -423,22 +423,28 @@ namespace vmath_hpp
|
||||
|
||||
template fix2x2f rotate(fix<float>);
|
||||
template fix2x2f rotate(const fix2x2f&, fix<float>);
|
||||
template fix3x3f rotate3(fix<float>);
|
||||
template fix3x3f rotate3(const fix3x3f&, fix<float>);
|
||||
|
||||
template fix2x2f scale(const fix2f&);
|
||||
template fix2x2f scale(const fix2x2f&, const fix2f&);
|
||||
template fix3x3f scale3(const fix2f&);
|
||||
template fix3x3f scale3(const fix3x3f&, const fix2f&);
|
||||
|
||||
template fix2x2f shear(fix<float>, fix<float>);
|
||||
template fix2x2f shear(const fix2x2f&, fix<float>, fix<float>);
|
||||
template fix2x2f shear(const fix2f&);
|
||||
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