00001
00034 #include <tut/tut.h>
00035
00036 #include "linden_common.h"
00037 #include "lltut.h"
00038 #include "llquaternion.h"
00039 #include "v4math.h"
00040 #include "v3math.h"
00041 #include "v3dmath.h"
00042 #include "m4math.h"
00043 #include "m3math.h"
00044 #include "math.h"
00045
00046 namespace tut
00047 {
00048 struct llquat_test
00049 {
00050 };
00051 typedef test_group<llquat_test> llquat_test_t;
00052 typedef llquat_test_t::object llquat_test_object_t;
00053 tut::llquat_test_t tut_llquat_test("llquat");
00054
00055
00056 template<> template<>
00057 void llquat_test_object_t::test<1>()
00058 {
00059 LLQuaternion llquat;
00060 ensure("LLQuaternion::LLQuaternion() failed", 0.f == llquat.mQ[0] &&
00061 0.f == llquat.mQ[1] &&
00062 0.f == llquat.mQ[2] &&
00063 1.f == llquat.mQ[3]);
00064 }
00065
00066
00067 template<> template<>
00068 void llquat_test_object_t::test<2>()
00069 {
00070 LLMatrix4 llmat;
00071 LLVector4 vector1(2.0f, 1.0f, 3.0f, 6.0f);
00072 LLVector4 vector2(5.0f, 6.0f, 0.0f, 1.0f);
00073 LLVector4 vector3(2.0f, 1.0f, 2.0f, 9.0f);
00074 LLVector4 vector4(3.0f, 8.0f, 1.0f, 5.0f);
00075
00076 llmat.initRows(vector1, vector2, vector3, vector4);
00077 ensure("explicit LLQuaternion(const LLMatrix4 &mat) failed", 2.0f == llmat.mMatrix[0][0] &&
00078 1.0f == llmat.mMatrix[0][1] &&
00079 3.0f == llmat.mMatrix[0][2] &&
00080 6.0f == llmat.mMatrix[0][3] &&
00081 5.0f == llmat.mMatrix[1][0] &&
00082 6.0f == llmat.mMatrix[1][1] &&
00083 0.0f == llmat.mMatrix[1][2] &&
00084 1.0f == llmat.mMatrix[1][3] &&
00085 2.0f == llmat.mMatrix[2][0] &&
00086 1.0f == llmat.mMatrix[2][1] &&
00087 2.0f == llmat.mMatrix[2][2] &&
00088 9.0f == llmat.mMatrix[2][3] &&
00089 3.0f == llmat.mMatrix[3][0] &&
00090 8.0f == llmat.mMatrix[3][1] &&
00091 1.0f == llmat.mMatrix[3][2] &&
00092 5.0f == llmat.mMatrix[3][3]);
00093 }
00094
00095 template<> template<>
00096 void llquat_test_object_t::test<3>()
00097 {
00098 LLMatrix3 llmat;
00099
00100 LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f);
00101 LLVector3 vect2(741.434f, 23.00034f, 6567.223423f);
00102 LLVector3 vect3(566.003034f, 12.98705f, 234.764423f);
00103 llmat.setRows(vect1, vect2, vect3);
00104
00105 ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] &&
00106 234.56f == llmat.mMatrix[0][1] &&
00107 4234.442234f == llmat.mMatrix[0][2] &&
00108 741.434f == llmat.mMatrix[1][0] &&
00109 23.00034f == llmat.mMatrix[1][1] &&
00110 6567.223423f == llmat.mMatrix[1][2] &&
00111 566.003034f == llmat.mMatrix[2][0] &&
00112 12.98705f == llmat.mMatrix[2][1] &&
00113 234.764423f == llmat.mMatrix[2][2]);
00114 }
00115
00116
00117 template<> template<>
00118 void llquat_test_object_t::test<4>()
00119 {
00120 F32 x_val = 3.0f;
00121 F32 y_val = 2.0f;
00122 F32 z_val = 6.0f;
00123 F32 w_val = 1.0f;
00124
00125 LLQuaternion res_quat;
00126 res_quat.setQuatInit(x_val, y_val, z_val, w_val);
00127 res_quat.normQuat();
00128
00129 ensure("LLQuaternion::normQuat() fn failed",
00130 is_approx_equal(0.42426407f, res_quat.mQ[0]) &&
00131 is_approx_equal(0.28284273f, res_quat.mQ[1]) &&
00132 is_approx_equal(0.84852815f, res_quat.mQ[2]) &&
00133 is_approx_equal(0.14142136f, res_quat.mQ[3]));
00134
00135 x_val = 0.0f;
00136 y_val = 0.0f;
00137 z_val = 0.0f;
00138 w_val = 0.0f;
00139
00140 res_quat.setQuatInit(x_val, y_val, z_val, w_val);
00141 res_quat.normQuat();
00142
00143 ensure("LLQuaternion::normQuat() fn. failed.",
00144 is_approx_equal(0.0f, res_quat.mQ[0]) &&
00145 is_approx_equal(0.0f, res_quat.mQ[1]) &&
00146 is_approx_equal(0.0f, res_quat.mQ[2]) &&
00147 is_approx_equal(1.0f, res_quat.mQ[3]));
00148
00149
00150 ensure("LLQuaternion::normQuat() fn. failed.",
00151 is_approx_equal(0.0f, res_quat.mQ[0]) &&
00152 is_approx_equal(0.0f, res_quat.mQ[1]) &&
00153 is_approx_equal(0.0f, res_quat.mQ[2]) &&
00154 is_approx_equal(1.0f, res_quat.mQ[3]));
00155 }
00156
00157
00158 template<> template<>
00159 void llquat_test_object_t::test<5>()
00160 {
00161 F32 x_val = 3.0f;
00162 F32 y_val = 2.0f;
00163 F32 z_val = 6.0f;
00164 F32 w_val = 1.0f;
00165
00166 LLQuaternion res_quat;
00167 LLQuaternion result, result1;
00168 result1 = result = res_quat.setQuatInit(x_val, y_val, z_val, w_val);
00169
00170 result.conjQuat();
00171 result1.transQuat();
00172
00173 ensure("LLQuaternion::conjQuat and LLQuaternion::transQuat failed ",
00174 is_approx_equal(result1.mQ[0], result.mQ[0]) &&
00175 is_approx_equal(result1.mQ[1], result.mQ[1]) &&
00176 is_approx_equal(result1.mQ[2], result.mQ[2]));
00177
00178 }
00179
00180
00181 template<> template<>
00182 void llquat_test_object_t::test<6>()
00183 {
00184 LLQuaternion quat1(3.0f, 2.0f, 6.0f, 0.0f), quat2(1.0f, 1.0f, 1.0f, 1.0f);
00185 ensure("1. The two values are different", llround(12.000000f, 2) == llround(dot(quat1, quat2), 2));
00186
00187 LLQuaternion quat0(3.0f, 9.334f, 34.5f, 23.0f), quat(34.5f, 23.23f, 2.0f, 45.5f);
00188 ensure("2. The two values are different", llround(1435.828807f, 2) == llround(dot(quat0, quat), 2));
00189 }
00190
00191
00192 template<> template<>
00193 void llquat_test_object_t::test<7>()
00194 {
00195 F32 radian = 60.0f;
00196 LLQuaternion quat(3.0f, 2.0f, 6.0f, 0.0f);
00197 LLQuaternion quat1;
00198 quat1 = quat.constrain(radian);
00199 ensure("1. LLQuaternion::constrain(F32 radians) failed",
00200 is_approx_equal_fraction(-0.423442f, quat1.mQ[0], 8) &&
00201 is_approx_equal_fraction(-0.282295f, quat1.mQ[1], 8) &&
00202 is_approx_equal_fraction(-0.846884f, quat1.mQ[2], 8) &&
00203 is_approx_equal_fraction(0.154251f, quat1.mQ[3], 8));
00204
00205
00206 radian = 30.0f;
00207 LLQuaternion quat0(37.50f, 12.0f, 86.023f, 40.32f);
00208 quat1 = quat0.constrain(radian);
00209
00210 ensure("2. LLQuaternion::constrain(F32 radians) failed",
00211 is_approx_equal_fraction(37.500000f, quat1.mQ[0], 8) &&
00212 is_approx_equal_fraction(12.0000f, quat1.mQ[1], 8) &&
00213 is_approx_equal_fraction(86.0230f, quat1.mQ[2], 8) &&
00214 is_approx_equal_fraction(40.320000f, quat1.mQ[3], 8));
00215 }
00216
00217 template<> template<>
00218 void llquat_test_object_t::test<8>()
00219 {
00220 F32 value1 = 15.0f;
00221 LLQuaternion quat1(1.0f, 2.0f, 4.0f, 1.0f);
00222 LLQuaternion quat2(4.0f, 3.0f, 6.5f, 9.7f);
00223 LLQuaternion res_lerp, res_slerp, res_nlerp;
00224
00225
00226 res_lerp = lerp(value1, quat1);
00227 ensure("1. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed",
00228 is_approx_equal_fraction(0.181355f, res_lerp.mQ[0], 16) &&
00229 is_approx_equal_fraction(0.362711f, res_lerp.mQ[1], 16) &&
00230 is_approx_equal_fraction(0.725423f, res_lerp.mQ[2], 16) &&
00231 is_approx_equal_fraction(0.556158f, res_lerp.mQ[3], 16));
00232
00233
00234 res_lerp = lerp(value1, quat1, quat2);
00235 ensure("2. LLQuaternion lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) failed",
00236 is_approx_equal_fraction(0.314306f, res_lerp.mQ[0], 16) &&
00237 is_approx_equal_fraction(0.116156f, res_lerp.mQ[1], 16) &&
00238 is_approx_equal_fraction(0.283559f, res_lerp.mQ[2], 16) &&
00239 is_approx_equal_fraction(0.898506f, res_lerp.mQ[3], 16));
00240
00241
00242 res_slerp = slerp(value1, quat1, quat2);
00243 ensure("3. LLQuaternion slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b) failed",
00244 is_approx_equal_fraction(46.000f, res_slerp.mQ[0], 16) &&
00245 is_approx_equal_fraction(17.00f, res_slerp.mQ[1], 16) &&
00246 is_approx_equal_fraction(41.5f, res_slerp.mQ[2], 16) &&
00247 is_approx_equal_fraction(131.5f, res_slerp.mQ[3], 16));
00248
00249
00250 res_nlerp = nlerp(value1, quat1, quat2);
00251 ensure("4. LLQuaternion nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) failed",
00252 is_approx_equal_fraction(0.314306f, res_nlerp.mQ[0], 16) &&
00253 is_approx_equal_fraction(0.116157f, res_nlerp.mQ[1], 16) &&
00254 is_approx_equal_fraction(0.283559f, res_nlerp.mQ[2], 16) &&
00255 is_approx_equal_fraction(0.898506f, res_nlerp.mQ[3], 16));
00256
00257
00258 res_slerp = slerp(value1, quat1);
00259 ensure("5. LLQuaternion slerp(F32 t, const LLQuaternion &q) failed",
00260 is_approx_equal_fraction(1.0f, res_slerp.mQ[0], 16) &&
00261 is_approx_equal_fraction(2.0f, res_slerp.mQ[1], 16) &&
00262 is_approx_equal_fraction(4.0000f, res_slerp.mQ[2], 16) &&
00263 is_approx_equal_fraction(1.000f, res_slerp.mQ[3], 16));
00264
00265 LLQuaternion quat3(2.0f, 1.0f, 5.5f, 10.5f);
00266 LLQuaternion res_nlerp1;
00267 value1 = 100.0f;
00268 res_nlerp1 = nlerp(value1, quat3);
00269 ensure("6. LLQuaternion nlerp(F32 t, const LLQuaternion &q) failed",
00270 is_approx_equal_fraction(0.268245f, res_nlerp1.mQ[0], 16) && is_approx_equal_fraction(0.134122f, res_nlerp1.mQ[1], 2) &&
00271 is_approx_equal_fraction(0.737673f, res_nlerp1.mQ[2], 16) &&
00272 is_approx_equal_fraction(0.604892f, res_nlerp1.mQ[3], 16));
00273
00274
00275 res_lerp = lerp(value1, quat2);
00276 ensure("7. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed",
00277 is_approx_equal_fraction(0.404867f, res_lerp.mQ[0], 16) &&
00278 is_approx_equal_fraction(0.303650f, res_lerp.mQ[1], 16) &&
00279 is_approx_equal_fraction(0.657909f, res_lerp.mQ[2], 16) &&
00280 is_approx_equal_fraction(0.557704f, res_lerp.mQ[3], 16));
00281
00282 }
00283
00284 template<> template<>
00285 void llquat_test_object_t::test<9>()
00286 {
00287
00288 LLQuaternion quat1(1.0f, 2.5f, 3.5f, 5.5f);
00289 LLQuaternion quat2(4.0f, 3.0f, 5.0f, 1.0f);
00290 LLQuaternion result = quat1 * quat2;
00291 ensure("1. LLQuaternion Operator* failed", (21.0f == result.mQ[0]) &&
00292 (10.0f == result.mQ[1]) &&
00293 (38.0f == result.mQ[2]) &&
00294 (-23.5f == result.mQ[3]));
00295
00296 LLQuaternion quat3(2341.340f, 2352.345f, 233.25f, 7645.5f);
00297 LLQuaternion quat4(674.067f, 893.0897f, 578.0f, 231.0f);
00298 result = quat3 * quat4;
00299 ensure("2. LLQuaternion Operator* failed", (4543086.5f == result.mQ[0]) &&
00300 (8567578.0f == result.mQ[1]) &&
00301 (3967591.25f == result.mQ[2]) &&
00302 (-2047783.25f == result.mQ[3]));
00303
00304
00305 result = quat1 + quat2;
00306 ensure("3. LLQuaternion operator+ failed", (5.0f == result.mQ[0]) &&
00307 (5.5f == result.mQ[1]) &&
00308 (8.5f == result.mQ[2]) &&
00309 (6.5f == result.mQ[3]));
00310
00311 result = quat3 + quat4;
00312 ensure(
00313 "4. LLQuaternion operator+ failed",
00314 is_approx_equal(3015.407227f, result.mQ[0]) &&
00315 is_approx_equal(3245.434570f, result.mQ[1]) &&
00316 (811.25f == result.mQ[2]) &&
00317 (7876.5f == result.mQ[3]));
00318
00319
00320 result = quat1 - quat2;
00321 ensure(
00322 "5. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed",
00323 (-3.0f == result.mQ[0]) &&
00324 (-0.5f == result.mQ[1]) &&
00325 (-1.5f == result.mQ[2]) &&
00326 (4.5f == result.mQ[3]));
00327
00328 result = quat3 - quat4;
00329 ensure(
00330 "6. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed",
00331 is_approx_equal(1667.273071f, result.mQ[0]) &&
00332 is_approx_equal(1459.255249f, result.mQ[1]) &&
00333 (-344.75f == result.mQ[2]) &&
00334 (7414.50f == result.mQ[3]));
00335 }
00336
00337
00338 template<> template<>
00339 void llquat_test_object_t::test<10>()
00340 {
00341 LLVector4 vect(12.0f, 5.0f, 60.0f, 75.1f);
00342 LLQuaternion quat(2323.034f, 23.5f, 673.23f, 57667.5f);
00343 LLVector4 result = vect * quat;
00344 ensure(
00345 "1. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed",
00346 (39928406016.0f == result.mV[0]) &&
00347
00348 (1457802240.0f >= result.mV[1]) &&
00349 (1457801728.0f <= result.mV[1]) &&
00350 (200580612096.0f == result.mV[2]) &&
00351 (75.099998f == result.mV[3]));
00352
00353 LLVector4 vect1(22.0f, 45.0f, 40.0f, 78.1f);
00354 LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f);
00355 result = vect1 * quat1;
00356 ensure(
00357 "2. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed",
00358 is_approx_equal(-58153.5390f, result.mV[0]) &&
00359 (183787.8125f == result.mV[1]) &&
00360 (116864.164063f == result.mV[2]) &&
00361 (78.099998f == result.mV[3]));
00362 }
00363
00364
00365 template<> template<>
00366 void llquat_test_object_t::test<11>()
00367 {
00368 LLVector3 vect(12.0f, 5.0f, 60.0f);
00369 LLQuaternion quat(23.5f, 6.5f, 3.23f, 56.5f);
00370 LLVector3 result = vect * quat;
00371 ensure(
00372 "1. LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed",
00373 is_approx_equal(97182.953125f,result.mV[0]) &&
00374 is_approx_equal(-135405.640625f, result.mV[1]) &&
00375 is_approx_equal(162986.140f, result.mV[2]));
00376
00377 LLVector3 vect1(5.0f, 40.0f, 78.1f);
00378 LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f);
00379 result = vect1 * quat1;
00380 ensure(
00381 "2. LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed",
00382 is_approx_equal(33217.703f, result.mV[0]) &&
00383 is_approx_equal(295383.8125f, result.mV[1]) &&
00384 is_approx_equal(84718.140f, result.mV[2]));
00385 }
00386
00387
00388 template<> template<>
00389 void llquat_test_object_t::test<12>()
00390 {
00391 LLVector3d vect(-2.0f, 5.0f, -6.0f);
00392 LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f);
00393 LLVector3d result = vect * quat;
00394 ensure(
00395 "1. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ",
00396 (-633.0f == result.mdV[0]) &&
00397 (-300.0f == result.mdV[1]) &&
00398 (-36.0f == result.mdV[2]));
00399
00400 LLVector3d vect1(5.0f, -4.5f, 8.21f);
00401 LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f);
00402 result = vect1 * quat1;
00403 ensure(
00404 "2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed",
00405 is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) &&
00406 is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) &&
00407 is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8));
00408
00409 LLVector3d vect2(2.0f, 3.5f, 1.1f);
00410 LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f);
00411 result = vect2 * quat2;
00412 ensure(
00413 "3. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed",
00414 is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) &&
00415 is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) &&
00416 is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8));
00417 }
00418
00419
00420 template<> template<>
00421 void llquat_test_object_t::test<13>()
00422 {
00423 LLQuaternion quat(23.5f, 34.5f, 16723.4f, 324.7f);
00424 LLQuaternion result = -quat;
00425 ensure(
00426 "1. LLQuaternion operator-(const LLQuaternion &a) failed",
00427 (-23.5f == result.mQ[0]) &&
00428 (-34.5f == result.mQ[1]) &&
00429 (-16723.4f == result.mQ[2]) &&
00430 (-324.7f == result.mQ[3]));
00431
00432 LLQuaternion quat1(-3.5f, -34.5f, -16.4f, -154.7f);
00433 result = -quat1;
00434 ensure(
00435 "2. LLQuaternion operator-(const LLQuaternion &a) failed.",
00436 (3.5f == result.mQ[0]) &&
00437 (34.5f == result.mQ[1]) &&
00438 (16.4f == result.mQ[2]) &&
00439 (154.7f == result.mQ[3]));
00440 }
00441
00442
00443
00444 template<> template<>
00445 void llquat_test_object_t::test<14>()
00446 {
00447 LLQuaternion quat_value(9.0f, 8.0f, 7.0f, 6.0f);
00448 F32 a =3.5f;
00449 LLQuaternion result = a * quat_value;
00450 LLQuaternion result1 = quat_value * a;
00451
00452 ensure(
00453 "1. LLQuaternion operator* failed",
00454 (result.mQ[0] == result1.mQ[0]) &&
00455 (result.mQ[1] == result1.mQ[1]) &&
00456 (result.mQ[2] == result1.mQ[2]) &&
00457 (result.mQ[3] == result1.mQ[3]));
00458
00459
00460 LLQuaternion quat_val(9454.0f, 43568.3450f, 456343247.0343f, 2346.03434f);
00461 a =-3324.3445f;
00462 result = a * quat_val;
00463 result1 = quat_val * a;
00464
00465 ensure(
00466 "2. LLQuaternion operator* failed",
00467 (result.mQ[0] == result1.mQ[0]) &&
00468 (result.mQ[1] == result1.mQ[1]) &&
00469 (result.mQ[2] == result1.mQ[2]) &&
00470 (result.mQ[3] == result1.mQ[3]));
00471 }
00472
00473 template<> template<>
00474 void llquat_test_object_t::test<15>()
00475 {
00476
00477 LLQuaternion quat_val(2323.634f, -43535.4f, 3455.88f, -32232.45f);
00478 LLQuaternion result = ~quat_val;
00479 ensure(
00480 "1. LLQuaternion operator~(const LLQuaternion &a) failed ",
00481 (-2323.634f == result.mQ[0]) &&
00482 (43535.4f == result.mQ[1]) &&
00483 (-3455.88f == result.mQ[2]) &&
00484 (-32232.45f == result.mQ[3]));
00485
00486
00487 LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f);
00488 LLQuaternion quat_val2(2323.634f, -43535.4f, 3455.88f, -32232.45f);
00489 ensure(
00490 "2. LLQuaternion::operator==(const LLQuaternion &b) failed",
00491 quat_val1 == quat_val2);
00492 }
00493
00494 template<> template<>
00495 void llquat_test_object_t::test<16>()
00496 {
00497
00498 LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f);
00499 LLQuaternion quat_val2(0, -43535.4f, 3455.88f, -32232.45f);
00500 ensure("LLQuaternion::operator!=(const LLQuaternion &b) failed", quat_val1 != quat_val2);
00501 }
00502
00503 template<> template<>
00504 void llquat_test_object_t::test<17>()
00505 {
00506
00507 F32 x = 2.0f;
00508 F32 y = 1.0f;
00509 F32 z = 3.0f;
00510
00511 LLQuaternion result = mayaQ(x, y, z, LLQuaternion::XYZ);
00512 ensure(
00513 "1. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
00514 is_approx_equal_fraction(0.0172174f, result.mQ[0], 16) &&
00515 is_approx_equal_fraction(0.009179f, result.mQ[1], 16) &&
00516 is_approx_equal_fraction(0.026020f, result.mQ[2], 16) &&
00517 is_approx_equal_fraction(0.999471f, result.mQ[3], 16));
00518
00519 LLQuaternion result1 = mayaQ(x, y, z, LLQuaternion::YZX);
00520 ensure(
00521 "2. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
00522 is_approx_equal_fraction(0.017217f, result1.mQ[0], 16) &&
00523 is_approx_equal_fraction(0.008265f, result1.mQ[1], 16) &&
00524 is_approx_equal_fraction(0.026324f, result1.mQ[2], 16) &&
00525 is_approx_equal_fraction(0.999471f, result1.mQ[3], 16));
00526
00527 LLQuaternion result2 = mayaQ(x, y, z, LLQuaternion::ZXY);
00528 ensure(
00529 "3. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZXY",
00530 is_approx_equal_fraction(0.017674f, result2.mQ[0], 16) &&
00531 is_approx_equal_fraction(0.008265f, result2.mQ[1], 16) &&
00532 is_approx_equal_fraction(0.026020f, result2.mQ[2], 16) &&
00533 is_approx_equal_fraction(0.999471f, result2.mQ[3], 16));
00534
00535 LLQuaternion result3 = mayaQ(x, y, z, LLQuaternion::XZY);
00536 ensure(
00537 "4. TLLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XZY",
00538 is_approx_equal_fraction(0.017674f, result3.mQ[0], 16) &&
00539 is_approx_equal_fraction(0.009179f, result3.mQ[1], 16) &&
00540 is_approx_equal_fraction(0.026020f, result3.mQ[2], 16) &&
00541 is_approx_equal_fraction(0.999463f, result3.mQ[3], 16));
00542
00543 LLQuaternion result4 = mayaQ(x, y, z, LLQuaternion::YXZ);
00544 ensure(
00545 "5. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for YXZ",
00546 is_approx_equal_fraction(0.017217f, result4.mQ[0], 16) &&
00547 is_approx_equal_fraction(0.009179f, result4.mQ[1], 16) &&
00548 is_approx_equal_fraction(0.026324f, result4.mQ[2], 16) &&
00549 is_approx_equal_fraction(0.999463f, result4.mQ[3], 16));
00550
00551 LLQuaternion result5 = mayaQ(x, y, z, LLQuaternion::ZYX);
00552 ensure(
00553 "6. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZYX",
00554 is_approx_equal_fraction(0.017674f, result5.mQ[0], 16) &&
00555 is_approx_equal_fraction(0.008265f, result5.mQ[1], 16) &&
00556 is_approx_equal_fraction(0.026324f, result5.mQ[2], 16) &&
00557 is_approx_equal_fraction(0.999463f, result5.mQ[3], 16));
00558 }
00559
00560 template<> template<>
00561 void llquat_test_object_t::test<18>()
00562 {
00563
00564 LLQuaternion a(1.0f, 1.0f, 1.0f, 1.0f);
00565 std::ostringstream result_value;
00566 result_value << a;
00567 ensure_equals("1. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }");
00568
00569 LLQuaternion b(-31.034f, 231.2340f, 3451.344320f, -341.0f);
00570 std::ostringstream result_value1;
00571 result_value1 << b;
00572 ensure_equals("2. Operator << failed", result_value1.str(), "{ -31.034, 231.234, 3451.34, -341 }");
00573
00574 LLQuaternion c(1.0f, 2.2f, 3.3f, 4.4f);
00575 result_value << c;
00576 ensure_equals("3. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }{ 1, 2.2, 3.3, 4.4 }");
00577
00578 }
00579
00580 template<> template<>
00581 void llquat_test_object_t::test<19>()
00582 {
00583
00584 const char* result = OrderToString(LLQuaternion::XYZ);
00585 ensure("1. OrderToString failed for XYZ", (0 == strcmp("XYZ", result)));
00586
00587 result = OrderToString(LLQuaternion::YZX);
00588 ensure("2. OrderToString failed for YZX", (0 == strcmp("YZX", result)));
00589
00590 result = OrderToString(LLQuaternion::ZXY);
00591 ensure(
00592 "3. OrderToString failed for ZXY",
00593 (0 == strcmp("ZXY", result)) &&
00594 (0 != strcmp("XYZ", result)) &&
00595 (0 != strcmp("YXZ", result)) &&
00596 (0 != strcmp("ZYX", result)) &&
00597 (0 != strcmp("XYZ", result)));
00598
00599 result = OrderToString(LLQuaternion::XZY);
00600 ensure("4. OrderToString failed for XZY", (0 == strcmp("XZY", result)));
00601
00602 result = OrderToString(LLQuaternion::ZYX);
00603 ensure("5. OrderToString failed for ZYX", (0 == strcmp("ZYX", result)));
00604
00605 result = OrderToString(LLQuaternion::YXZ);
00606 ensure("6.OrderToString failed for YXZ", (0 == strcmp("YXZ", result)));
00607 }
00608
00609 template<> template<>
00610 void llquat_test_object_t::test<20>()
00611 {
00612
00613 int result = StringToOrder("XYZ");
00614 ensure("1. LLQuaternion::Order StringToOrder(const char *str ) failed for XYZ", 0 == result);
00615
00616 result = StringToOrder("YZX");
00617 ensure("2. LLQuaternion::Order StringToOrder(const char *str) failed for YZX", 1 == result);
00618
00619 result = StringToOrder("ZXY");
00620 ensure("3. LLQuaternion::Order StringToOrder(const char *str) failed for ZXY", 2 == result);
00621
00622 result = StringToOrder("XZY");
00623 ensure("4. LLQuaternion::Order StringToOrder(const char *str) failed for XZY", 3 == result);
00624
00625 result = StringToOrder("YXZ");
00626 ensure("5. LLQuaternion::Order StringToOrder(const char *str) failed for YXZ", 4 == result);
00627
00628 result = StringToOrder("ZYX");
00629 ensure("6. LLQuaternion::Order StringToOrder(const char *str) failed for ZYX", 5 == result);
00630
00631 }
00632
00633 template<> template<>
00634 void llquat_test_object_t::test<21>()
00635 {
00636
00637 F32 angle_value = 90.0f;
00638 LLVector3 vect(12.0f, 4.0f, 1.0f);
00639 LLQuaternion llquat(angle_value, vect);
00640 llquat.getAngleAxis(&angle_value, vect);
00641 ensure(
00642 "LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) failed",
00643 is_approx_equal_fraction(2.035406f, angle_value, 16) &&
00644 is_approx_equal_fraction(0.315244f, vect.mV[1], 16) &&
00645 is_approx_equal_fraction(0.078811f, vect.mV[2], 16) &&
00646 is_approx_equal_fraction(0.945733f, vect.mV[0], 16));
00647 }
00648
00649 template<> template<>
00650 void llquat_test_object_t::test<22>()
00651 {
00652
00653 F32 roll = -12.0f;
00654 F32 pitch = -22.43f;
00655 F32 yaw = 11.0f;
00656
00657 LLQuaternion llquat;
00658 llquat.getEulerAngles(&roll, &pitch, &yaw);
00659 ensure(
00660 "LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) failed",
00661 is_approx_equal(0.000f, llquat.mQ[0]) &&
00662 is_approx_equal(0.000f, llquat.mQ[1]) &&
00663 is_approx_equal(0.000f, llquat.mQ[2]) &&
00664 is_approx_equal(1.000f, llquat.mQ[3]));
00665 }
00666
00667 }