diff options
author | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
commit | d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch) | |
tree | 7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/llquaternion_tut.cpp | |
parent | Second Life viewer sources 1.17.3.0 (diff) | |
download | meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2 meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz |
Second Life viewer sources 1.18.0.6
Diffstat (limited to 'linden/indra/test/llquaternion_tut.cpp')
-rw-r--r-- | linden/indra/test/llquaternion_tut.cpp | 665 |
1 files changed, 665 insertions, 0 deletions
diff --git a/linden/indra/test/llquaternion_tut.cpp b/linden/indra/test/llquaternion_tut.cpp new file mode 100644 index 0000000..f64e87a --- /dev/null +++ b/linden/indra/test/llquaternion_tut.cpp | |||
@@ -0,0 +1,665 @@ | |||
1 | /** | ||
2 | * @file llquaternion_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief Test cases of llquaternion.h | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "llmath.h" | ||
33 | #include "lltut.h" | ||
34 | #include "linden_common.h" | ||
35 | #include "llquaternion.h" | ||
36 | #include "v4math.h" | ||
37 | #include "v3math.h" | ||
38 | #include "v3dmath.h" | ||
39 | #include "m4math.h" | ||
40 | #include "m3math.h" | ||
41 | #include "math.h" | ||
42 | |||
43 | namespace tut | ||
44 | { | ||
45 | struct llquat_test | ||
46 | { | ||
47 | }; | ||
48 | typedef test_group<llquat_test> llquat_test_t; | ||
49 | typedef llquat_test_t::object llquat_test_object_t; | ||
50 | tut::llquat_test_t tut_llquat_test("llquat"); | ||
51 | |||
52 | //test case for LLQuaternion::LLQuaternion(void) fn. | ||
53 | template<> template<> | ||
54 | void llquat_test_object_t::test<1>() | ||
55 | { | ||
56 | LLQuaternion llquat; | ||
57 | ensure("LLQuaternion::LLQuaternion() failed", 0.f == llquat.mQ[0] && | ||
58 | 0.f == llquat.mQ[1] && | ||
59 | 0.f == llquat.mQ[2] && | ||
60 | 1.f == llquat.mQ[3]); | ||
61 | } | ||
62 | |||
63 | //test case for explicit LLQuaternion(const LLMatrix4 &mat) fn. | ||
64 | template<> template<> | ||
65 | void llquat_test_object_t::test<2>() | ||
66 | { | ||
67 | LLMatrix4 llmat; | ||
68 | LLVector4 vector1(2.0f, 1.0f, 3.0f, 6.0f); | ||
69 | LLVector4 vector2(5.0f, 6.0f, 0.0f, 1.0f); | ||
70 | LLVector4 vector3(2.0f, 1.0f, 2.0f, 9.0f); | ||
71 | LLVector4 vector4(3.0f, 8.0f, 1.0f, 5.0f); | ||
72 | |||
73 | llmat.initRows(vector1, vector2, vector3, vector4); | ||
74 | ensure("explicit LLQuaternion(const LLMatrix4 &mat) failed", 2.0f == llmat.mMatrix[0][0] && | ||
75 | 1.0f == llmat.mMatrix[0][1] && | ||
76 | 3.0f == llmat.mMatrix[0][2] && | ||
77 | 6.0f == llmat.mMatrix[0][3] && | ||
78 | 5.0f == llmat.mMatrix[1][0] && | ||
79 | 6.0f == llmat.mMatrix[1][1] && | ||
80 | 0.0f == llmat.mMatrix[1][2] && | ||
81 | 1.0f == llmat.mMatrix[1][3] && | ||
82 | 2.0f == llmat.mMatrix[2][0] && | ||
83 | 1.0f == llmat.mMatrix[2][1] && | ||
84 | 2.0f == llmat.mMatrix[2][2] && | ||
85 | 9.0f == llmat.mMatrix[2][3] && | ||
86 | 3.0f == llmat.mMatrix[3][0] && | ||
87 | 8.0f == llmat.mMatrix[3][1] && | ||
88 | 1.0f == llmat.mMatrix[3][2] && | ||
89 | 5.0f == llmat.mMatrix[3][3]); | ||
90 | } | ||
91 | |||
92 | template<> template<> | ||
93 | void llquat_test_object_t::test<3>() | ||
94 | { | ||
95 | LLMatrix3 llmat; | ||
96 | |||
97 | LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f); | ||
98 | LLVector3 vect2(741.434f, 23.00034f, 6567.223423f); | ||
99 | LLVector3 vect3(566.003034f, 12.98705f, 234.764423f); | ||
100 | llmat.setRows(vect1, vect2, vect3); | ||
101 | |||
102 | ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] && | ||
103 | 234.56f == llmat.mMatrix[0][1] && | ||
104 | 4234.442234f == llmat.mMatrix[0][2] && | ||
105 | 741.434f == llmat.mMatrix[1][0] && | ||
106 | 23.00034f == llmat.mMatrix[1][1] && | ||
107 | 6567.223423f == llmat.mMatrix[1][2] && | ||
108 | 566.003034f == llmat.mMatrix[2][0] && | ||
109 | 12.98705f == llmat.mMatrix[2][1] && | ||
110 | 234.764423f == llmat.mMatrix[2][2]); | ||
111 | } | ||
112 | |||
113 | //test case for LLQuaternion(F32 x, F32 y, F32 z, F32 w), setQuatInit() and normQuat() fns. | ||
114 | template<> template<> | ||
115 | void llquat_test_object_t::test<4>() | ||
116 | { | ||
117 | F32 x_val = 3.0f; | ||
118 | F32 y_val = 2.0f; | ||
119 | F32 z_val = 6.0f; | ||
120 | F32 w_val = 1.0f; | ||
121 | |||
122 | LLQuaternion res_quat; | ||
123 | res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
124 | res_quat.normQuat(); | ||
125 | |||
126 | ensure("LLQuaternion::normQuat() fn failed", | ||
127 | is_approx_equal(0.42426407f, res_quat.mQ[0]) && | ||
128 | is_approx_equal(0.28284273f, res_quat.mQ[1]) && | ||
129 | is_approx_equal(0.84852815f, res_quat.mQ[2]) && | ||
130 | is_approx_equal(0.14142136f, res_quat.mQ[3])); | ||
131 | |||
132 | x_val = 0.0f; | ||
133 | y_val = 0.0f; | ||
134 | z_val = 0.0f; | ||
135 | w_val = 0.0f; | ||
136 | |||
137 | res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
138 | res_quat.normQuat(); | ||
139 | |||
140 | ensure("LLQuaternion::normQuat() fn. failed.", | ||
141 | is_approx_equal(0.0f, res_quat.mQ[0]) && | ||
142 | is_approx_equal(0.0f, res_quat.mQ[1]) && | ||
143 | is_approx_equal(0.0f, res_quat.mQ[2]) && | ||
144 | is_approx_equal(1.0f, res_quat.mQ[3])); | ||
145 | |||
146 | |||
147 | ensure("LLQuaternion::normQuat() fn. failed.", | ||
148 | is_approx_equal(0.0f, res_quat.mQ[0]) && | ||
149 | is_approx_equal(0.0f, res_quat.mQ[1]) && | ||
150 | is_approx_equal(0.0f, res_quat.mQ[2]) && | ||
151 | is_approx_equal(1.0f, res_quat.mQ[3])); | ||
152 | } | ||
153 | |||
154 | //test case for conjQuat() and transQuat() fns. | ||
155 | template<> template<> | ||
156 | void llquat_test_object_t::test<5>() | ||
157 | { | ||
158 | F32 x_val = 3.0f; | ||
159 | F32 y_val = 2.0f; | ||
160 | F32 z_val = 6.0f; | ||
161 | F32 w_val = 1.0f; | ||
162 | |||
163 | LLQuaternion res_quat; | ||
164 | LLQuaternion result, result1; | ||
165 | result1 = result = res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
166 | |||
167 | result.conjQuat(); | ||
168 | result1.transQuat(); | ||
169 | |||
170 | ensure("LLQuaternion::conjQuat and LLQuaternion::transQuat failed ", | ||
171 | is_approx_equal(result1.mQ[0], result.mQ[0]) && | ||
172 | is_approx_equal(result1.mQ[1], result.mQ[1]) && | ||
173 | is_approx_equal(result1.mQ[2], result.mQ[2])); | ||
174 | |||
175 | } | ||
176 | |||
177 | //test case for dot(const LLQuaternion &a, const LLQuaternion &b) fn. | ||
178 | template<> template<> | ||
179 | void llquat_test_object_t::test<6>() | ||
180 | { | ||
181 | LLQuaternion quat1(3.0f, 2.0f, 6.0f, 0.0f), quat2(1.0f, 1.0f, 1.0f, 1.0f); | ||
182 | ensure("1. The two values are different", llround(12.000000f, 2) == llround(dot(quat1, quat2), 2)); | ||
183 | |||
184 | LLQuaternion quat0(3.0f, 9.334f, 34.5f, 23.0f), quat(34.5f, 23.23f, 2.0f, 45.5f); | ||
185 | ensure("2. The two values are different", llround(1435.828807f, 2) == llround(dot(quat0, quat), 2)); | ||
186 | } | ||
187 | |||
188 | //test case for LLQuaternion &LLQuaternion::constrain(F32 radians) fn. | ||
189 | template<> template<> | ||
190 | void llquat_test_object_t::test<7>() | ||
191 | { | ||
192 | F32 radian = 60.0f; | ||
193 | LLQuaternion quat(3.0f, 2.0f, 6.0f, 0.0f); | ||
194 | LLQuaternion quat1; | ||
195 | quat1 = quat.constrain(radian); | ||
196 | ensure("1. LLQuaternion::constrain(F32 radians) failed", | ||
197 | is_approx_equal_fraction(-0.423442f, quat1.mQ[0], 8) && | ||
198 | is_approx_equal_fraction(-0.282295f, quat1.mQ[1], 8) && | ||
199 | is_approx_equal_fraction(-0.846884f, quat1.mQ[2], 8) && | ||
200 | is_approx_equal_fraction(0.154251f, quat1.mQ[3], 8)); | ||
201 | |||
202 | |||
203 | radian = 30.0f; | ||
204 | LLQuaternion quat0(37.50f, 12.0f, 86.023f, 40.32f); | ||
205 | quat1 = quat0.constrain(radian); | ||
206 | |||
207 | ensure("2. LLQuaternion::constrain(F32 radians) failed", | ||
208 | is_approx_equal_fraction(37.500000f, quat1.mQ[0], 8) && | ||
209 | is_approx_equal_fraction(12.0000f, quat1.mQ[1], 8) && | ||
210 | is_approx_equal_fraction(86.0230f, quat1.mQ[2], 8) && | ||
211 | is_approx_equal_fraction(40.320000f, quat1.mQ[3], 8)); | ||
212 | } | ||
213 | |||
214 | template<> template<> | ||
215 | void llquat_test_object_t::test<8>() | ||
216 | { | ||
217 | F32 value1 = 15.0f; | ||
218 | LLQuaternion quat1(1.0f, 2.0f, 4.0f, 1.0f); | ||
219 | LLQuaternion quat2(4.0f, 3.0f, 6.5f, 9.7f); | ||
220 | LLQuaternion res_lerp, res_slerp, res_nlerp; | ||
221 | |||
222 | //test case for lerp(F32 t, const LLQuaternion &q) fn. | ||
223 | res_lerp = lerp(value1, quat1); | ||
224 | ensure("1. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", | ||
225 | is_approx_equal_fraction(0.181355f, res_lerp.mQ[0], 16) && | ||
226 | is_approx_equal_fraction(0.362711f, res_lerp.mQ[1], 16) && | ||
227 | is_approx_equal_fraction(0.725423f, res_lerp.mQ[2], 16) && | ||
228 | is_approx_equal_fraction(0.556158f, res_lerp.mQ[3], 16)); | ||
229 | |||
230 | //test case for lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) fn. | ||
231 | res_lerp = lerp(value1, quat1, quat2); | ||
232 | ensure("2. LLQuaternion lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) failed", | ||
233 | is_approx_equal_fraction(0.314306f, res_lerp.mQ[0], 16) && | ||
234 | is_approx_equal_fraction(0.116156f, res_lerp.mQ[1], 16) && | ||
235 | is_approx_equal_fraction(0.283559f, res_lerp.mQ[2], 16) && | ||
236 | is_approx_equal_fraction(0.898506f, res_lerp.mQ[3], 16)); | ||
237 | |||
238 | //test case for slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b ) fn. | ||
239 | res_slerp = slerp(value1, quat1, quat2); | ||
240 | ensure("3. LLQuaternion slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b) failed", | ||
241 | is_approx_equal_fraction(46.000f, res_slerp.mQ[0], 16) && | ||
242 | is_approx_equal_fraction(17.00f, res_slerp.mQ[1], 16) && | ||
243 | is_approx_equal_fraction(41.5f, res_slerp.mQ[2], 16) && | ||
244 | is_approx_equal_fraction(131.5f, res_slerp.mQ[3], 16)); | ||
245 | |||
246 | //test case for nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) fn. | ||
247 | res_nlerp = nlerp(value1, quat1, quat2); | ||
248 | ensure("4. LLQuaternion nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) failed", | ||
249 | is_approx_equal_fraction(0.314306f, res_nlerp.mQ[0], 16) && | ||
250 | is_approx_equal_fraction(0.116157f, res_nlerp.mQ[1], 16) && | ||
251 | is_approx_equal_fraction(0.283559f, res_nlerp.mQ[2], 16) && | ||
252 | is_approx_equal_fraction(0.898506f, res_nlerp.mQ[3], 16)); | ||
253 | |||
254 | //test case for nlerp(F32 t, const LLQuaternion &q) fn. | ||
255 | res_slerp = slerp(value1, quat1); | ||
256 | ensure("5. LLQuaternion slerp(F32 t, const LLQuaternion &q) failed", | ||
257 | is_approx_equal_fraction(1.0f, res_slerp.mQ[0], 16) && | ||
258 | is_approx_equal_fraction(2.0f, res_slerp.mQ[1], 16) && | ||
259 | is_approx_equal_fraction(4.0000f, res_slerp.mQ[2], 16) && | ||
260 | is_approx_equal_fraction(1.000f, res_slerp.mQ[3], 16)); | ||
261 | |||
262 | LLQuaternion quat3(2.0f, 1.0f, 5.5f, 10.5f); | ||
263 | LLQuaternion res_nlerp1; | ||
264 | value1 = 100.0f; | ||
265 | res_nlerp1 = nlerp(value1, quat3); | ||
266 | ensure("6. LLQuaternion nlerp(F32 t, const LLQuaternion &q) failed", | ||
267 | is_approx_equal_fraction(0.268245f, res_nlerp1.mQ[0], 16) && is_approx_equal_fraction(0.134122f, res_nlerp1.mQ[1], 2) && | ||
268 | is_approx_equal_fraction(0.737673f, res_nlerp1.mQ[2], 16) && | ||
269 | is_approx_equal_fraction(0.604892f, res_nlerp1.mQ[3], 16)); | ||
270 | |||
271 | //test case for lerp(F32 t, const LLQuaternion &q) fn. | ||
272 | res_lerp = lerp(value1, quat2); | ||
273 | ensure("7. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", | ||
274 | is_approx_equal_fraction(0.404867f, res_lerp.mQ[0], 16) && | ||
275 | is_approx_equal_fraction(0.303650f, res_lerp.mQ[1], 16) && | ||
276 | is_approx_equal_fraction(0.657909f, res_lerp.mQ[2], 16) && | ||
277 | is_approx_equal_fraction(0.557704f, res_lerp.mQ[3], 16)); | ||
278 | |||
279 | } | ||
280 | |||
281 | template<> template<> | ||
282 | void llquat_test_object_t::test<9>() | ||
283 | { | ||
284 | //test case for LLQuaternion operator*(const LLQuaternion &a, const LLQuaternion &b) fn | ||
285 | LLQuaternion quat1(1.0f, 2.5f, 3.5f, 5.5f); | ||
286 | LLQuaternion quat2(4.0f, 3.0f, 5.0f, 1.0f); | ||
287 | LLQuaternion result = quat1 * quat2; | ||
288 | ensure("1. LLQuaternion Operator* failed", (21.0f == result.mQ[0]) && | ||
289 | (10.0f == result.mQ[1]) && | ||
290 | (38.0f == result.mQ[2]) && | ||
291 | (-23.5f == result.mQ[3])); | ||
292 | |||
293 | LLQuaternion quat3(2341.340f, 2352.345f, 233.25f, 7645.5f); | ||
294 | LLQuaternion quat4(674.067f, 893.0897f, 578.0f, 231.0f); | ||
295 | result = quat3 * quat4; | ||
296 | ensure("2. LLQuaternion Operator* failed", (4543086.5f == result.mQ[0]) && | ||
297 | (8567578.0f == result.mQ[1]) && | ||
298 | (3967591.25f == result.mQ[2]) && | ||
299 | (-2047783.25f == result.mQ[3])); | ||
300 | |||
301 | //inline LLQuaternion operator+(const LLQuaternion &a, const LLQuaternion &b)fn. | ||
302 | result = quat1 + quat2; | ||
303 | ensure("3. LLQuaternion operator+ failed", (5.0f == result.mQ[0]) && | ||
304 | (5.5f == result.mQ[1]) && | ||
305 | (8.5f == result.mQ[2]) && | ||
306 | (6.5f == result.mQ[3])); | ||
307 | |||
308 | result = quat3 + quat4; | ||
309 | ensure( | ||
310 | "4. LLQuaternion operator+ failed", | ||
311 | is_approx_equal(3015.407227f, result.mQ[0]) && | ||
312 | is_approx_equal(3245.434570f, result.mQ[1]) && | ||
313 | (811.25f == result.mQ[2]) && | ||
314 | (7876.5f == result.mQ[3])); | ||
315 | |||
316 | //inline LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) fn | ||
317 | result = quat1 - quat2; | ||
318 | ensure( | ||
319 | "5. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed", | ||
320 | (-3.0f == result.mQ[0]) && | ||
321 | (-0.5f == result.mQ[1]) && | ||
322 | (-1.5f == result.mQ[2]) && | ||
323 | (4.5f == result.mQ[3])); | ||
324 | |||
325 | result = quat3 - quat4; | ||
326 | ensure( | ||
327 | "6. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed", | ||
328 | is_approx_equal(1667.273071f, result.mQ[0]) && | ||
329 | is_approx_equal(1459.255249f, result.mQ[1]) && | ||
330 | (-344.75f == result.mQ[2]) && | ||
331 | (7414.50f == result.mQ[3])); | ||
332 | } | ||
333 | |||
334 | //test case for LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) fn. | ||
335 | template<> template<> | ||
336 | void llquat_test_object_t::test<10>() | ||
337 | { | ||
338 | #if (LL_RELEASE && LL_LINUX) | ||
339 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
340 | #endif | ||
341 | LLVector4 vect(12.0f, 5.0f, 60.0f, 75.1f); | ||
342 | LLQuaternion quat(2323.034f, 23.5f, 673.23f, 57667.5f); | ||
343 | LLVector4 result = vect * quat; | ||
344 | ensure( | ||
345 | "1. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed", | ||
346 | (39928406016.0f == result.mV[0]) && | ||
347 | (1457801728.0f == result.mV[1]) && | ||
348 | (200580612096.0f == result.mV[2]) && | ||
349 | (75.099998f == result.mV[3])); | ||
350 | |||
351 | LLVector4 vect1(22.0f, 45.0f, 40.0f, 78.1f); | ||
352 | LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f); | ||
353 | result = vect1 * quat1; | ||
354 | ensure( | ||
355 | "2. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed", | ||
356 | is_approx_equal(-58153.5390f, result.mV[0]) && | ||
357 | (183787.8125f == result.mV[1]) && | ||
358 | (116864.164063f == result.mV[2]) && | ||
359 | (78.099998f == result.mV[3])); | ||
360 | } | ||
361 | |||
362 | //test case for LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) fn. | ||
363 | template<> template<> | ||
364 | void llquat_test_object_t::test<11>() | ||
365 | { | ||
366 | LLVector3 vect(12.0f, 5.0f, 60.0f); | ||
367 | LLQuaternion quat(23.5f, 6.5f, 3.23f, 56.5f); | ||
368 | LLVector3 result = vect * quat; | ||
369 | ensure( | ||
370 | "1. LLVEctor3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed", | ||
371 | is_approx_equal(97182.953125f,result.mV[0]) && | ||
372 | is_approx_equal(-135405.640625f, result.mV[1]) && | ||
373 | is_approx_equal(162986.140f, result.mV[2])); | ||
374 | |||
375 | LLVector3 vect1(5.0f, 40.0f, 78.1f); | ||
376 | LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f); | ||
377 | result = vect1 * quat1; | ||
378 | ensure( | ||
379 | "2. LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed", | ||
380 | is_approx_equal(33217.703f, result.mV[0]) && | ||
381 | is_approx_equal(295383.8125f, result.mV[1]) && | ||
382 | is_approx_equal(84718.140f, result.mV[2])); | ||
383 | } | ||
384 | |||
385 | //test case for LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) fn. | ||
386 | template<> template<> | ||
387 | void llquat_test_object_t::test<12>() | ||
388 | { | ||
389 | LLVector3d vect(-2.0f, 5.0f, -6.0f); | ||
390 | LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f); | ||
391 | LLVector3d result = vect * quat; | ||
392 | ensure( | ||
393 | "1. LLVEctor3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ", | ||
394 | (-633.0f == result.mdV[0]) && | ||
395 | (-300.0f == result.mdV[1]) && | ||
396 | (-36.0f == result.mdV[2])); | ||
397 | |||
398 | LLVector3d vect1(5.0f, -4.5f, 8.21f); | ||
399 | LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f); | ||
400 | result = vect1 * quat1; | ||
401 | ensure( | ||
402 | "2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", | ||
403 | is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) && | ||
404 | is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) && | ||
405 | is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8)); | ||
406 | |||
407 | LLVector3d vect2(2.0f, 3.5f, 1.1f); | ||
408 | LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f); | ||
409 | result = vect2 * quat2; | ||
410 | ensure( | ||
411 | "3. LLvector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", | ||
412 | is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) && | ||
413 | is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) && | ||
414 | is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8)); | ||
415 | } | ||
416 | |||
417 | //test case for inline LLQuaternion operator-(const LLQuaternion &a) fn. | ||
418 | template<> template<> | ||
419 | void llquat_test_object_t::test<13>() | ||
420 | { | ||
421 | LLQuaternion quat(23.5f, 34.5f, 16723.4f, 324.7f); | ||
422 | LLQuaternion result = -quat; | ||
423 | ensure( | ||
424 | "1. LLQuaternion operator-(const LLQuaternion &a) failed", | ||
425 | (-23.5f == result.mQ[0]) && | ||
426 | (-34.5f == result.mQ[1]) && | ||
427 | (-16723.4f == result.mQ[2]) && | ||
428 | (-324.7f == result.mQ[3])); | ||
429 | |||
430 | LLQuaternion quat1(-3.5f, -34.5f, -16.4f, -154.7f); | ||
431 | result = -quat1; | ||
432 | ensure( | ||
433 | "2. LLQuaternion operator-(const LLQuaternion &a) failed.", | ||
434 | (3.5f == result.mQ[0]) && | ||
435 | (34.5f == result.mQ[1]) && | ||
436 | (16.4f == result.mQ[2]) && | ||
437 | (154.7f == result.mQ[3])); | ||
438 | } | ||
439 | |||
440 | //test case for inline LLQuaternion operator*(F32 a, const LLQuaternion &q) and | ||
441 | //inline LLQuaternion operator*(F32 a, const LLQuaternion &q) fns. | ||
442 | template<> template<> | ||
443 | void llquat_test_object_t::test<14>() | ||
444 | { | ||
445 | LLQuaternion quat_value(9.0f, 8.0f, 7.0f, 6.0f); | ||
446 | F32 a =3.5f; | ||
447 | LLQuaternion result = a * quat_value; | ||
448 | LLQuaternion result1 = quat_value * a; | ||
449 | |||
450 | ensure( | ||
451 | "1. LLQuaternion operator* failed", | ||
452 | (result.mQ[0] == result1.mQ[0]) && | ||
453 | (result.mQ[1] == result1.mQ[1]) && | ||
454 | (result.mQ[2] == result1.mQ[2]) && | ||
455 | (result.mQ[3] == result1.mQ[3])); | ||
456 | |||
457 | |||
458 | LLQuaternion quat_val(9454.0f, 43568.3450f, 456343247.0343f, 2346.03434f); | ||
459 | a =-3324.3445f; | ||
460 | result = a * quat_val; | ||
461 | result1 = quat_val * a; | ||
462 | |||
463 | ensure( | ||
464 | "2. LLQuaternion operator* failed", | ||
465 | (result.mQ[0] == result1.mQ[0]) && | ||
466 | (result.mQ[1] == result1.mQ[1]) && | ||
467 | (result.mQ[2] == result1.mQ[2]) && | ||
468 | (result.mQ[3] == result1.mQ[3])); | ||
469 | } | ||
470 | |||
471 | template<> template<> | ||
472 | void llquat_test_object_t::test<15>() | ||
473 | { | ||
474 | // test cases for inline LLQuaternion operator~(const LLQuaternion &a) | ||
475 | LLQuaternion quat_val(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
476 | LLQuaternion result = ~quat_val; | ||
477 | ensure( | ||
478 | "1. LLQuaternion operator~(const LLQuaternion &a) failed ", | ||
479 | (-2323.634f == result.mQ[0]) && | ||
480 | (43535.4f == result.mQ[1]) && | ||
481 | (-3455.88f == result.mQ[2]) && | ||
482 | (-32232.45f == result.mQ[3])); | ||
483 | |||
484 | //test case for inline bool LLQuaternion::operator==(const LLQuaternion &b) const | ||
485 | LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
486 | LLQuaternion quat_val2(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
487 | ensure( | ||
488 | "2. LLQuaternion::operator==(const LLQuaternion &b) failed", | ||
489 | quat_val1 == quat_val2); | ||
490 | } | ||
491 | |||
492 | template<> template<> | ||
493 | void llquat_test_object_t::test<16>() | ||
494 | { | ||
495 | //test case for inline bool LLQuaternion::operator!=(const LLQuaternion &b) const | ||
496 | LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
497 | LLQuaternion quat_val2(0, -43535.4f, 3455.88f, -32232.45f); | ||
498 | ensure("LLQuaternion::operator!=(const LLQuaternion &b) failed", quat_val1 != quat_val2); | ||
499 | } | ||
500 | |||
501 | template<> template<> | ||
502 | void llquat_test_object_t::test<17>() | ||
503 | { | ||
504 | //test case for LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) | ||
505 | F32 x = 2.0f; | ||
506 | F32 y = 1.0f; | ||
507 | F32 z = 3.0f; | ||
508 | |||
509 | LLQuaternion result = mayaQ(x, y, z, LLQuaternion::XYZ); | ||
510 | ensure( | ||
511 | "1. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ", | ||
512 | is_approx_equal_fraction(0.0172174f, result.mQ[0], 16) && | ||
513 | is_approx_equal_fraction(0.009179f, result.mQ[1], 16) && | ||
514 | is_approx_equal_fraction(0.026020f, result.mQ[2], 16) && | ||
515 | is_approx_equal_fraction(0.999471f, result.mQ[3], 16)); | ||
516 | |||
517 | LLQuaternion result1 = mayaQ(x, y, z, LLQuaternion::YZX); | ||
518 | ensure( | ||
519 | "2. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ", | ||
520 | is_approx_equal_fraction(0.017217f, result1.mQ[0], 16) && | ||
521 | is_approx_equal_fraction(0.008265f, result1.mQ[1], 16) && | ||
522 | is_approx_equal_fraction(0.026324f, result1.mQ[2], 16) && | ||
523 | is_approx_equal_fraction(0.999471f, result1.mQ[3], 16)); | ||
524 | |||
525 | LLQuaternion result2 = mayaQ(x, y, z, LLQuaternion::ZXY); | ||
526 | ensure( | ||
527 | "3. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZXY", | ||
528 | is_approx_equal_fraction(0.017674f, result2.mQ[0], 16) && | ||
529 | is_approx_equal_fraction(0.008265f, result2.mQ[1], 16) && | ||
530 | is_approx_equal_fraction(0.026020f, result2.mQ[2], 16) && | ||
531 | is_approx_equal_fraction(0.999471f, result2.mQ[3], 16)); | ||
532 | |||
533 | LLQuaternion result3 = mayaQ(x, y, z, LLQuaternion::XZY); | ||
534 | ensure( | ||
535 | "4. TLLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XZY", | ||
536 | is_approx_equal_fraction(0.017674f, result3.mQ[0], 16) && | ||
537 | is_approx_equal_fraction(0.009179f, result3.mQ[1], 16) && | ||
538 | is_approx_equal_fraction(0.026020f, result3.mQ[2], 16) && | ||
539 | is_approx_equal_fraction(0.999463f, result3.mQ[3], 16)); | ||
540 | |||
541 | LLQuaternion result4 = mayaQ(x, y, z, LLQuaternion::YXZ); | ||
542 | ensure( | ||
543 | "5. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for YXZ", | ||
544 | is_approx_equal_fraction(0.017217f, result4.mQ[0], 16) && | ||
545 | is_approx_equal_fraction(0.009179f, result4.mQ[1], 16) && | ||
546 | is_approx_equal_fraction(0.026324f, result4.mQ[2], 16) && | ||
547 | is_approx_equal_fraction(0.999463f, result4.mQ[3], 16)); | ||
548 | |||
549 | LLQuaternion result5 = mayaQ(x, y, z, LLQuaternion::ZYX); | ||
550 | ensure( | ||
551 | "6. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZYX", | ||
552 | is_approx_equal_fraction(0.017674f, result5.mQ[0], 16) && | ||
553 | is_approx_equal_fraction(0.008265f, result5.mQ[1], 16) && | ||
554 | is_approx_equal_fraction(0.026324f, result5.mQ[2], 16) && | ||
555 | is_approx_equal_fraction(0.999463f, result5.mQ[3], 16)); | ||
556 | } | ||
557 | |||
558 | template<> template<> | ||
559 | void llquat_test_object_t::test<18>() | ||
560 | { | ||
561 | // test case for friend std::ostream& operator<<(std::ostream &s, const LLQuaternion &a) fn | ||
562 | LLQuaternion a(1.0f, 1.0f, 1.0f, 1.0f); | ||
563 | std::ostringstream result_value; | ||
564 | result_value << a; | ||
565 | ensure_equals("1. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }"); | ||
566 | |||
567 | LLQuaternion b(-31.034f, 231.2340f, 3451.344320f, -341.0f); | ||
568 | std::ostringstream result_value1; | ||
569 | result_value1 << b; | ||
570 | ensure_equals("2. Operator << failed", result_value1.str(), "{ -31.034, 231.234, 3451.34, -341 }"); | ||
571 | |||
572 | LLQuaternion c(1.0f, 2.2f, 3.3f, 4.4f); | ||
573 | result_value << c; | ||
574 | ensure_equals("3. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }{ 1, 2.2, 3.3, 4.4 }"); | ||
575 | |||
576 | } | ||
577 | |||
578 | template<> template<> | ||
579 | void llquat_test_object_t::test<19>() | ||
580 | { | ||
581 | //test case for const char *OrderToString( const LLQuaternion::Order order ) fn | ||
582 | const char* result = OrderToString(LLQuaternion::XYZ); | ||
583 | ensure("1. OrderToString failed for XYZ", (0 == strcmp("XYZ", result))); | ||
584 | |||
585 | result = OrderToString(LLQuaternion::YZX); | ||
586 | ensure("2. OrderToString failed for YZX", (0 == strcmp("YZX", result))); | ||
587 | |||
588 | result = OrderToString(LLQuaternion::ZXY); | ||
589 | ensure( | ||
590 | "3. OrderToString failed for ZXY", | ||
591 | (0 == strcmp("ZXY", result)) && | ||
592 | (0 != strcmp("XYZ", result)) && | ||
593 | (0 != strcmp("YXZ", result)) && | ||
594 | (0 != strcmp("ZYX", result)) && | ||
595 | (0 != strcmp("XYZ", result))); | ||
596 | |||
597 | result = OrderToString(LLQuaternion::XZY); | ||
598 | ensure("4. OrderToString failed for XZY", (0 == strcmp("XZY", result))); | ||
599 | |||
600 | result = OrderToString(LLQuaternion::ZYX); | ||
601 | ensure("5. OrderToString failed for ZYX", (0 == strcmp("ZYX", result))); | ||
602 | |||
603 | result = OrderToString(LLQuaternion::YXZ); | ||
604 | ensure("6.OrderToString failed for YXZ", (0 == strcmp("YXZ", result))); | ||
605 | } | ||
606 | |||
607 | template<> template<> | ||
608 | void llquat_test_object_t::test<20>() | ||
609 | { | ||
610 | //test case for LLQuaternion::Order StringToOrder( const char *str ) fn | ||
611 | int result = StringToOrder("XYZ"); | ||
612 | ensure("1. LLQuaternion::Order StringToOrder(const char *str ) failed for XYZ", 0 == result); | ||
613 | |||
614 | result = StringToOrder("YZX"); | ||
615 | ensure("2. LLQuaternion::Order StringToOrder(const char *str) failed for YZX", 1 == result); | ||
616 | |||
617 | result = StringToOrder("ZXY"); | ||
618 | ensure("3. LLQuaternion::Order StringToOrder(const char *str) failed for ZXY", 2 == result); | ||
619 | |||
620 | result = StringToOrder("XZY"); | ||
621 | ensure("4. LLQuaternion::Order StringToOrder(const char *str) failed for XZY", 3 == result); | ||
622 | |||
623 | result = StringToOrder("YXZ"); | ||
624 | ensure("5. LLQuaternion::Order StringToOrder(const char *str) failed for YXZ", 4 == result); | ||
625 | |||
626 | result = StringToOrder("ZYX"); | ||
627 | ensure("6. LLQuaternion::Order StringToOrder(const char *str) failed for ZYX", 5 == result); | ||
628 | |||
629 | } | ||
630 | |||
631 | template<> template<> | ||
632 | void llquat_test_object_t::test<21>() | ||
633 | { | ||
634 | //void LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) const fn | ||
635 | F32 angle_value = 90.0f; | ||
636 | LLVector3 vect(12.0f, 4.0f, 1.0f); | ||
637 | LLQuaternion llquat(angle_value, vect); | ||
638 | llquat.getAngleAxis(&angle_value, vect); | ||
639 | ensure( | ||
640 | "LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) failed", | ||
641 | is_approx_equal_fraction(2.035406f, angle_value, 16) && | ||
642 | is_approx_equal_fraction(0.315244f, vect.mV[1], 16) && | ||
643 | is_approx_equal_fraction(0.078811f, vect.mV[2], 16) && | ||
644 | is_approx_equal_fraction(0.945733f, vect.mV[0], 16)); | ||
645 | } | ||
646 | |||
647 | template<> template<> | ||
648 | void llquat_test_object_t::test<22>() | ||
649 | { | ||
650 | //test case for void LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const fn | ||
651 | F32 roll = -12.0f; | ||
652 | F32 pitch = -22.43f; | ||
653 | F32 yaw = 11.0f; | ||
654 | |||
655 | LLQuaternion llquat; | ||
656 | llquat.getEulerAngles(&roll, &pitch, &yaw); | ||
657 | ensure( | ||
658 | "LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) failed", | ||
659 | is_approx_equal(0.000f, llquat.mQ[0]) && | ||
660 | is_approx_equal(0.000f, llquat.mQ[1]) && | ||
661 | is_approx_equal(0.000f, llquat.mQ[2]) && | ||
662 | is_approx_equal(1.000f, llquat.mQ[3])); | ||
663 | } | ||
664 | |||
665 | } | ||