Changeset 1318


Ignore:
Timestamp:
Apr 30, 2012, 3:40:54 PM (10 years ago)
Author:
sam
Message:

test: add several unit tests for rotations with matrices and quaternions.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1294 r1318  
    2525    unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \
    2626    unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \
    27     unit/array.cpp
     27    unit/array.cpp unit/rotation.cpp
    2828testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
    2929testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
  • trunk/test/unit/quat.cpp

    r1305 r1318  
    2727    LOLUNIT_TEST(Equality)
    2828    {
    29         quat a4(1.0f, 2.0f, 3.0f, 4.0f);
    30         quat b4(0.0f, 2.0f, 3.0f, 4.0f);
    31         quat c4(1.0f, 0.0f, 3.0f, 4.0f);
    32         quat d4(1.0f, 2.0f, 0.0f, 4.0f);
    33         quat e4(1.0f, 2.0f, 3.0f, 0.0f);
     29        quat a4(1.f, 2.f, 3.f, 4.f);
     30        quat b4(0.f, 2.f, 3.f, 4.f);
     31        quat c4(1.f, 0.f, 3.f, 4.f);
     32        quat d4(1.f, 2.f, 0.f, 4.f);
     33        quat e4(1.f, 2.f, 3.f, 0.f);
    3434
    3535        LOLUNIT_ASSERT_EQUAL(a4, a4);
     
    4848    LOLUNIT_TEST(UnaryMinus)
    4949    {
    50         quat a(1.0f, 3.0f, 2.0f, 4.0f);
    51         quat b(-1.0f, -3.0f, -2.0f, -4.0f);
     50        quat a(1.f, 3.f, 2.f, 4.f);
     51        quat b(-1.f, -3.f, -2.f, -4.f);
    5252
    5353        LOLUNIT_ASSERT_EQUAL(a, -b);
     
    5757    LOLUNIT_TEST(Conjugate)
    5858    {
    59         quat a(1.0f, 3.0f, 2.0f, 4.0f);
    60         quat b(1.0f, -3.0f, -2.0f, -4.0f);
     59        quat a(1.f, 3.f, 2.f, 4.f);
     60        quat b(1.f, -3.f, -2.f, -4.f);
    6161
    6262        LOLUNIT_ASSERT_EQUAL(a, ~b);
     
    6666    LOLUNIT_TEST(Norm)
    6767    {
    68         quat a(2.0f, -2.0f, -8.0f, 3.0f);
     68        quat a(2.f, -2.f, -8.f, 3.f);
    6969
    70         LOLUNIT_ASSERT_EQUAL(norm(a), 81.0f);
     70        LOLUNIT_ASSERT_EQUAL(norm(a), 81.f);
    7171
    7272        quat b = a * ~a;
    73         quat c(norm(a), 0.0f, 0.0f, 0.0f);
     73        quat c(norm(a), 0.f, 0.f, 0.f);
    7474
    7575        LOLUNIT_ASSERT_EQUAL(b, c);
    7676
    77         quat d(2.0f, 3.0f, -4.0f, -1.0f);
     77        quat d(2.f, 3.f, -4.f, -1.f);
    7878
    7979        LOLUNIT_ASSERT_EQUAL(norm(a * d), norm(a) * norm(d));
     
    8282    LOLUNIT_TEST(Base)
    8383    {
    84         quat i(0.0f, 1.0f, 0.0f, 0.0f);
    85         quat j(0.0f, 0.0f, 1.0f, 0.0f);
    86         quat k(0.0f, 0.0f, 0.0f, 1.0f);
    87         quat one(1.0f, 0.0f, 0.0f, 0.0f);
     84        quat one(1.f, 0.f, 0.f, 0.f);
     85        quat i(0.f, 1.f, 0.f, 0.f);
     86        quat j(0.f, 0.f, 1.f, 0.f);
     87        quat k(0.f, 0.f, 0.f, 1.f);
    8888
    89         LOLUNIT_ASSERT_EQUAL(norm(i), 1.0f);
    90         LOLUNIT_ASSERT_EQUAL(norm(j), 1.0f);
    91         LOLUNIT_ASSERT_EQUAL(norm(k), 1.0f);
    92         LOLUNIT_ASSERT_EQUAL(norm(one), 1.0f);
     89        LOLUNIT_ASSERT_EQUAL(norm(one), 1.f);
     90        LOLUNIT_ASSERT_EQUAL(norm(i), 1.f);
     91        LOLUNIT_ASSERT_EQUAL(norm(j), 1.f);
     92        LOLUNIT_ASSERT_EQUAL(norm(k), 1.f);
    9393
    9494        LOLUNIT_ASSERT_EQUAL(i * i, -one);
     
    107107    LOLUNIT_TEST(Normalize)
    108108    {
    109         quat a(2.0f, -2.0f, -8.0f, 3.0f);
     109        quat a(2.f, -2.f, -8.f, 3.f);
    110110        quat b = normalize(a);
    111111
    112         LOLUNIT_ASSERT_DOUBLES_EQUAL(norm(b), 1.0, 1e-8);
     112        LOLUNIT_ASSERT_DOUBLES_EQUAL(norm(b), 1.0, 1e-5);
    113113    }
    114114
    115115    LOLUNIT_TEST(Reciprocal)
    116116    {
    117         quat a(2.0f, -2.0f, -8.0f, 3.0f);
     117        quat a(2.f, -2.f, -8.f, 3.f);
    118118        quat b = re(a);
    119119
    120120        quat m1 = a * b;
    121121        quat m2 = b * a;
    122         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, m2.x, 1e-8);
    123         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, m2.y, 1e-8);
    124         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, m2.z, 1e-8);
    125         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, m2.w, 1e-8);
     122        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, m2.w, 1e-5);
     123        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, m2.x, 1e-5);
     124        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, m2.y, 1e-5);
     125        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, m2.z, 1e-5);
    126126
    127         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, 0.0, 1e-8);
    128         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, 0.0, 1e-8);
    129         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, 0.0, 1e-8);
    130         LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, 1.0, 1e-8);
     127        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, 1.0, 1e-5);
     128        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.x, 0.0, 1e-5);
     129        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.y, 0.0, 1e-5);
     130        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.z, 0.0, 1e-5);
    131131    }
    132132
    133133    LOLUNIT_TEST(Rotation)
    134134    {
    135         quat a = quat::rotate(10.0f, vec3(1, 0, 0));
    136         quat b = quat::rotate(20.0f, vec3(1, 0, 0));
     135        /* Check that rotating 10 degrees twice means rotating 20 degrees */
     136        quat a = quat::rotate(10.f, vec3(1, 0, 0));
     137        quat b = quat::rotate(20.f, vec3(1, 0, 0));
    137138        quat c = a * a;
    138139
    139         LOLUNIT_ASSERT_DOUBLES_EQUAL(a.w, a.w, 1e-8);
    140         LOLUNIT_ASSERT_DOUBLES_EQUAL(a.x, a.x, 1e-8);
    141         LOLUNIT_ASSERT_DOUBLES_EQUAL(a.y, a.y, 1e-8);
    142         LOLUNIT_ASSERT_DOUBLES_EQUAL(a.z, a.z, 1e-8);
     140        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.w, b.w, 1e-5);
     141        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.x, b.x, 1e-5);
     142        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.y, b.y, 1e-5);
     143        LOLUNIT_ASSERT_DOUBLES_EQUAL(c.z, b.z, 1e-5);
     144
     145        /* Check that rotating 10 degrees then 20 is the same as 20 then 10 */
     146        quat d = a * b;
     147        quat e = b * a;
     148
     149        LOLUNIT_ASSERT_DOUBLES_EQUAL(e.w, d.w, 1e-5);
     150        LOLUNIT_ASSERT_DOUBLES_EQUAL(e.x, d.x, 1e-5);
     151        LOLUNIT_ASSERT_DOUBLES_EQUAL(e.y, d.y, 1e-5);
     152        LOLUNIT_ASSERT_DOUBLES_EQUAL(e.z, d.z, 1e-5);
    143153    }
    144154};
  • trunk/win32/testsuite.vcxproj

    r1294 r1318  
    3737    <ClCompile Include="..\test\unit\quat.cpp" />
    3838    <ClCompile Include="..\test\unit\real.cpp" />
     39    <ClCompile Include="..\test\unit\rotation.cpp" />
    3940    <ClCompile Include="..\test\unit\trig.cpp" />
    4041    <ClCompile Include="..\test\unit\vector.cpp" />
Note: See TracChangeset for help on using the changeset viewer.