Ignore:
Timestamp:
Apr 29, 2012, 4:01:00 PM (9 years ago)
Author:
sam
Message:

math: chage quaternion constructor to wxyz order because it matches the
mathematical writing, and add static constructors to create quaternions
from a rotation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/quat.cpp

    r1135 r1305  
    5858    {
    5959        quat a(1.0f, 3.0f, 2.0f, 4.0f);
    60         quat b(-1.0f, -3.0f, -2.0f, 4.0f);
     60        quat b(1.0f, -3.0f, -2.0f, -4.0f);
    6161
    6262        LOLUNIT_ASSERT_EQUAL(a, ~b);
     
    7171
    7272        quat b = a * ~a;
    73         quat c(0.0f, 0.0f, 0.0f, norm(a));
     73        quat c(norm(a), 0.0f, 0.0f, 0.0f);
    7474
    7575        LOLUNIT_ASSERT_EQUAL(b, c);
     
    8282    LOLUNIT_TEST(Base)
    8383    {
    84         quat i(1.0f, 0.0f, 0.0f, 0.0f);
    85         quat j(0.0f, 1.0f, 0.0f, 0.0f);
    86         quat k(0.0f, 0.0f, 1.0f, 0.0f);
    87         quat one(0.0f, 0.0f, 0.0f, 1.0f);
     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);
    8888
    8989        LOLUNIT_ASSERT_EQUAL(norm(i), 1.0f);
     
    130130        LOLUNIT_ASSERT_DOUBLES_EQUAL(m1.w, 1.0, 1e-8);
    131131    }
     132
     133    LOLUNIT_TEST(Rotation)
     134    {
     135        quat a = quat::rotate(10.0f, vec3(1, 0, 0));
     136        quat b = quat::rotate(20.0f, vec3(1, 0, 0));
     137        quat c = a * a;
     138
     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);
     143    }
    132144};
    133145
Note: See TracChangeset for help on using the changeset viewer.