diff --git a/matrix.cpp b/matrix.cpp index 7c10857a..7d3bdf01 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -301,7 +301,7 @@ matrix::look_at (util::point<3,T> eye, { 0, 0, 0, 1 } }}; - return util::matrix4::translation (-eye.template as ()) * rot; + return rot * util::matrix4::translation (-eye.template as ()); } diff --git a/test/affine.cpp b/test/affine.cpp index 66c3159a..4ecd4dfa 100644 --- a/test/affine.cpp +++ b/test/affine.cpp @@ -5,6 +5,40 @@ #include "quaternion.hpp" +/////////////////////////////////////////////////////////////////////////////// +void +test_matrix_identities (util::TAP::logger &tap) +{ + static constexpr util::vector3f UP {0,1,0}; + + { + util::point3f p { 1, 2, 3 }; + + auto m = util::matrix4f::translation (0-p); + auto x = m * p.homog<4> (); + tap.expect_eq (x, util::point4f {0,0,0,1}, "trivial translation"); + } + + { + util::point3f eye { 1, 2, 3 }; + util::point3f tgt { 0, 0, 0 }; + + auto m = util::matrix4f::look_at (eye, tgt, UP); + auto x = m * eye.homog<4> (); + tap.expect_eq (x, util::point4f {0,0,0,1}, "look_at eye translation"); + } + + { + util::point3f eye { 1, 2, 3 }; + util::point3f tgt { 4, 5, 6 }; + + auto m = util::matrix4f::look_at (eye, tgt, UP); + auto x = m * eye.homog<4> (); + tap.expect_eq (x, util::point4f {0,0,0,1}, "look_at eye translation with target"); + } +} + + /////////////////////////////////////////////////////////////////////////////// void test_mq_axis (util::TAP::logger &tap) @@ -66,6 +100,7 @@ main (int, char**) { util::TAP::logger tap; + test_matrix_identities (tap); test_mq_axis (tap); test_mq_euler (tap);