Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / vectormathlibrary / tests / test4_aos_c.c
1 /*
2   Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
3   All rights reserved.
4
5   Redistribution and use in source and binary forms,
6   with or without modification, are permitted provided that the
7   following conditions are met:
8    * Redistributions of source code must retain the above copyright
9      notice, this list of conditions and the following disclaimer.
10    * Redistributions in binary form must reproduce the above copyright
11      notice, this list of conditions and the following disclaimer in the
12      documentation and/or other materials provided with the distribution.
13    * Neither the name of the Sony Computer Entertainment Inc nor the names
14      of its contributors may be used to endorse or promote products derived
15      from this software without specific prior written permission.
16
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27   POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #define _VECTORMATH_AOS_TEST
31
32 #include "vectormath_aos.h"
33 #include "test.h"
34
35 int iteration = 0;
36
37 void
38 Matrix3_methods_test()
39 {
40     VmathMatrix3 a_Matrix3, b_Matrix3;
41     VmathMatrix4 a_Matrix4, b_Matrix4;
42     VmathTransform3 a_Transform3, b_Transform3;
43     VmathMatrix3 tmpM3_0, tmpM3_1, tmpM3_2, tmpM3_3, tmpM3_4, tmpM3_5, tmpM3_6, tmpM3_7, tmpM3_8, tmpM3_9, tmpM3_10;
44     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3;
45     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4;
46     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3;
47     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat;
48     VmathVector4 tmpV4;
49     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3, tmpV3_4, tmpV3_5, tmpV3_6, tmpV3_7, tmpV3_8;
50     float rndflt1, rndflt2, rndflt3, rndflt4, rndflt5, rndflt6, pad;
51     // set a pad value to detect invalid use of padding.
52     // this will be nan for scalar/ppu implementations, max. float for spu
53     union { float f; unsigned int u; } tmp;
54     tmp.u = 0x7fffffff;
55     pad = tmp.f;
56     rndflt1 = randfloat();
57     rndflt2 = randfloat();
58     rndflt3 = randfloat();
59     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
60     rndflt4 = randfloat();
61     rndflt5 = randfloat();
62     rndflt6 = randfloat();
63     vmathV3MakeFromElems( &b_Vector3, rndflt4, rndflt5, rndflt6 );
64     rndflt1 = randfloat();
65     rndflt2 = randfloat();
66     rndflt3 = randfloat();
67     vmathV3MakeFromElems( &c_Vector3, rndflt1, rndflt2, rndflt3 );
68     rndflt1 = randfloat();
69     rndflt2 = randfloat();
70     rndflt3 = randfloat();
71     vmathV3MakeFromElems( &d_Vector3, rndflt1, rndflt2, rndflt3 );
72     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
73     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
74     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
75     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
76     vmathV4MakeFromV3Scalar( &tmpV4, &c_Vector3, pad );
77     vmathV4GetXYZ( &c_Vector3, &tmpV4 );
78     vmathV4MakeFromV3Scalar( &tmpV4, &d_Vector3, pad );
79     vmathV4GetXYZ( &d_Vector3, &tmpV4 );
80     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
81     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
82     vmathV3Prints( &c_Vector3, "set Vector3 with floats" );
83     vmathV3Prints( &d_Vector3, "set Vector3 with floats" );
84     rndflt1 = randfloat();
85     rndflt2 = randfloat();
86     rndflt3 = randfloat();
87     rndflt4 = randfloat();
88     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
89     rndflt3 = randfloat();
90     rndflt4 = randfloat();
91     rndflt5 = randfloat();
92     rndflt6 = randfloat();
93     vmathV4MakeFromElems( &b_Vector4, rndflt3, rndflt4, rndflt5, rndflt6 );
94     rndflt1 = randfloat();
95     rndflt2 = randfloat();
96     rndflt3 = randfloat();
97     rndflt4 = randfloat();
98     vmathV4MakeFromElems( &c_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
99     rndflt1 = randfloat();
100     rndflt2 = randfloat();
101     rndflt3 = randfloat();
102     rndflt4 = randfloat();
103     vmathV4MakeFromElems( &d_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
104     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
105     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
106     vmathV4Prints( &c_Vector4, "set Vector4 with floats" );
107     vmathV4Prints( &d_Vector4, "set Vector4 with floats" );
108     rndflt1 = randfloat();
109     rndflt2 = randfloat();
110     rndflt3 = randfloat();
111     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
112     rndflt4 = randfloat();
113     rndflt5 = randfloat();
114     rndflt6 = randfloat();
115     vmathP3MakeFromElems( &b_Point3, rndflt4, rndflt5, rndflt6 );
116     rndflt1 = randfloat();
117     rndflt2 = randfloat();
118     rndflt3 = randfloat();
119     vmathP3MakeFromElems( &c_Point3, rndflt1, rndflt2, rndflt3 );
120     rndflt1 = randfloat();
121     rndflt2 = randfloat();
122     rndflt3 = randfloat();
123     vmathP3MakeFromElems( &d_Point3, rndflt1, rndflt2, rndflt3 );
124     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
125     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
126     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
127     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
128     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
129     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
130     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
131     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
132     vmathV3MakeFromP3( &tmpV3_4, &c_Point3 );
133     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_4, pad );
134     vmathV4GetXYZ( &tmpV3_5, &tmpV4 );
135     vmathP3MakeFromV3( &c_Point3, &tmpV3_5 );
136     vmathV3MakeFromP3( &tmpV3_6, &d_Point3 );
137     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_6, pad );
138     vmathV4GetXYZ( &tmpV3_7, &tmpV4 );
139     vmathP3MakeFromV3( &d_Point3, &tmpV3_7 );
140     vmathP3Prints( &a_Point3, "set Point3 with floats" );
141     vmathP3Prints( &b_Point3, "set Point3 with floats" );
142     vmathP3Prints( &c_Point3, "set Point3 with floats" );
143     vmathP3Prints( &d_Point3, "set Point3 with floats" );
144     rndflt1 = randfloat();
145     rndflt2 = randfloat();
146     rndflt3 = randfloat();
147     rndflt4 = randfloat();
148     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
149     rndflt3 = randfloat();
150     rndflt4 = randfloat();
151     rndflt5 = randfloat();
152     rndflt6 = randfloat();
153     vmathQMakeFromElems( &b_Quat, rndflt3, rndflt4, rndflt5, rndflt6 );
154     rndflt1 = randfloat();
155     rndflt2 = randfloat();
156     rndflt3 = randfloat();
157     rndflt4 = randfloat();
158     vmathQMakeFromElems( &c_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
159     rndflt1 = randfloat();
160     rndflt2 = randfloat();
161     rndflt3 = randfloat();
162     rndflt4 = randfloat();
163     vmathQMakeFromElems( &d_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
164     vmathQPrints( &a_Quat, "set Quat with floats" );
165     vmathQPrints( &b_Quat, "set Quat with floats" );
166     vmathQPrints( &c_Quat, "set Quat with floats" );
167     vmathQPrints( &d_Quat, "set Quat with floats" );
168     vmathM3MakeFromCols( &a_Matrix3, &a_Vector3, &b_Vector3, &c_Vector3 );
169     vmathM3MakeFromCols( &b_Matrix3, &d_Vector3, &a_Vector3, &b_Vector3 );
170     vmathM3Prints( &a_Matrix3, "set Matrix3 columns" );
171     vmathM3Prints( &b_Matrix3, "set Matrix3 columns" );
172     vmathM4MakeFromCols( &a_Matrix4, &a_Vector4, &b_Vector4, &c_Vector4, &d_Vector4 );
173     vmathM4MakeFromCols( &b_Matrix4, &d_Vector4, &a_Vector4, &b_Vector4, &c_Vector4 );
174     vmathM4Prints( &a_Matrix4, "set Matrix4 columns" );
175     vmathM4Prints( &b_Matrix4, "set Matrix4 columns" );
176     vmathT3MakeFromCols( &a_Transform3, &a_Vector3, &b_Vector3, &c_Vector3, &d_Vector3 );
177     vmathT3MakeFromCols( &b_Transform3, &d_Vector3, &a_Vector3, &b_Vector3, &c_Vector3 );
178     vmathT3Prints( &a_Transform3, "set Transform3 columns" );
179     vmathT3Prints( &b_Transform3, "set Transform3 columns" );
180     vmathM3AppendScale( &tmpM3_0, &a_Matrix3, &a_Vector3 );
181     vmathM3Prints( &tmpM3_0, "appendScale Matrix3 Vector3" );
182     vmathM3PrependScale( &tmpM3_1, &a_Vector3, &a_Matrix3 );
183     vmathM3Prints( &tmpM3_1, "prependScale Vector3 Matrix3" );
184     vmathM3MulPerElem( &tmpM3_2, &a_Matrix3, &b_Matrix3 );
185     vmathM3Prints( &tmpM3_2, "mulPerElem Matrix3" );
186     vmathM3AbsPerElem( &tmpM3_3, &a_Matrix3 );
187     vmathM3Prints( &tmpM3_3, "absPerElem Matrix3" );
188     vmathM3Transpose( &tmpM3_4, &a_Matrix3 );
189     vmathM3Prints( &tmpM3_4, "transpose Matrix3" );
190     vmathM3Inverse( &tmpM3_5, &a_Matrix3 );
191     vmathM3Prints( &tmpM3_5, "inverse Matrix3" );
192     vmathM3Inverse( &tmpM3_6, &a_Matrix3 );
193     vmathM3Mul( &tmpM3_7, &tmpM3_6, &a_Matrix3 );
194     vmathM3Prints( &tmpM3_7, "inverse(Matrix3) * Matrix3" );
195     printf("%f\n", getfloat(vmathM3Determinant( &a_Matrix3 )) );
196     vmathV3Outer( &tmpM3_8, &a_Vector3, &b_Vector3 );
197     vmathM3Prints( &tmpM3_8, "outer Vector3" );
198     vmathV3RowMul( &tmpV3_8, &a_Vector3, &a_Matrix3 );
199     vmathV3Prints( &tmpV3_8, "rowMul Vector3" );
200     vmathV3CrossMatrix( &tmpM3_9, &a_Vector3 );
201     vmathM3Prints( &tmpM3_9, "crossMatrix" );
202     vmathV3CrossMatrixMul( &tmpM3_10, &a_Vector3, &a_Matrix3 );
203     vmathM3Prints( &tmpM3_10, "crossMatrixMul" );
204 }
205
206 void
207 Matrix4_methods_test()
208 {
209     VmathMatrix3 a_Matrix3, b_Matrix3;
210     VmathMatrix4 a_Matrix4, b_Matrix4;
211     VmathTransform3 a_Transform3, b_Transform3;
212     VmathMatrix4 tmpM4_0, tmpM4_1, tmpM4_2, tmpM4_3, tmpM4_4, tmpM4_5, tmpM4_6, tmpM4_7;
213     VmathMatrix3 tmpM3_0;
214     VmathMatrix4 tmpM4_8, tmpM4_9, tmpM4_10, tmpM4_11, tmpM4_12, tmpM4_13, tmpM4_14;
215     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3;
216     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4;
217     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3;
218     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat;
219     VmathVector4 tmpV4;
220     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3, tmpV3_4, tmpV3_5, tmpV3_6, tmpV3_7;
221     VmathVector4 tmpV4_0;
222     VmathQuat tmpQ_0;
223     float rndflt1, rndflt2, rndflt3, rndflt4, rndflt5, rndflt6, pad;
224     // set a pad value to detect invalid use of padding.
225     // this will be nan for scalar/ppu implementations, max. float for spu
226     union { float f; unsigned int u; } tmp;
227     tmp.u = 0x7fffffff;
228     pad = tmp.f;
229     rndflt1 = randfloat();
230     rndflt2 = randfloat();
231     rndflt3 = randfloat();
232     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
233     rndflt4 = randfloat();
234     rndflt5 = randfloat();
235     rndflt6 = randfloat();
236     vmathV3MakeFromElems( &b_Vector3, rndflt4, rndflt5, rndflt6 );
237     rndflt1 = randfloat();
238     rndflt2 = randfloat();
239     rndflt3 = randfloat();
240     vmathV3MakeFromElems( &c_Vector3, rndflt1, rndflt2, rndflt3 );
241     rndflt1 = randfloat();
242     rndflt2 = randfloat();
243     rndflt3 = randfloat();
244     vmathV3MakeFromElems( &d_Vector3, rndflt1, rndflt2, rndflt3 );
245     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
246     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
247     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
248     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
249     vmathV4MakeFromV3Scalar( &tmpV4, &c_Vector3, pad );
250     vmathV4GetXYZ( &c_Vector3, &tmpV4 );
251     vmathV4MakeFromV3Scalar( &tmpV4, &d_Vector3, pad );
252     vmathV4GetXYZ( &d_Vector3, &tmpV4 );
253     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
254     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
255     vmathV3Prints( &c_Vector3, "set Vector3 with floats" );
256     vmathV3Prints( &d_Vector3, "set Vector3 with floats" );
257     rndflt1 = randfloat();
258     rndflt2 = randfloat();
259     rndflt3 = randfloat();
260     rndflt4 = randfloat();
261     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
262     rndflt3 = randfloat();
263     rndflt4 = randfloat();
264     rndflt5 = randfloat();
265     rndflt6 = randfloat();
266     vmathV4MakeFromElems( &b_Vector4, rndflt3, rndflt4, rndflt5, rndflt6 );
267     rndflt1 = randfloat();
268     rndflt2 = randfloat();
269     rndflt3 = randfloat();
270     rndflt4 = randfloat();
271     vmathV4MakeFromElems( &c_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
272     rndflt1 = randfloat();
273     rndflt2 = randfloat();
274     rndflt3 = randfloat();
275     rndflt4 = randfloat();
276     vmathV4MakeFromElems( &d_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
277     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
278     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
279     vmathV4Prints( &c_Vector4, "set Vector4 with floats" );
280     vmathV4Prints( &d_Vector4, "set Vector4 with floats" );
281     rndflt1 = randfloat();
282     rndflt2 = randfloat();
283     rndflt3 = randfloat();
284     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
285     rndflt4 = randfloat();
286     rndflt5 = randfloat();
287     rndflt6 = randfloat();
288     vmathP3MakeFromElems( &b_Point3, rndflt4, rndflt5, rndflt6 );
289     rndflt1 = randfloat();
290     rndflt2 = randfloat();
291     rndflt3 = randfloat();
292     vmathP3MakeFromElems( &c_Point3, rndflt1, rndflt2, rndflt3 );
293     rndflt1 = randfloat();
294     rndflt2 = randfloat();
295     rndflt3 = randfloat();
296     vmathP3MakeFromElems( &d_Point3, rndflt1, rndflt2, rndflt3 );
297     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
298     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
299     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
300     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
301     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
302     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
303     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
304     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
305     vmathV3MakeFromP3( &tmpV3_4, &c_Point3 );
306     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_4, pad );
307     vmathV4GetXYZ( &tmpV3_5, &tmpV4 );
308     vmathP3MakeFromV3( &c_Point3, &tmpV3_5 );
309     vmathV3MakeFromP3( &tmpV3_6, &d_Point3 );
310     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_6, pad );
311     vmathV4GetXYZ( &tmpV3_7, &tmpV4 );
312     vmathP3MakeFromV3( &d_Point3, &tmpV3_7 );
313     vmathP3Prints( &a_Point3, "set Point3 with floats" );
314     vmathP3Prints( &b_Point3, "set Point3 with floats" );
315     vmathP3Prints( &c_Point3, "set Point3 with floats" );
316     vmathP3Prints( &d_Point3, "set Point3 with floats" );
317     rndflt1 = randfloat();
318     rndflt2 = randfloat();
319     rndflt3 = randfloat();
320     rndflt4 = randfloat();
321     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
322     rndflt3 = randfloat();
323     rndflt4 = randfloat();
324     rndflt5 = randfloat();
325     rndflt6 = randfloat();
326     vmathQMakeFromElems( &b_Quat, rndflt3, rndflt4, rndflt5, rndflt6 );
327     rndflt1 = randfloat();
328     rndflt2 = randfloat();
329     rndflt3 = randfloat();
330     rndflt4 = randfloat();
331     vmathQMakeFromElems( &c_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
332     rndflt1 = randfloat();
333     rndflt2 = randfloat();
334     rndflt3 = randfloat();
335     rndflt4 = randfloat();
336     vmathQMakeFromElems( &d_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
337     vmathQPrints( &a_Quat, "set Quat with floats" );
338     vmathQPrints( &b_Quat, "set Quat with floats" );
339     vmathQPrints( &c_Quat, "set Quat with floats" );
340     vmathQPrints( &d_Quat, "set Quat with floats" );
341     vmathM3MakeFromCols( &a_Matrix3, &a_Vector3, &b_Vector3, &c_Vector3 );
342     vmathM3MakeFromCols( &b_Matrix3, &d_Vector3, &a_Vector3, &b_Vector3 );
343     vmathM3Prints( &a_Matrix3, "set Matrix3 columns" );
344     vmathM3Prints( &b_Matrix3, "set Matrix3 columns" );
345     vmathM4MakeFromCols( &a_Matrix4, &a_Vector4, &b_Vector4, &c_Vector4, &d_Vector4 );
346     vmathM4MakeFromCols( &b_Matrix4, &d_Vector4, &a_Vector4, &b_Vector4, &c_Vector4 );
347     vmathM4Prints( &a_Matrix4, "set Matrix4 columns" );
348     vmathM4Prints( &b_Matrix4, "set Matrix4 columns" );
349     vmathT3MakeFromCols( &a_Transform3, &a_Vector3, &b_Vector3, &c_Vector3, &d_Vector3 );
350     vmathT3MakeFromCols( &b_Transform3, &d_Vector3, &a_Vector3, &b_Vector3, &c_Vector3 );
351     vmathT3Prints( &a_Transform3, "set Transform3 columns" );
352     vmathT3Prints( &b_Transform3, "set Transform3 columns" );
353     vmathM4AppendScale( &tmpM4_0, &a_Matrix4, &a_Vector3 );
354     vmathM4Prints( &tmpM4_0, "appendScale Matrix4 Vector3" );
355     vmathM4PrependScale( &tmpM4_1, &a_Vector3, &a_Matrix4 );
356     vmathM4Prints( &tmpM4_1, "prependScale Vector3 Matrix4" );
357     vmathM4MulPerElem( &tmpM4_2, &a_Matrix4, &b_Matrix4 );
358     vmathM4Prints( &tmpM4_2, "mulPerElem Matrix4" );
359     vmathM4AbsPerElem( &tmpM4_3, &a_Matrix4 );
360     vmathM4Prints( &tmpM4_3, "absPerElem Matrix4" );
361     vmathM4Transpose( &tmpM4_4, &a_Matrix4 );
362     vmathM4Prints( &tmpM4_4, "transpose Matrix4" );
363     vmathM4Inverse( &tmpM4_5, &a_Matrix4 );
364     vmathM4Prints( &tmpM4_5, "inverse Matrix4" );
365     vmathM4Inverse( &tmpM4_6, &a_Matrix4 );
366     vmathM4Mul( &tmpM4_7, &tmpM4_6, &a_Matrix4 );
367     vmathM4Prints( &tmpM4_7, "inverse(Matrix4) * Matrix4" );
368     vmathV4MakeFromElems( &tmpV4_0, 0.0f, 0.0f, 0.0f, 1.0f );
369     vmathM4SetRow( &a_Matrix4, 3, &tmpV4_0 );
370     vmathQNormalize( &tmpQ_0, &a_Quat );
371     vmathM3MakeFromQ( &tmpM3_0, &tmpQ_0 );
372     vmathM4SetUpper3x3( &a_Matrix4, &tmpM3_0 );
373     vmathM4AffineInverse( &tmpM4_8, &a_Matrix4 );
374     vmathM4Prints( &tmpM4_8, "affineInverse Matrix4" );
375     vmathM4AffineInverse( &tmpM4_9, &a_Matrix4 );
376     vmathM4Mul( &tmpM4_10, &tmpM4_9, &a_Matrix4 );
377     vmathM4Prints( &tmpM4_10, "affineInverse(Matrix4) * Matrix4" );
378     vmathM4OrthoInverse( &tmpM4_11, &a_Matrix4 );
379     vmathM4Prints( &tmpM4_11, "orthoInverse Matrix4" );
380     vmathM4OrthoInverse( &tmpM4_12, &a_Matrix4 );
381     vmathM4Mul( &tmpM4_13, &tmpM4_12, &a_Matrix4 );
382     vmathM4Prints( &tmpM4_13, "orthoInverse(Matrix4) * Matrix4" );
383     printf("%f\n", getfloat(vmathM4Determinant( &a_Matrix4 )) );
384     vmathV4Outer( &tmpM4_14, &a_Vector4, &b_Vector4 );
385     vmathM4Prints( &tmpM4_14, "outer Vector4" );
386 }
387
388 void
389 Transform3_methods_test()
390 {
391     VmathMatrix3 a_Matrix3, b_Matrix3;
392     VmathMatrix4 a_Matrix4, b_Matrix4;
393     VmathTransform3 a_Transform3, b_Transform3, tmpT3_0, tmpT3_1, tmpT3_2, tmpT3_3, tmpT3_4, tmpT3_5, tmpT3_6;
394     VmathMatrix3 tmpM3_0;
395     VmathTransform3 tmpT3_7, tmpT3_8, tmpT3_9;
396     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3;
397     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4;
398     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3;
399     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat;
400     VmathVector4 tmpV4;
401     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3, tmpV3_4, tmpV3_5, tmpV3_6, tmpV3_7;
402     VmathQuat tmpQ_0;
403     float rndflt1, rndflt2, rndflt3, rndflt4, rndflt5, rndflt6, pad;
404     // set a pad value to detect invalid use of padding.
405     // this will be nan for scalar/ppu implementations, max. float for spu
406     union { float f; unsigned int u; } tmp;
407     tmp.u = 0x7fffffff;
408     pad = tmp.f;
409     rndflt1 = randfloat();
410     rndflt2 = randfloat();
411     rndflt3 = randfloat();
412     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
413     rndflt4 = randfloat();
414     rndflt5 = randfloat();
415     rndflt6 = randfloat();
416     vmathV3MakeFromElems( &b_Vector3, rndflt4, rndflt5, rndflt6 );
417     rndflt1 = randfloat();
418     rndflt2 = randfloat();
419     rndflt3 = randfloat();
420     vmathV3MakeFromElems( &c_Vector3, rndflt1, rndflt2, rndflt3 );
421     rndflt1 = randfloat();
422     rndflt2 = randfloat();
423     rndflt3 = randfloat();
424     vmathV3MakeFromElems( &d_Vector3, rndflt1, rndflt2, rndflt3 );
425     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
426     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
427     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
428     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
429     vmathV4MakeFromV3Scalar( &tmpV4, &c_Vector3, pad );
430     vmathV4GetXYZ( &c_Vector3, &tmpV4 );
431     vmathV4MakeFromV3Scalar( &tmpV4, &d_Vector3, pad );
432     vmathV4GetXYZ( &d_Vector3, &tmpV4 );
433     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
434     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
435     vmathV3Prints( &c_Vector3, "set Vector3 with floats" );
436     vmathV3Prints( &d_Vector3, "set Vector3 with floats" );
437     rndflt1 = randfloat();
438     rndflt2 = randfloat();
439     rndflt3 = randfloat();
440     rndflt4 = randfloat();
441     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
442     rndflt3 = randfloat();
443     rndflt4 = randfloat();
444     rndflt5 = randfloat();
445     rndflt6 = randfloat();
446     vmathV4MakeFromElems( &b_Vector4, rndflt3, rndflt4, rndflt5, rndflt6 );
447     rndflt1 = randfloat();
448     rndflt2 = randfloat();
449     rndflt3 = randfloat();
450     rndflt4 = randfloat();
451     vmathV4MakeFromElems( &c_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
452     rndflt1 = randfloat();
453     rndflt2 = randfloat();
454     rndflt3 = randfloat();
455     rndflt4 = randfloat();
456     vmathV4MakeFromElems( &d_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
457     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
458     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
459     vmathV4Prints( &c_Vector4, "set Vector4 with floats" );
460     vmathV4Prints( &d_Vector4, "set Vector4 with floats" );
461     rndflt1 = randfloat();
462     rndflt2 = randfloat();
463     rndflt3 = randfloat();
464     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
465     rndflt4 = randfloat();
466     rndflt5 = randfloat();
467     rndflt6 = randfloat();
468     vmathP3MakeFromElems( &b_Point3, rndflt4, rndflt5, rndflt6 );
469     rndflt1 = randfloat();
470     rndflt2 = randfloat();
471     rndflt3 = randfloat();
472     vmathP3MakeFromElems( &c_Point3, rndflt1, rndflt2, rndflt3 );
473     rndflt1 = randfloat();
474     rndflt2 = randfloat();
475     rndflt3 = randfloat();
476     vmathP3MakeFromElems( &d_Point3, rndflt1, rndflt2, rndflt3 );
477     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
478     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
479     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
480     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
481     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
482     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
483     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
484     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
485     vmathV3MakeFromP3( &tmpV3_4, &c_Point3 );
486     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_4, pad );
487     vmathV4GetXYZ( &tmpV3_5, &tmpV4 );
488     vmathP3MakeFromV3( &c_Point3, &tmpV3_5 );
489     vmathV3MakeFromP3( &tmpV3_6, &d_Point3 );
490     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_6, pad );
491     vmathV4GetXYZ( &tmpV3_7, &tmpV4 );
492     vmathP3MakeFromV3( &d_Point3, &tmpV3_7 );
493     vmathP3Prints( &a_Point3, "set Point3 with floats" );
494     vmathP3Prints( &b_Point3, "set Point3 with floats" );
495     vmathP3Prints( &c_Point3, "set Point3 with floats" );
496     vmathP3Prints( &d_Point3, "set Point3 with floats" );
497     rndflt1 = randfloat();
498     rndflt2 = randfloat();
499     rndflt3 = randfloat();
500     rndflt4 = randfloat();
501     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
502     rndflt3 = randfloat();
503     rndflt4 = randfloat();
504     rndflt5 = randfloat();
505     rndflt6 = randfloat();
506     vmathQMakeFromElems( &b_Quat, rndflt3, rndflt4, rndflt5, rndflt6 );
507     rndflt1 = randfloat();
508     rndflt2 = randfloat();
509     rndflt3 = randfloat();
510     rndflt4 = randfloat();
511     vmathQMakeFromElems( &c_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
512     rndflt1 = randfloat();
513     rndflt2 = randfloat();
514     rndflt3 = randfloat();
515     rndflt4 = randfloat();
516     vmathQMakeFromElems( &d_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
517     vmathQPrints( &a_Quat, "set Quat with floats" );
518     vmathQPrints( &b_Quat, "set Quat with floats" );
519     vmathQPrints( &c_Quat, "set Quat with floats" );
520     vmathQPrints( &d_Quat, "set Quat with floats" );
521     vmathM3MakeFromCols( &a_Matrix3, &a_Vector3, &b_Vector3, &c_Vector3 );
522     vmathM3MakeFromCols( &b_Matrix3, &d_Vector3, &a_Vector3, &b_Vector3 );
523     vmathM3Prints( &a_Matrix3, "set Matrix3 columns" );
524     vmathM3Prints( &b_Matrix3, "set Matrix3 columns" );
525     vmathM4MakeFromCols( &a_Matrix4, &a_Vector4, &b_Vector4, &c_Vector4, &d_Vector4 );
526     vmathM4MakeFromCols( &b_Matrix4, &d_Vector4, &a_Vector4, &b_Vector4, &c_Vector4 );
527     vmathM4Prints( &a_Matrix4, "set Matrix4 columns" );
528     vmathM4Prints( &b_Matrix4, "set Matrix4 columns" );
529     vmathT3MakeFromCols( &a_Transform3, &a_Vector3, &b_Vector3, &c_Vector3, &d_Vector3 );
530     vmathT3MakeFromCols( &b_Transform3, &d_Vector3, &a_Vector3, &b_Vector3, &c_Vector3 );
531     vmathT3Prints( &a_Transform3, "set Transform3 columns" );
532     vmathT3Prints( &b_Transform3, "set Transform3 columns" );
533     vmathT3AppendScale( &tmpT3_0, &a_Transform3, &a_Vector3 );
534     vmathT3Prints( &tmpT3_0, "appendScale Transform3 Vector3" );
535     vmathT3PrependScale( &tmpT3_1, &a_Vector3, &a_Transform3 );
536     vmathT3Prints( &tmpT3_1, "prependScale Vector3 Transform3" );
537     vmathT3MulPerElem( &tmpT3_2, &a_Transform3, &b_Transform3 );
538     vmathT3Prints( &tmpT3_2, "mulPerElem Transform3" );
539     vmathT3AbsPerElem( &tmpT3_3, &a_Transform3 );
540     vmathT3Prints( &tmpT3_3, "absPerElem Transform3" );
541     vmathT3Inverse( &tmpT3_4, &a_Transform3 );
542     vmathT3Prints( &tmpT3_4, "inverse Transform3" );
543     vmathT3Inverse( &tmpT3_5, &a_Transform3 );
544     vmathT3Mul( &tmpT3_6, &tmpT3_5, &a_Transform3 );
545     vmathT3Prints( &tmpT3_6, "inverse(Transform3) * Transform3" );
546     vmathQNormalize( &tmpQ_0, &a_Quat );
547     vmathM3MakeFromQ( &tmpM3_0, &tmpQ_0 );
548     vmathT3SetUpper3x3( &a_Transform3, &tmpM3_0 );
549     vmathT3OrthoInverse( &tmpT3_7, &a_Transform3 );
550     vmathT3Prints( &tmpT3_7, "orthoInverse Transform3" );
551     vmathT3OrthoInverse( &tmpT3_8, &a_Transform3 );
552     vmathT3Mul( &tmpT3_9, &tmpT3_8, &a_Transform3 );
553     vmathT3Prints( &tmpT3_9, "orthoInverse(Transform3) * Transform3" );
554 }
555
556 int main()
557 {
558     int i;
559     printf("\n __begin__ \n");
560     for ( i = 0; i < 2; i++ ) {
561         Matrix3_methods_test();
562         Matrix4_methods_test();
563         Transform3_methods_test();
564     }
565     printf("\n __end__ \n");
566     return 0;
567 }