diff --git a/README.md b/README.md index c6a8cd9..a009621 100644 --- a/README.md +++ b/README.md @@ -1875,6 +1875,12 @@ mat rotate(T angle); template < typename T > mat rotate(const mat& m, T angle); +template < typename T > +mat rotate3(T angle); + +template < typename T > +mat rotate3(const mat& m, T angle); + template < typename T > mat scale(const vec& v); @@ -1887,29 +1893,41 @@ mat scale3(const vec& v); template < typename T > mat scale3(const mat& m, const vec& v); -template < typename T > -mat shear(T x, T y); - -template < typename T > -mat shear(const mat& m, T x, T y); - template < typename T > mat shear(const vec& v); template < typename T > mat shear(const mat& m, const vec& v); +template < typename T > +mat shear3(const vec& v); + +template < typename T > +mat shear3(const mat& m, const vec& v); + template < typename T > mat shear_x(T y); template < typename T > mat shear_x(const mat& m, T y); +template < typename T > +mat shear3_x(T y); + +template < typename T > +mat shear3_x(const mat& m, T y); + template < typename T > mat shear_y(T x); template < typename T > mat shear_y(const mat& m, T x); + +template < typename T > +mat shear3_y(T x); + +template < typename T > +mat shear3_y(const mat& m, T x); ``` ### Matrix Projections diff --git a/headers/vmath.hpp/vmath_ext.hpp b/headers/vmath.hpp/vmath_ext.hpp index d328b5c..02fe4c8 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -543,6 +543,16 @@ namespace vmath_hpp return m * rotate(angle); } + template < typename T > + [[nodiscard]] constexpr mat rotate3(T angle) { + return mat(rotate(angle)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate3(const mat& m, T angle) { + return m * rotate3(angle); + } + // scale template < typename T > @@ -564,13 +574,7 @@ namespace vmath_hpp template < typename T > [[nodiscard]] constexpr mat scale3(const vec& 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(scale(v)); } template < typename T > @@ -581,23 +585,13 @@ namespace vmath_hpp // shear template < typename T > - [[nodiscard]] constexpr mat shear(T x, T y) { + [[nodiscard]] constexpr mat shear(const vec& v) { /// REFERENCE: /// https://en.wikipedia.org/wiki/Shear_matrix return { - { T{1}, y }, - { x, T{1} }}; - } - - template < typename T > - [[nodiscard]] constexpr mat shear(const mat& m, T x, T y) { - return m * shear(x, y); - } - - template < typename T > - [[nodiscard]] constexpr mat shear(const vec& 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 shear3(const vec& v) { + return mat(shear(v)); + } + + template < typename T > + [[nodiscard]] constexpr mat shear3(const mat& m, const vec& v) { + return m * shear3(v); + } + + // shear_x + template < typename T > [[nodiscard]] constexpr mat shear_x(T x) { /// REFERENCE: @@ -620,6 +626,18 @@ namespace vmath_hpp return m * shear_x(x); } + template < typename T > + [[nodiscard]] constexpr mat shear3_x(T x) { + return mat(shear_x(x)); + } + + template < typename T > + [[nodiscard]] constexpr mat shear3_x(const mat& m, T x) { + return m * shear3_x(x); + } + + // shear_y + template < typename T > [[nodiscard]] constexpr mat shear_y(T y) { /// REFERENCE: @@ -634,6 +652,16 @@ namespace vmath_hpp [[nodiscard]] constexpr mat shear_y(const mat& m, T y) { return m * shear_y(y); } + + template < typename T > + [[nodiscard]] constexpr mat shear3_y(T y) { + return mat(shear_y(y)); + } + + template < typename T > + [[nodiscard]] constexpr mat shear3_y(const mat& m, T y) { + return m * shear3_y(y); + } } // diff --git a/untests/vmath_ext_tests.cpp b/untests/vmath_ext_tests.cpp index 84af38c..bc69284 100644 --- a/untests/vmath_ext_tests.cpp +++ b/untests/vmath_ext_tests.cpp @@ -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") { diff --git a/untests/vmath_fix_tests.cpp b/untests/vmath_fix_tests.cpp index e76fdc8..73faddf 100644 --- a/untests/vmath_fix_tests.cpp +++ b/untests/vmath_fix_tests.cpp @@ -423,22 +423,28 @@ namespace vmath_hpp template fix2x2f rotate(fix); template fix2x2f rotate(const fix2x2f&, fix); + template fix3x3f rotate3(fix); + template fix3x3f rotate3(const fix3x3f&, fix); 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, fix); - template fix2x2f shear(const fix2x2f&, fix, fix); 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); template fix2x2f shear_x(const fix2x2f&, fix); + template fix3x3f shear3_x(fix); + template fix3x3f shear3_x(const fix3x3f&, fix); template fix2x2f shear_y(fix); template fix2x2f shear_y(const fix2x2f&, fix); + template fix3x3f shear3_y(fix); + template fix3x3f shear3_y(const fix3x3f&, fix); } //