matrix: fix look_at multiply ordering

This commit is contained in:
Danny Robson 2016-10-12 22:58:34 +11:00
parent 2c6011394f
commit 1af6ed4ca8
2 changed files with 36 additions and 1 deletions

View File

@ -301,7 +301,7 @@ matrix<S,T>::look_at (util::point<3,T> eye,
{ 0, 0, 0, 1 }
}};
return util::matrix4<T>::translation (-eye.template as<vector> ()) * rot;
return rot * util::matrix4<T>::translation (-eye.template as<vector> ());
}

View File

@ -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);