aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/m3math_tut.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:56 -0500
committerJacek Antonelli2008-08-15 23:44:56 -0500
commitc07901e29ed545bbb02e3bddf148fe1104b94e9f (patch)
treef1ada64ce834acd7d92a425efb96c4b86bcf16b1 /linden/indra/test/m3math_tut.cpp
parentSecond Life viewer sources 1.15.0.2 (diff)
downloadmeta-impy-c07901e29ed545bbb02e3bddf148fe1104b94e9f.zip
meta-impy-c07901e29ed545bbb02e3bddf148fe1104b94e9f.tar.gz
meta-impy-c07901e29ed545bbb02e3bddf148fe1104b94e9f.tar.bz2
meta-impy-c07901e29ed545bbb02e3bddf148fe1104b94e9f.tar.xz
Second Life viewer sources 1.15.1.3
Diffstat (limited to '')
-rw-r--r--linden/indra/test/m3math_tut.cpp320
1 files changed, 320 insertions, 0 deletions
diff --git a/linden/indra/test/m3math_tut.cpp b/linden/indra/test/m3math_tut.cpp
new file mode 100644
index 0000000..62ad365
--- /dev/null
+++ b/linden/indra/test/m3math_tut.cpp
@@ -0,0 +1,320 @@
1/**
2 * @file m3math_tut.cpp
3 * @author Adroit
4 * @date March 2007
5 * @brief Test cases of m3math.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 "lltut.h"
33#include "linden_common.h"
34#include "m3math.h"
35#include "v3math.h"
36#include "v4math.h"
37#include "m4math.h"
38#include "llquaternion.h"
39#include "v3dmath.h"
40
41namespace tut
42{
43 struct m3math_test
44 {
45 };
46 typedef test_group<m3math_test> m3math_test_t;
47 typedef m3math_test_t::object m3math_test_object_t;
48 tut::m3math_test_t tut_m3math_test("m3math_test");
49
50 //test case for identity() fn.
51 template<> template<>
52 void m3math_test_object_t::test<1>()
53 {
54 LLMatrix3 llmat3_obj;
55 llmat3_obj.identity();
56 ensure("LLMatrix3::identity failed", 1.f == llmat3_obj.mMatrix[0][0] &&
57 0.f == llmat3_obj.mMatrix[0][1] &&
58 0.f == llmat3_obj.mMatrix[0][2] &&
59 0.f == llmat3_obj.mMatrix[1][0] &&
60 1.f == llmat3_obj.mMatrix[1][1] &&
61 0.f == llmat3_obj.mMatrix[1][2] &&
62 0.f == llmat3_obj.mMatrix[2][0] &&
63 0.f == llmat3_obj.mMatrix[2][1] &&
64 1.f == llmat3_obj.mMatrix[2][2]);
65 }
66
67 //test case for LLMatrix3& zero() fn.
68 template<> template<>
69 void m3math_test_object_t::test<2>()
70 {
71 LLMatrix3 llmat3_obj(30, 1, 2, 3);
72 llmat3_obj.zero();
73
74 ensure("LLMatrix3::zero failed", 0.f == llmat3_obj.zero().mMatrix[0][0] &&
75 0.f == llmat3_obj.zero().mMatrix[0][1] &&
76 0.f == llmat3_obj.zero().mMatrix[0][2] &&
77 0.f == llmat3_obj.zero().mMatrix[1][0] &&
78 0.f == llmat3_obj.zero().mMatrix[1][1] &&
79 0.f == llmat3_obj.zero().mMatrix[1][2] &&
80 0.f == llmat3_obj.zero().mMatrix[2][0] &&
81 0.f == llmat3_obj.zero().mMatrix[2][1] &&
82 0.f == llmat3_obj.zero().mMatrix[2][2]);
83 }
84
85 //test case for setRows(const LLVector3 &x_axis, const LLVector3 &y_axis, const LLVector3 &z_axis) fns.
86 template<> template<>
87 void m3math_test_object_t::test<3>()
88 {
89 LLMatrix3 llmat3_obj;
90 LLVector3 vect1(2, 1, 4);
91 LLVector3 vect2(3, 5, 7);
92 LLVector3 vect3(6, 9, 7);
93 llmat3_obj.setRows(vect1, vect2, vect3);
94 ensure("LLVector3::setRows failed ", 2 == llmat3_obj.mMatrix[0][0] &&
95 1 == llmat3_obj.mMatrix[0][1] &&
96 4 == llmat3_obj.mMatrix[0][2] &&
97 3 == llmat3_obj.mMatrix[1][0] &&
98 5 == llmat3_obj.mMatrix[1][1] &&
99 7 == llmat3_obj.mMatrix[1][2] &&
100 6 == llmat3_obj.mMatrix[2][0] &&
101 9 == llmat3_obj.mMatrix[2][1] &&
102 7 == llmat3_obj.mMatrix[2][2]);
103 }
104
105 //test case for getFwdRow(), getLeftRow(), getUpRow() fns.
106 template<> template<>
107 void m3math_test_object_t::test<4>()
108 {
109 LLMatrix3 llmat3_obj;
110 LLVector3 vect1(2, 1, 4);
111 LLVector3 vect2(3, 5, 7);
112 LLVector3 vect3(6, 9, 7);
113 llmat3_obj.setRows(vect1, vect2, vect3);
114
115 ensure("LLVector3::getFwdRow failed ", vect1 == llmat3_obj.getFwdRow());
116 ensure("LLVector3::getLeftRow failed ", vect2 == llmat3_obj.getLeftRow());
117 ensure("LLVector3::getUpRow failed ", vect3 == llmat3_obj.getUpRow());
118 }
119
120 //test case for operator*(const LLMatrix3 &a, const LLMatrix3 &b)
121 template<> template<>
122 void m3math_test_object_t::test<5>()
123 {
124 LLMatrix3 llmat_obj1;
125 LLMatrix3 llmat_obj2;
126 LLMatrix3 llmat_obj3;
127
128 LLVector3 llvec1(1, 3, 5);
129 LLVector3 llvec2(3, 6, 1);
130 LLVector3 llvec3(4, 6, 9);
131
132 LLVector3 llvec4(1, 1, 5);
133 LLVector3 llvec5(3, 6, 8);
134 LLVector3 llvec6(8, 6, 2);
135
136 LLVector3 llvec7(0, 0, 0);
137 LLVector3 llvec8(0, 0, 0);
138 LLVector3 llvec9(0, 0, 0);
139
140 llmat_obj1.setRows(llvec1, llvec2, llvec3);
141 llmat_obj2.setRows(llvec4, llvec5, llvec6);
142 llmat_obj3.setRows(llvec7, llvec8, llvec9);
143 llmat_obj3 = llmat_obj1 * llmat_obj2;
144 ensure("LLMatrix3::operator*(const LLMatrix3 &a, const LLMatrix3 &b) failed",
145 50 == llmat_obj3.mMatrix[0][0] &&
146 49 == llmat_obj3.mMatrix[0][1] &&
147 39 == llmat_obj3.mMatrix[0][2] &&
148 29 == llmat_obj3.mMatrix[1][0] &&
149 45 == llmat_obj3.mMatrix[1][1] &&
150 65 == llmat_obj3.mMatrix[1][2] &&
151 94 == llmat_obj3.mMatrix[2][0] &&
152 94 == llmat_obj3.mMatrix[2][1] &&
153 86 == llmat_obj3.mMatrix[2][2]);
154 }
155
156
157 //test case for operator*(const LLVector3 &a, const LLMatrix3 &b)
158 template<> template<>
159 void m3math_test_object_t::test<6>()
160 {
161
162 LLMatrix3 llmat_obj1;
163
164 LLVector3 llvec(1, 3, 5);
165 LLVector3 res_vec(0, 0, 0);
166 LLVector3 llvec1(1, 3, 5);
167 LLVector3 llvec2(3, 6, 1);
168 LLVector3 llvec3(4, 6, 9);
169
170 llmat_obj1.setRows(llvec1, llvec2, llvec3);
171 res_vec = llvec * llmat_obj1;
172
173 LLVector3 expected_result(30, 51, 53);
174
175 ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", res_vec == expected_result);
176 }
177
178 //test case for operator*(const LLVector3d &a, const LLMatrix3 &b)
179 template<> template<>
180 void m3math_test_object_t::test<7>()
181 {
182 LLMatrix3 llmat_obj1;
183 LLVector3d llvec3d1;
184 LLVector3d llvec3d2(0, 3, 4);
185
186 LLVector3 llvec1(1, 3, 5);
187 LLVector3 llvec2(3, 2, 1);
188 LLVector3 llvec3(4, 6, 0);
189
190 llmat_obj1.setRows(llvec1, llvec2, llvec3);
191 llvec3d1 = llvec3d2 * llmat_obj1;
192
193 LLVector3d expected_result(25, 30, 3);
194
195 ensure("LLMatrix3::operator*(const LLVector3 &a, const LLMatrix3 &b) failed", llvec3d1 == expected_result);
196 }
197
198 // test case for operator==(const LLMatrix3 &a, const LLMatrix3 &b)
199 template<> template<>
200 void m3math_test_object_t::test<8>()
201 {
202 LLMatrix3 llmat_obj1;
203 LLMatrix3 llmat_obj2;
204
205 LLVector3 llvec1(1, 3, 5);
206 LLVector3 llvec2(3, 6, 1);
207 LLVector3 llvec3(4, 6, 9);
208
209 llmat_obj1.setRows(llvec1, llvec2, llvec3);
210 llmat_obj2.setRows(llvec1, llvec2, llvec3);
211 ensure("LLMatrix3::operator==(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 == llmat_obj2);
212
213 llmat_obj2.setRows(llvec2, llvec2, llvec3);
214 ensure("LLMatrix3::operator!=(const LLMatrix3 &a, const LLMatrix3 &b) failed", llmat_obj1 != llmat_obj2);
215 }
216
217 //test case for quaternion() fn.
218 template<> template<>
219 void m3math_test_object_t::test<9>()
220 {
221 LLMatrix3 llmat_obj1;
222 LLQuaternion llmat_quat;
223
224 LLVector3 llmat1(2.0f, 1.0f, 6.0f);
225 LLVector3 llmat2(1.0f, 1.0f, 3.0f);
226 LLVector3 llmat3(1.0f, 7.0f, 5.0f);
227
228 llmat_obj1.setRows(llmat1, llmat2, llmat3);
229 llmat_quat = llmat_obj1.quaternion();
230 ensure("LLMatrix3::quaternion failed ", is_approx_equal(-0.66666669f, llmat_quat.mQ[0]) &&
231 is_approx_equal(-0.83333337f, llmat_quat.mQ[1]) &&
232 is_approx_equal(0.0f, llmat_quat.mQ[2]) &&
233 is_approx_equal(1.5f, llmat_quat.mQ[3]));
234 }
235
236 //test case for transpose() fn.
237 template<> template<>
238 void m3math_test_object_t::test<10>()
239 {
240 LLMatrix3 llmat_obj;
241
242 LLVector3 llvec1(1, 2, 3);
243 LLVector3 llvec2(3, 2, 1);
244 LLVector3 llvec3(2, 2, 2);
245
246 llmat_obj.setRows(llvec1, llvec2, llvec3);
247 llmat_obj.transpose();
248
249 LLVector3 resllvec1(1, 3, 2);
250 LLVector3 resllvec2(2, 2, 2);
251 LLVector3 resllvec3(3, 1, 2);
252 LLMatrix3 expectedllmat_obj;
253 expectedllmat_obj.setRows(resllvec1, resllvec2, resllvec3);
254
255 ensure("LLMatrix3::transpose failed ", llmat_obj == expectedllmat_obj);
256 }
257
258 //test case for determinant() fn.
259 template<> template<>
260 void m3math_test_object_t::test<11>()
261 {
262 LLMatrix3 llmat_obj1;
263
264 LLVector3 llvec1(1, 2, 3);
265 LLVector3 llvec2(3, 2, 1);
266 LLVector3 llvec3(2, 2, 2);
267 llmat_obj1.setRows(llvec1, llvec2, llvec3);
268 ensure("LLMatrix3::determinant failed ", 0.0f == llmat_obj1.determinant());
269 }
270
271 //test case for orthogonalize() fn.
272 template<> template<>
273 void m3math_test_object_t::test<12>()
274 {
275 LLMatrix3 llmat_obj;
276
277 LLVector3 llvec1(1, 4, 3);
278 LLVector3 llvec2(1, 2, 0);
279 LLVector3 llvec3(2, 4, 2);
280
281 llmat_obj.setRows(llvec1, llvec2, llvec3);
282 llmat_obj.orthogonalize();
283
284 ensure("LLMatrix3::orthogonalize failed ", is_approx_equal(0.19611613f, llmat_obj.mMatrix[0][0]) &&
285 is_approx_equal(0.78446454f, llmat_obj.mMatrix[0][1]) &&
286 is_approx_equal(0.58834839f, llmat_obj.mMatrix[0][2]) &&
287 is_approx_equal(0.47628206f, llmat_obj.mMatrix[1][0]) &&
288 is_approx_equal(0.44826555f, llmat_obj.mMatrix[1][1]) &&
289 is_approx_equal(-0.75644791f, llmat_obj.mMatrix[1][2]) &&
290 is_approx_equal(-0.85714287f, llmat_obj.mMatrix[2][0]) &&
291 is_approx_equal(0.42857143f, llmat_obj.mMatrix[2][1]) &&
292 is_approx_equal(-0.28571427f, llmat_obj.mMatrix[2][2]));
293 }
294
295 //test case for adjointTranspose() fn.
296 template<> template<>
297 void m3math_test_object_t::test<13>()
298 {
299 LLMatrix3 llmat_obj;
300
301 LLVector3 llvec1(3, 2, 1);
302 LLVector3 llvec2(6, 2, 1);
303 LLVector3 llvec3(3, 6, 8);
304
305 llmat_obj.setRows(llvec1, llvec2, llvec3);
306 llmat_obj.adjointTranspose();
307
308 ensure("LLMatrix3::adjointTranspose failed ", 10 == llmat_obj.mMatrix[0][0] &&
309 -45 == llmat_obj.mMatrix[1][0] &&
310 30 == llmat_obj.mMatrix[2][0] &&
311 -10 == llmat_obj.mMatrix[0][1] &&
312 21 == llmat_obj.mMatrix[1][1] &&
313 -12 == llmat_obj.mMatrix[2][1] &&
314 0 == llmat_obj.mMatrix[0][2] &&
315 3 == llmat_obj.mMatrix[1][2] &&
316 -6 == llmat_obj.mMatrix[2][2]);
317 }
318
319 /* TBD: Need to add test cases for getEulerAngles() and setRot() functions */
320}