Changeset 3852
 Timestamp:
 Mar 2, 2015, 2:52:24 PM (7 years ago)
 Location:
 trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/matrix.h
r3820 r3852 572 572 573 573 /* 574 * Compute permutation matrix 575 */ 576 577 template<typename T, int N> 578 mat_t<T, N, N> p_matrix(mat_t<T, N, N> const & m) 579 { 580 int used[N]; 581 int order[N]; 582 583 for (int i = 0 ; i < N ; ++i) 584 { 585 used[i] = 0; 586 order[i] = 1; 587 } 588 589 for (int i = 0 ; i < N ; ++i) 590 { 591 int index_max = 1; 592 593 for (int j = 0 ; j < N ; ++j) 594 { 595 while (j < N && used[j]) 596 ++j; 597 598 if (j >= N) 599 break; 600 601 if (index_max == 1  m[i][j] > m[i][index_max]) 602 index_max = j; 603 } 604 605 ASSERT(index_max != 1); 606 ASSERT(index_max < N); 607 608 order[i] = index_max; 609 used[index_max] = 1; 610 } 611 612 mat_t<T, N, N> P; 613 for (int i = 0 ; i < N ; ++i) 614 P[order[i]][i] = 1.0f; 615 616 return P; 617 } 618 619 /* 574 620 * Compute L matrix inverse 575 621 */ 
trunk/src/t/math/matrix.cpp
r3837 r3852 96 96 } 97 97 98 lolunit_declare_test(PMatrixTest) 99 { 100 mat4 m1(vec4(0, 1, 0, 0), 101 vec4(1, 0, 0, 0), 102 vec4(0, 0, 0, 1), 103 vec4(0, 0, 1, 0)); 104 105 mat4 P1 = p_matrix(m1); 106 P1 = P1 * m1; 107 108 for (int i = 0 ; i < 4 ; ++i) 109 { 110 for (int j = 0 ; j < 4 ; ++j) 111 { 112 if (i == j) 113 lolunit_assert_equal(P1[i][j], 1); 114 else 115 lolunit_assert_equal(P1[i][j], 0); 116 } 117 } 118 119 mat4 m2(vec4(0, 1, 0, 0), 120 vec4(0, 0, 1, 0), 121 vec4(0, 0, 0, 1), 122 vec4(1, 0, 0, 0)); 123 124 mat4 P2 = p_matrix(m2); 125 P2 = P2 * m2; 126 127 for (int i = 0 ; i < 4 ; ++i) 128 { 129 for (int j = 0 ; j < 4 ; ++j) 130 { 131 if (i == j) 132 lolunit_assert_equal(P2[i][j], 1); 133 else 134 lolunit_assert_equal(P2[i][j], 0); 135 } 136 } 137 } 138 98 139 #if 0 /* XXX: LU decomposition is currently broken */ 99 140 lolunit_declare_test(lu_decomposition_3x3)
Note: See TracChangeset
for help on using the changeset viewer.