Changeset 2862


Ignore:
Timestamp:
Sep 3, 2013, 10:22:31 PM (6 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/math/vector.cpp

    r2860 r2862  
    505505{
    506506    vec3 v = cross(src, dst);
     507v.printf();
    507508    float d = dot(src, dst) + lol::sqrt(sqlength(src) * sqlength(dst));
     509fprintf(stderr, "%f + %f = %f\n", dot(src, dst), lol::sqrt(sqlength(src) * sqlength(dst)), d);
    508510
    509511    return normalize(quat(d, v.x, v.y, v.z));
  • trunk/test/unit/quat.cpp

    r2852 r2862  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    166166        LOLUNIT_ASSERT_DOUBLES_EQUAL(e.z, d.z, 1e-5);
    167167    }
     168
     169    LOLUNIT_TEST(FromTwoVectors)
     170    {
     171        vec3 a(1.f, 2.f, 3.f);
     172        vec3 b(4.f, 5.f, 6.f);
     173        float ratio = length(a) / length(b);
     174
     175        quat q = quat::rotate(a, b);
     176
     177        /* Check that q transforms a into b */
     178        vec3 c = q.transform(a);
     179
     180        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.x, b.x * ratio, 1e-5);
     181        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.y, b.y * ratio, 1e-5);
     182        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.z, b.z * ratio, 1e-5);
     183
     184        /* Check that ~q transforms b into a */
     185        vec3 d = (~q).transform(b);
     186
     187        LOLUNIT_ASSERT_DOUBLES_EQUAL(d.x, a.x / ratio, 1e-5);
     188        LOLUNIT_ASSERT_DOUBLES_EQUAL(d.y, a.y / ratio, 1e-5);
     189        LOLUNIT_ASSERT_DOUBLES_EQUAL(d.z, a.z / ratio, 1e-5);
     190    }
    168191};
    169192
Note: See TracChangeset for help on using the changeset viewer.