diff --git a/README.md b/README.md index a009621..e6f9265 100644 --- a/README.md +++ b/README.md @@ -1811,30 +1811,60 @@ mat rotate(const qua& q); template < typename T > mat rotate(const mat& m, const qua& q); +template < typename T > +mat rotate4(const qua& q); + +template < typename T > +mat rotate4(const mat& m, const qua& q); + template < typename T > mat rotate(T angle, const vec& axis); template < typename T > mat rotate(const mat& m, T angle, const vec& axis); +template < typename T > +mat rotate4(T angle, const vec& axis); + +template < typename T > +mat rotate4(const mat& m, T angle, const vec& axis); + template < typename T > mat rotate_x(T angle); template < typename T > mat rotate_x(const mat& m, T angle); +template < typename T > +mat rotate4_x(T angle); + +template < typename T > +mat rotate4_x(const mat& m, T angle); + template < typename T > mat rotate_y(T angle); template < typename T > mat rotate_y(const mat& m, T angle); +template < typename T > +mat rotate4_y(T angle); + +template < typename T > +mat rotate4_y(const mat& m, T angle); + template < typename T > mat rotate_z(T angle); template < typename T > mat rotate_z(const mat& m, T angle); +template < typename T > +mat rotate4_z(T angle); + +template < typename T > +mat rotate4_z(const mat& m, T angle); + template < typename T > mat scale(const vec& v); @@ -1904,30 +1934,6 @@ 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 02fe4c8..7883705 100644 --- a/headers/vmath.hpp/vmath_ext.hpp +++ b/headers/vmath.hpp/vmath_ext.hpp @@ -285,6 +285,16 @@ namespace vmath_hpp return m * rotate(q); } + template < typename T > + [[nodiscard]] constexpr mat rotate4(const qua& q) { + return mat(rotate(q)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate4(const mat& m, const qua& q) { + return m * rotate4(q); + } + template < typename T > [[nodiscard]] constexpr mat rotate(T angle, const vec& axis) { /// REFERENCE: @@ -322,6 +332,18 @@ namespace vmath_hpp return m * rotate(angle, axis); } + template < typename T > + [[nodiscard]] constexpr mat rotate4(T angle, const vec& axis) { + return mat(rotate(angle, axis)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate4(const mat& m, T angle, const vec& axis) { + return m * rotate4(angle, axis); + } + + // rotate_x + template < typename T > [[nodiscard]] constexpr mat rotate_x(T angle) { /// REFERENCE: @@ -340,6 +362,18 @@ namespace vmath_hpp return m * rotate_x(angle); } + template < typename T > + [[nodiscard]] constexpr mat rotate4_x(T angle) { + return mat(rotate_x(angle)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate4_x(const mat& m, T angle) { + return m * rotate4_x(angle); + } + + // rotate_y + template < typename T > [[nodiscard]] constexpr mat rotate_y(T angle) { /// REFERENCE: @@ -358,6 +392,18 @@ namespace vmath_hpp return m * rotate_y(angle); } + template < typename T > + [[nodiscard]] constexpr mat rotate4_y(T angle) { + return mat(rotate_y(angle)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate4_y(const mat& m, T angle) { + return m * rotate4_y(angle); + } + + // rotate_z + template < typename T > [[nodiscard]] constexpr mat rotate_z(T angle) { /// REFERENCE: @@ -376,6 +422,16 @@ namespace vmath_hpp return m * rotate_z(angle); } + template < typename T > + [[nodiscard]] constexpr mat rotate4_z(T angle) { + return mat(rotate_z(angle)); + } + + template < typename T > + [[nodiscard]] constexpr mat rotate4_z(const mat& 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 scale4(const vec& 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(scale(v)); } template < typename T > @@ -570,8 +619,6 @@ namespace vmath_hpp return m * scale(v); } - // scale3 - template < typename T > [[nodiscard]] constexpr mat scale3(const vec& v) { return mat(scale(v)); @@ -608,60 +655,6 @@ namespace vmath_hpp [[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: - /// https://en.wikipedia.org/wiki/Shear_matrix - - return { - { T{1}, T{0} }, - { x, T{1} }}; - } - - template < typename T > - [[nodiscard]] constexpr mat shear_x(const mat& m, T x) { - 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: - /// https://en.wikipedia.org/wiki/Shear_matrix - - return { - { T{1}, y }, - { T{0}, T{1} }}; - } - - template < typename T > - [[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 bc69284..694204e 100644 --- a/untests/vmath_ext_tests.cpp +++ b/untests/vmath_ext_tests.cpp @@ -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)); diff --git a/untests/vmath_fix_tests.cpp b/untests/vmath_fix_tests.cpp index 73faddf..8c786df 100644 --- a/untests/vmath_fix_tests.cpp +++ b/untests/vmath_fix_tests.cpp @@ -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, const fix3f&); template fix3x3f rotate(const fix3x3f&, fix, const fix3f&); + template fix4x4f rotate4(fix, const fix3f&); + template fix4x4f rotate4(const fix4x4f&, fix, const fix3f&); template fix3x3f rotate_x(fix); template fix3x3f rotate_x(const fix3x3f&, fix); + template fix4x4f rotate4_x(fix); + template fix4x4f rotate4_x(const fix4x4f&, fix); template fix3x3f rotate_y(fix); template fix3x3f rotate_y(const fix3x3f&, fix); + template fix4x4f rotate4_y(fix); + template fix4x4f rotate4_y(const fix4x4f&, fix); template fix3x3f rotate_z(fix); template fix3x3f rotate_z(const fix3x3f&, fix); + template fix4x4f rotate4_z(fix); + template fix4x4f rotate4_z(const fix4x4f&, fix); 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); - 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); } //