diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/xform_tut.cpp | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/linden/indra/test/xform_tut.cpp b/linden/indra/test/xform_tut.cpp new file mode 100644 index 0000000..b3bc347 --- /dev/null +++ b/linden/indra/test/xform_tut.cpp | |||
@@ -0,0 +1,247 @@ | |||
1 | /** | ||
2 | * @file xform_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief Test cases for LLXform | ||
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 "xform.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct xform_test | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<xform_test> xform_test_t; | ||
42 | typedef xform_test_t::object xform_test_object_t; | ||
43 | tut::xform_test_t tut_xform_test("xform_test"); | ||
44 | |||
45 | //test case for init(), getParent(), getRotation(), getPositionW(), getWorldRotation() fns. | ||
46 | template<> template<> | ||
47 | void xform_test_object_t::test<1>() | ||
48 | { | ||
49 | LLXform xform_obj; | ||
50 | LLVector3 emptyVec(0.f,0.f,0.f); | ||
51 | LLVector3 initialScaleVec(1.f,1.f,1.f); | ||
52 | |||
53 | ensure("LLXform empty constructor failed: ", !xform_obj.getParent() && !xform_obj.isChanged() && | ||
54 | xform_obj.getPosition() == emptyVec && | ||
55 | (xform_obj.getRotation()).isIdentity() && | ||
56 | xform_obj.getScale() == initialScaleVec && | ||
57 | xform_obj.getPositionW() == emptyVec && | ||
58 | (xform_obj.getWorldRotation()).isIdentity() && | ||
59 | !xform_obj.getScaleChildOffset()); | ||
60 | } | ||
61 | |||
62 | // test cases for | ||
63 | // setScale(const LLVector3& scale) | ||
64 | // setScale(const F32 x, const F32 y, const F32 z) | ||
65 | // setRotation(const F32 x, const F32 y, const F32 z) | ||
66 | // setPosition(const F32 x, const F32 y, const F32 z) | ||
67 | // getLocalMat4(LLMatrix4 &mat) | ||
68 | template<> template<> | ||
69 | void xform_test_object_t::test<2>() | ||
70 | { | ||
71 | LLMatrix4 llmat4; | ||
72 | LLXform xform_obj; | ||
73 | |||
74 | F32 x = 3.6f; | ||
75 | F32 y = 5.5f; | ||
76 | F32 z = 4.2f; | ||
77 | F32 w = 0.f; | ||
78 | F32 posz = z + 2.122f; | ||
79 | LLVector3 vec(x, y, z); | ||
80 | xform_obj.setScale(x, y, z); | ||
81 | xform_obj.setPosition(x, y, posz); | ||
82 | ensure("setScale failed: ", xform_obj.getScale() == vec); | ||
83 | |||
84 | vec.setVec(x, y, posz); | ||
85 | ensure("getPosition failed: ", xform_obj.getPosition() == vec); | ||
86 | |||
87 | x = x * 2.f; | ||
88 | y = y + 2.3f; | ||
89 | z = posz * 4.f; | ||
90 | vec.setVec(x, y, z); | ||
91 | xform_obj.setPositionX(x); | ||
92 | xform_obj.setPositionY(y); | ||
93 | xform_obj.setPositionZ(z); | ||
94 | ensure("setPositionX/Y/Z failed: ", xform_obj.getPosition() == vec); | ||
95 | |||
96 | xform_obj.setScaleChildOffset(TRUE); | ||
97 | ensure("setScaleChildOffset failed: ", xform_obj.getScaleChildOffset()); | ||
98 | |||
99 | vec.setVec(x, y, z); | ||
100 | |||
101 | xform_obj.addPosition(vec); | ||
102 | vec += vec; | ||
103 | ensure("addPosition failed: ", xform_obj.getPosition() == vec); | ||
104 | |||
105 | xform_obj.setScale(vec); | ||
106 | ensure("setScale vector failed: ", xform_obj.getScale() == vec); | ||
107 | |||
108 | LLQuaternion quat(x, y, z, w); | ||
109 | xform_obj.setRotation(quat); | ||
110 | ensure("setRotation quat failed: ", xform_obj.getRotation() == quat); | ||
111 | |||
112 | xform_obj.setRotation(x, y, z, w); | ||
113 | ensure("getRotation 2 failed: ", xform_obj.getRotation() == quat); | ||
114 | |||
115 | xform_obj.setRotation(x, y, z); | ||
116 | quat.setQuat(x,y,z); | ||
117 | ensure("setRotation xyz failed: ", xform_obj.getRotation() == quat); | ||
118 | |||
119 | // LLXform::setRotation(const F32 x, const F32 y, const F32 z) | ||
120 | // Does normalization | ||
121 | // LLXform::setRotation(const F32 x, const F32 y, const F32 z, const F32 s) | ||
122 | // Simply copies the individual values - does not do any normalization. | ||
123 | // Is that the expected behavior? | ||
124 | } | ||
125 | |||
126 | // test cases for inline BOOL setParent(LLXform *parent) and getParent() fn. | ||
127 | template<> template<> | ||
128 | void xform_test_object_t::test<3>() | ||
129 | { | ||
130 | LLXform xform_obj; | ||
131 | LLXform par; | ||
132 | LLXform grandpar; | ||
133 | xform_obj.setParent(&par); | ||
134 | par.setParent(&grandpar); | ||
135 | ensure("setParent/getParent failed: ", &par == xform_obj.getParent()); | ||
136 | ensure("getRoot failed: ", &grandpar == xform_obj.getRoot()); | ||
137 | ensure("isRoot failed: ", grandpar.isRoot() && !par.isRoot() && !xform_obj.isRoot()); | ||
138 | ensure("isRootEdit failed: ", grandpar.isRootEdit() && !par.isRootEdit() && !xform_obj.isRootEdit()); | ||
139 | } | ||
140 | |||
141 | template<> template<> | ||
142 | void xform_test_object_t::test<4>() | ||
143 | { | ||
144 | LLXform xform_obj; | ||
145 | xform_obj.setChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED); | ||
146 | ensure("setChanged/isChanged failed: ", xform_obj.isChanged()); | ||
147 | |||
148 | xform_obj.clearChanged(LLXform::TRANSLATED | LLXform::ROTATED | LLXform::SCALED); | ||
149 | ensure("clearChanged failed: ", !xform_obj.isChanged()); | ||
150 | |||
151 | LLVector3 llvect3(12.4f, -5.6f, 0.34f); | ||
152 | xform_obj.setScale(llvect3); | ||
153 | ensure("setScale did not set SCALED flag: ", xform_obj.isChanged(LLXform::SCALED)); | ||
154 | xform_obj.setPosition(1.2f, 2.3f, 3.4f); | ||
155 | ensure("setScale did not set TRANSLATED flag: ", xform_obj.isChanged(LLXform::TRANSLATED)); | ||
156 | ensure("TRANSLATED reset SCALED flag: ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::SCALED)); | ||
157 | xform_obj.clearChanged(LLXform::SCALED); | ||
158 | ensure("reset SCALED failed: ", !xform_obj.isChanged(LLXform::SCALED)); | ||
159 | xform_obj.setRotation(1, 2, 3, 4); | ||
160 | ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::TRANSLATED | LLXform::ROTATED)); | ||
161 | xform_obj.setScale(llvect3); | ||
162 | ensure("ROTATION flag not set ", xform_obj.isChanged(LLXform::MOVED)); | ||
163 | } | ||
164 | |||
165 | //to test init() and getWorldMatrix() fns. | ||
166 | template<> template<> | ||
167 | void xform_test_object_t::test<5>() | ||
168 | { | ||
169 | LLXformMatrix formMatrix_obj; | ||
170 | formMatrix_obj.init(); | ||
171 | LLMatrix4 mat4_obj; | ||
172 | |||
173 | ensure("1. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[0][0]); | ||
174 | ensure("2. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][1]); | ||
175 | ensure("3. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][2]); | ||
176 | ensure("4. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[0][3]); | ||
177 | ensure("5. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][0]); | ||
178 | ensure("6. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[1][1]); | ||
179 | ensure("7. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][2]); | ||
180 | ensure("8. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[1][3]); | ||
181 | ensure("9. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][0]); | ||
182 | ensure("10. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][1]); | ||
183 | ensure("11. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[2][2]); | ||
184 | ensure("12. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[2][3]); | ||
185 | ensure("13. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][0]); | ||
186 | ensure("14. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][1]); | ||
187 | ensure("15. The value is not NULL", 0.f == formMatrix_obj.getWorldMatrix().mMatrix[3][2]); | ||
188 | ensure("16. The value is not NULL", 1.f == formMatrix_obj.getWorldMatrix().mMatrix[3][3]); | ||
189 | } | ||
190 | |||
191 | //to test mMin.clearVec() and mMax.clearVec() fns | ||
192 | template<> template<> | ||
193 | void xform_test_object_t::test<6>() | ||
194 | { | ||
195 | LLXformMatrix formMatrix_obj; | ||
196 | formMatrix_obj.init(); | ||
197 | LLVector3 llmin_vec3; | ||
198 | LLVector3 llmax_vec3; | ||
199 | formMatrix_obj.getMinMax(llmin_vec3, llmax_vec3); | ||
200 | ensure("1. The value is not NULL", 0.f == llmin_vec3.mV[0]); | ||
201 | ensure("2. The value is not NULL", 0.f == llmin_vec3.mV[1]); | ||
202 | ensure("3. The value is not NULL", 0.f == llmin_vec3.mV[2]); | ||
203 | ensure("4. The value is not NULL", 0.f == llmin_vec3.mV[0]); | ||
204 | ensure("5. The value is not NULL", 0.f == llmin_vec3.mV[1]); | ||
205 | ensure("6. The value is not NULL", 0.f == llmin_vec3.mV[2]); | ||
206 | } | ||
207 | |||
208 | //test case of update() fn. | ||
209 | template<> template<> | ||
210 | void xform_test_object_t::test<7>() | ||
211 | { | ||
212 | LLXformMatrix formMatrix_obj; | ||
213 | |||
214 | LLXformMatrix parent; | ||
215 | LLVector3 llvecpos(1.0, 2.0, 3.0); | ||
216 | LLVector3 llvecpospar(10.0, 20.0, 30.0); | ||
217 | formMatrix_obj.setPosition(llvecpos); | ||
218 | parent.setPosition(llvecpospar); | ||
219 | |||
220 | LLVector3 llvecparentscale(1.0, 2.0, 0); | ||
221 | parent.setScaleChildOffset(TRUE); | ||
222 | parent.setScale(llvecparentscale); | ||
223 | |||
224 | LLQuaternion quat(1, 2, 3, 4); | ||
225 | LLQuaternion quatparent(5, 6, 7, 8); | ||
226 | formMatrix_obj.setRotation(quat); | ||
227 | parent.setRotation(quatparent); | ||
228 | formMatrix_obj.setParent(&parent); | ||
229 | |||
230 | parent.update(); | ||
231 | formMatrix_obj.update(); | ||
232 | |||
233 | LLVector3 worldPos = llvecpos; | ||
234 | worldPos.scaleVec(llvecparentscale); | ||
235 | worldPos *= quatparent; | ||
236 | worldPos += llvecpospar; | ||
237 | |||
238 | LLQuaternion worldRot = quat * quatparent; | ||
239 | |||
240 | ensure("getWorldPosition failed: ", formMatrix_obj.getWorldPosition() == worldPos); | ||
241 | ensure("getWorldRotation failed: ", formMatrix_obj.getWorldRotation() == worldRot); | ||
242 | |||
243 | ensure("getWorldPosition for parent failed: ", parent.getWorldPosition() == llvecpospar); | ||
244 | ensure("getWorldRotation for parent failed: ", parent.getWorldRotation() == quatparent); | ||
245 | } | ||
246 | } | ||
247 | |||