Procházet zdrojové kódy

math: add unit tests for quat::rotate(vec3, vec3).

undefined
Sam Hocevar před 11 roky
rodič
revize
c6e453fe5c
2 změnil soubory, kde provedl 26 přidání a 1 odebrání
  1. +2
    -0
      src/math/vector.cpp
  2. +24
    -1
      test/unit/quat.cpp

+ 2
- 0
src/math/vector.cpp Zobrazit soubor

@@ -504,7 +504,9 @@ template<> quat quat::rotate(float degrees, float x, float y, float z)
template<> quat quat::rotate(vec3 const &src, vec3 const &dst)
{
vec3 v = cross(src, dst);
v.printf();
float d = dot(src, dst) + lol::sqrt(sqlength(src) * sqlength(dst));
fprintf(stderr, "%f + %f = %f\n", dot(src, dst), lol::sqrt(sqlength(src) * sqlength(dst)), d);

return normalize(quat(d, v.x, v.y, v.z));
}


+ 24
- 1
test/unit/quat.cpp Zobrazit soubor

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
@@ -165,6 +165,29 @@ LOLUNIT_FIXTURE(QuaternionTest)
LOLUNIT_ASSERT_DOUBLES_EQUAL(e.y, d.y, 1e-5);
LOLUNIT_ASSERT_DOUBLES_EQUAL(e.z, d.z, 1e-5);
}

LOLUNIT_TEST(FromTwoVectors)
{
vec3 a(1.f, 2.f, 3.f);
vec3 b(4.f, 5.f, 6.f);
float ratio = length(a) / length(b);

quat q = quat::rotate(a, b);

/* Check that q transforms a into b */
vec3 c = q.transform(a);

LOLUNIT_ASSERT_DOUBLES_EQUAL(c.x, b.x * ratio, 1e-5);
LOLUNIT_ASSERT_DOUBLES_EQUAL(c.y, b.y * ratio, 1e-5);
LOLUNIT_ASSERT_DOUBLES_EQUAL(c.z, b.z * ratio, 1e-5);

/* Check that ~q transforms b into a */
vec3 d = (~q).transform(b);

LOLUNIT_ASSERT_DOUBLES_EQUAL(d.x, a.x / ratio, 1e-5);
LOLUNIT_ASSERT_DOUBLES_EQUAL(d.y, a.y / ratio, 1e-5);
LOLUNIT_ASSERT_DOUBLES_EQUAL(d.z, a.z / ratio, 1e-5);
}
};

} /* namespace lol */


Načítá se…
Zrušit
Uložit