00001
00034 #include <tut/tut.h>
00035 #include "lltut.h"
00036 #include "linden_common.h"
00037 #include "m3math.h"
00038 #include "v3math.h"
00039 #include "v4math.h"
00040 #include "m4math.h"
00041 #include "llquaternion.h"
00042 #include "v3dmath.h"
00043
00044 namespace tut
00045 {
00046 struct m3math_test
00047 {
00048 };
00049 typedef test_group<m3math_test> m3math_test_t;
00050 typedef m3math_test_t::object m3math_test_object_t;
00051 tut::m3math_test_t tut_m3math_test("m3math_test");
00052
00053
00054 template<> template<>
00055 void m3math_test_object_t::test<1>()
00056 {
00057 LLMatrix3 llmat3_obj;
00058 llmat3_obj.identity();
00059 ensure("LLMatrix3::identity failed", 1.f == llmat3_obj.mMatrix[0][0] &&
00060 0.f == llmat3_obj.mMatrix[0][1] &&
00061 0.f == llmat3_obj.mMatrix[0][2] &&
00062 0.f == llmat3_obj.mMatrix[1][0] &&
00063 1.f == llmat3_obj.mMatrix[1][1] &&
00064 0.f == llmat3_obj.mMatrix[1][2] &&
00065 0.f == llmat3_obj.mMatrix[2][0] &&
00066 0.f == llmat3_obj.mMatrix[2][1] &&
00067 1.f == llmat3_obj.mMatrix[2][2]);
00068 }
00069
00070
00071 template<> template<>
00072 void m3math_test_object_t::test<2>()
00073 {
00074 LLMatrix3 llmat3_obj(30, 1, 2, 3);
00075 llmat3_obj.zero();
00076
00077 ensure("LLMatrix3::zero failed", 0.f == llmat3_obj.zero().mMatrix[0][0] &&
00078 0.f == llmat3_obj.zero().mMatrix[0][1] &&
00079 0.f == llmat3_obj.zero().mMatrix[0][2] &&
00080 0.f == llmat3_obj.zero().mMatrix[1][0] &&
00081 0.f == llmat3_obj.zero().mMatrix[1][1] &&
00082 0.f == llmat3_obj.zero().mMatrix[1][2] &&
00083 0.f == llmat3_obj.zero().mMatrix[2][0] &&
00084 0.f == llmat3_obj.zero().mMatrix[2][1] &&
00085 0.f == llmat3_obj.zero().mMatrix[2][2]);
00086 }
00087
00088
00089 template<> template<>
00090 void m3math_test_object_t::test<3>()
00091 {
00092 LLMatrix3 llmat3_obj;
00093 LLVector3 vect1(2, 1, 4);
00094 LLVector3 vect2(3, 5, 7);
00095 LLVector3 vect3(6, 9, 7);
00096 llmat3_obj.setRows(vect1, vect2, vect3);
00097 ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] &&
00098 1 == llmat3_obj.mMatrix[0][1] &&
00099 4 == llmat3_obj.mMatrix[0][2] &&
00100 3 == llmat3_obj.mMatrix[1][0] &&
00101 5 == llmat3_obj.mMatrix[1][1] &&
00102 7 == llmat3_obj.mMatrix[1][2] &&
00103 6 == llmat3_obj.mMatrix[2][0] &&
00104 9 == llmat3_obj.mMatrix[2][1] &&
00105 7 == llmat3_obj.mMatrix[2][2]);
00106 }
00107
00108
00109 template<> template<>
00110 void m3math_test_object_t::test<4>()
00111 {
00112 LLMatrix3 llmat3_obj;
00113 LLVector3 vect1(2, 1, 4);
00114 LLVector3 vect2(3, 5, 7);
00115 LLVector3 vect3(6, 9, 7);
00116 llmat3_obj.setRows(vect1, vect2, vect3);
00117
00118 ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow());
00119 ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow());
00120 ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow());
00121 }
00122
00123
00124 template<> template<>
00125 void m3math_test_object_t::test<5>()
00126 {
00127 LLMatrix3 llmat_obj1;
00128 LLMatrix3 llmat_obj2;
00129 LLMatrix3 llmat_obj3;
00130
00131 LLVector3 llvec1(1, 3, 5);
00132 LLVector3 llvec2(3, 6, 1);
00133 LLVector3 llvec3(4, 6, 9);
00134
00135 LLVector3 llvec4(1, 1, 5);
00136 LLVector3 llvec5(3, 6, 8);
00137 LLVector3 llvec6(8, 6, 2);
00138
00139 LLVector3 llvec7(0, 0, 0);
00140 LLVector3 llvec8(0, 0, 0);
00141 LLVector3 llvec9(0, 0, 0);
00142
00143 llmat_obj1.setRows(llvec1, llvec2, llvec3);
00144 llmat_obj2.setRows(llvec4, llvec5, llvec6);
00145 llmat_obj3.setRows(llvec7, llvec8, llvec9);
00146 llmat_obj3 = llmat_obj1 * llmat_obj2;
00147 ensure("LLMatrix3::operator*(const LLMatrix3 &a, const LLMatrix3 &b) failed",
00148 50 == llmat_obj3.mMatrix[0][0] &&
00149 49 == llmat_obj3.mMatrix[0][1] &&
00150 39 == llmat_obj3.mMatrix[0][2] &&
00151 29 == llmat_obj3.mMatrix[1][0] &&
00152 45 == llmat_obj3.mMatrix[1][1] &&
00153 65 == llmat_obj3.mMatrix[1][2] &&
00154 94 == llmat_obj3.mMatrix[2][0] &&
00155 94 == llmat_obj3.mMatrix[2][1] &&
00156 86 == llmat_obj3.mMatrix[2][2]);
00157 }
00158
00159
00160
00161 template<> template<>
00162 void m3math_test_object_t::test<6>()
00163 {
00164
00165 LLMatrix3 llmat_obj1;
00166
00167 LLVector3 llvec(1, 3, 5);
00168 LLVector3 res_vec(0, 0, 0);
00169 LLVector3 llvec1(1, 3, 5);
00170 LLVector3 llvec2(3, 6, 1);
00171 LLVector3 llvec3(4, 6, 9);
00172
00173 llmat_obj1.setRows(llvec1, llvec2, llvec3);
00174 res_vec = llvec * llmat_obj1;
00175
00176 LLVector3 expected_result(30, 51, 53);
00177
00178 ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", res_vec == expected_result);
00179 }
00180
00181
00182 template<> template<>
00183 void m3math_test_object_t::test<7>()
00184 {
00185 LLMatrix3 llmat_obj1;
00186 LLVector3d llvec3d1;
00187 LLVector3d llvec3d2(0, 3, 4);
00188
00189 LLVector3 llvec1(1, 3, 5);
00190 LLVector3 llvec2(3, 2, 1);
00191 LLVector3 llvec3(4, 6, 0);
00192
00193 llmat_obj1.setRows(llvec1, llvec2, llvec3);
00194 llvec3d1 = llvec3d2 * llmat_obj1;
00195
00196 LLVector3d expected_result(25, 30, 3);
00197
00198 ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", llvec3d1 == expected_result);
00199 }
00200
00201
00202 template<> template<>
00203 void m3math_test_object_t::test<8>()
00204 {
00205 LLMatrix3 llmat_obj1;
00206 LLMatrix3 llmat_obj2;
00207
00208 LLVector3 llvec1(1, 3, 5);
00209 LLVector3 llvec2(3, 6, 1);
00210 LLVector3 llvec3(4, 6, 9);
00211
00212 llmat_obj1.setRows(llvec1, llvec2, llvec3);
00213 llmat_obj2.setRows(llvec1, llvec2, llvec3);
00214 ensure("LLMatrix3::operator==(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 == llmat_obj2);
00215
00216 llmat_obj2.setRows(llvec2, llvec2, llvec3);
00217 ensure("LLMatrix3::operator!=(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 != llmat_obj2);
00218 }
00219
00220
00221 template<> template<>
00222 void m3math_test_object_t::test<9>()
00223 {
00224 LLMatrix3 llmat_obj1;
00225 LLQuaternion llmat_quat;
00226
00227 LLVector3 llmat1(2.0f, 1.0f, 6.0f);
00228 LLVector3 llmat2(1.0f, 1.0f, 3.0f);
00229 LLVector3 llmat3(1.0f, 7.0f, 5.0f);
00230
00231 llmat_obj1.setRows(llmat1, llmat2, llmat3);
00232 llmat_quat = llmat_obj1.quaternion();
00233 ensure("LLMatrix3::quaternion failed ", is_approx_equal(-0.66666669f, llmat_quat.mQ[0]) &&
00234 is_approx_equal(-0.83333337f, llmat_quat.mQ[1]) &&
00235 is_approx_equal(0.0f, llmat_quat.mQ[2]) &&
00236 is_approx_equal(1.5f, llmat_quat.mQ[3]));
00237 }
00238
00239
00240 template<> template<>
00241 void m3math_test_object_t::test<10>()
00242 {
00243 LLMatrix3 llmat_obj;
00244
00245 LLVector3 llvec1(1, 2, 3);
00246 LLVector3 llvec2(3, 2, 1);
00247 LLVector3 llvec3(2, 2, 2);
00248
00249 llmat_obj.setRows(llvec1, llvec2, llvec3);
00250 llmat_obj.transpose();
00251
00252 LLVector3 resllvec1(1, 3, 2);
00253 LLVector3 resllvec2(2, 2, 2);
00254 LLVector3 resllvec3(3, 1, 2);
00255 LLMatrix3 expectedllmat_obj;
00256 expectedllmat_obj.setRows(resllvec1, resllvec2, resllvec3);
00257
00258 ensure("LLMatrix3::transpose failed ", llmat_obj == expectedllmat_obj);
00259 }
00260
00261
00262 template<> template<>
00263 void m3math_test_object_t::test<11>()
00264 {
00265 LLMatrix3 llmat_obj1;
00266
00267 LLVector3 llvec1(1, 2, 3);
00268 LLVector3 llvec2(3, 2, 1);
00269 LLVector3 llvec3(2, 2, 2);
00270 llmat_obj1.setRows(llvec1, llvec2, llvec3);
00271 ensure("LLMatrix3::determinant failed ", 0.0f == llmat_obj1.determinant());
00272 }
00273
00274
00275 template<> template<>
00276 void m3math_test_object_t::test<12>()
00277 {
00278 LLMatrix3 llmat_obj;
00279
00280 LLVector3 llvec1(1, 4, 3);
00281 LLVector3 llvec2(1, 2, 0);
00282 LLVector3 llvec3(2, 4, 2);
00283
00284 llmat_obj.setRows(llvec1, llvec2, llvec3);
00285 llmat_obj.orthogonalize();
00286
00287 ensure("LLMatrix3::orthogonalize failed ", is_approx_equal(0.19611613f, llmat_obj.mMatrix[0][0]) &&
00288 is_approx_equal(0.78446454f, llmat_obj.mMatrix[0][1]) &&
00289 is_approx_equal(0.58834839f, llmat_obj.mMatrix[0][2]) &&
00290 is_approx_equal(0.47628206f, llmat_obj.mMatrix[1][0]) &&
00291 is_approx_equal(0.44826555f, llmat_obj.mMatrix[1][1]) &&
00292 is_approx_equal(-0.75644791f, llmat_obj.mMatrix[1][2]) &&
00293 is_approx_equal(-0.85714287f, llmat_obj.mMatrix[2][0]) &&
00294 is_approx_equal(0.42857143f, llmat_obj.mMatrix[2][1]) &&
00295 is_approx_equal(-0.28571427f, llmat_obj.mMatrix[2][2]));
00296 }
00297
00298
00299 template<> template<>
00300 void m3math_test_object_t::test<13>()
00301 {
00302 LLMatrix3 llmat_obj;
00303
00304 LLVector3 llvec1(3, 2, 1);
00305 LLVector3 llvec2(6, 2, 1);
00306 LLVector3 llvec3(3, 6, 8);
00307
00308 llmat_obj.setRows(llvec1, llvec2, llvec3);
00309 llmat_obj.adjointTranspose();
00310
00311 ensure("LLMatrix3::adjointTranspose failed ", 10 == llmat_obj.mMatrix[0][0] &&
00312 -45 == llmat_obj.mMatrix[1][0] &&
00313 30 == llmat_obj.mMatrix[2][0] &&
00314 -10 == llmat_obj.mMatrix[0][1] &&
00315 21 == llmat_obj.mMatrix[1][1] &&
00316 -12 == llmat_obj.mMatrix[2][1] &&
00317 0 == llmat_obj.mMatrix[0][2] &&
00318 3 == llmat_obj.mMatrix[1][2] &&
00319 -6 == llmat_obj.mMatrix[2][2]);
00320 }
00321
00322
00323 }