Ignore:
Timestamp:
Apr 21, 2012, 6:58:26 PM (8 years ago)
Author:
sam
Message:

math: add inversion code for 2×2 and 3×3 matrices, and transposition
code for all matrices.

File:
1 edited

Legend:

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

    r1139 r1257  
    2121LOLUNIT_FIXTURE(VectorTest)
    2222{
    23     void SetUp()
    24     {
    25         identity = mat4(1.0f);
    26         triangular = mat4(vec4(1.0f, 0.0f, 0.0f, 0.0f),
    27                           vec4(7.0f, 2.0f, 0.0f, 0.0f),
    28                           vec4(1.0f, 5.0f, 3.0f, 0.0f),
    29                           vec4(8.0f, 9.0f, 2.0f, 4.0f));
    30         invertible = mat4(vec4( 1.0f,  1.0f,  2.0f, -1.0f),
    31                           vec4(-2.0f, -1.0f, -2.0f,  2.0f),
    32                           vec4( 4.0f,  2.0f,  5.0f, -4.0f),
    33                           vec4( 5.0f, -3.0f, -7.0f, -6.0f));
    34     }
     23    void SetUp() {}
    3524
    3625    void TearDown() {}
     
    136125        LOLUNIT_ASSERT_EQUAL(a3, a1);
    137126    }
    138 
    139     LOLUNIT_TEST(MatrixDeterminant)
    140     {
    141         float d1 = triangular.det();
    142         LOLUNIT_ASSERT_EQUAL(d1, 24.0f);
    143         float d2 = invertible.det();
    144         LOLUNIT_ASSERT_EQUAL(d2, -1.0f);
    145     }
    146 
    147     LOLUNIT_TEST(MatrixMultiplication)
    148     {
    149         mat4 m0 = identity;
    150         mat4 m1 = identity;
    151         mat4 m2 = m0 * m1;
    152 
    153         LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f);
    154         LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f);
    155         LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f);
    156         LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f);
    157 
    158         LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f);
    159         LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f);
    160         LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f);
    161         LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f);
    162 
    163         LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f);
    164         LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f);
    165         LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f);
    166         LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f);
    167 
    168         LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f);
    169         LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f);
    170         LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f);
    171         LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f);
    172     }
    173 
    174     LOLUNIT_TEST(MatrixInverse)
    175     {
    176         mat4 m0 = invertible;
    177         mat4 m1 = m0.invert();
    178 
    179         mat4 m2 = m0 * m1;
    180 
    181         LOLUNIT_ASSERT_EQUAL(m2[0][0], 1.0f);
    182         LOLUNIT_ASSERT_EQUAL(m2[1][0], 0.0f);
    183         LOLUNIT_ASSERT_EQUAL(m2[2][0], 0.0f);
    184         LOLUNIT_ASSERT_EQUAL(m2[3][0], 0.0f);
    185 
    186         LOLUNIT_ASSERT_EQUAL(m2[0][1], 0.0f);
    187         LOLUNIT_ASSERT_EQUAL(m2[1][1], 1.0f);
    188         LOLUNIT_ASSERT_EQUAL(m2[2][1], 0.0f);
    189         LOLUNIT_ASSERT_EQUAL(m2[3][1], 0.0f);
    190 
    191         LOLUNIT_ASSERT_EQUAL(m2[0][2], 0.0f);
    192         LOLUNIT_ASSERT_EQUAL(m2[1][2], 0.0f);
    193         LOLUNIT_ASSERT_EQUAL(m2[2][2], 1.0f);
    194         LOLUNIT_ASSERT_EQUAL(m2[3][2], 0.0f);
    195 
    196         LOLUNIT_ASSERT_EQUAL(m2[0][3], 0.0f);
    197         LOLUNIT_ASSERT_EQUAL(m2[1][3], 0.0f);
    198         LOLUNIT_ASSERT_EQUAL(m2[2][3], 0.0f);
    199         LOLUNIT_ASSERT_EQUAL(m2[3][3], 1.0f);
    200     }
    201 
    202     mat4 triangular, identity, invertible;
    203127};
    204128
Note: See TracChangeset for help on using the changeset viewer.