Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / vectormathlibrary / tests / test1_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 Vector3_methods_test()
39 {
40     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
41     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
42     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
43     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
44     VmathVector4 tmpV4;
45     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3, aos_Vector3_0, aos_Vector3_1, aos_Vector3_2, aos_Vector3_3, tmpV3_4, tmpV3_5, tmpV3_6, tmpV3_7;
46     VmathVector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2;
47     VmathVector3 tmpV3_8, tmpV3_9;
48     VmathPoint3 tmpP3_0;
49     VmathVector3 tmpV3_10, tmpV3_11, tmpV3_12, tmpV3_13, tmpV3_14, tmpV3_15, tmpV3_16, tmpV3_17, tmpV3_18, tmpV3_19, tmpV3_20, tmpV3_21, tmpV3_22, tmpV3_23, tmpV3_24, tmpV3_25;
50     float rndflt1, rndflt2, rndflt3, rndflt4, pad;
51     float xyz4[12] __attribute__ ((aligned(16)));
52 #ifndef _VECTORMATH_SCALAR_TEST
53     vec_float4 quad;
54 #endif
55     xyz4[0] = randfloat();
56     xyz4[1] = randfloat();
57     xyz4[2] = randfloat();
58     xyz4[3] = randfloat();
59     xyz4[4] = randfloat();
60     xyz4[5] = randfloat();
61     xyz4[6] = randfloat();
62     xyz4[7] = randfloat();
63     xyz4[8] = randfloat();
64     xyz4[9] = randfloat();
65     xyz4[10] = randfloat();
66     xyz4[11] = randfloat();
67     // set a pad value to detect invalid use of padding.
68     // this will be nan for scalar/ppu implementations, max. float for spu
69     union { float f; unsigned int u; } tmp;
70     tmp.u = 0x7fffffff;
71     pad = tmp.f;
72     rndflt1 = randfloat();
73     rndflt2 = randfloat();
74     rndflt3 = randfloat();
75     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
76     rndflt1 = randfloat();
77     rndflt2 = randfloat();
78     rndflt3 = randfloat();
79     vmathV3MakeFromElems( &b_Vector3, rndflt1, rndflt2, rndflt3 );
80     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
81     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
82     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
83     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
84     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
85     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
86     vmathV3MakeFromScalar( &c_Vector3, 0.0f );
87     vmathV3MakeFromScalar( &d_Vector3, 0.0f );
88     vmathV3MakeFromScalar( &e_Vector3, 0.0f );
89     vmathV3Prints( &c_Vector3, "set Vector3 elements to zero" );
90     vmathV3Prints( &d_Vector3, "set Vector3 elements to zero" );
91     vmathV3Prints( &e_Vector3, "set Vector3 elements to zero" );
92     rndflt1 = randfloat();
93     rndflt2 = randfloat();
94     rndflt3 = randfloat();
95     rndflt4 = randfloat();
96     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
97     rndflt1 = randfloat();
98     rndflt2 = randfloat();
99     rndflt3 = randfloat();
100     rndflt4 = randfloat();
101     vmathV4MakeFromElems( &b_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
102     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
103     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
104     vmathV4MakeFromScalar( &c_Vector4, 0.0f );
105     vmathV4MakeFromScalar( &d_Vector4, 0.0f );
106     vmathV4MakeFromScalar( &e_Vector4, 0.0f );
107     vmathV4Prints( &c_Vector4, "set Vector4 elements to zero" );
108     vmathV4Prints( &d_Vector4, "set Vector4 elements to zero" );
109     vmathV4Prints( &e_Vector4, "set Vector4 elements to zero" );
110     rndflt1 = randfloat();
111     rndflt2 = randfloat();
112     rndflt3 = randfloat();
113     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
114     rndflt1 = randfloat();
115     rndflt2 = randfloat();
116     rndflt3 = randfloat();
117     vmathP3MakeFromElems( &b_Point3, rndflt1, rndflt2, rndflt3 );
118     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
119     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
120     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
121     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
122     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
123     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
124     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
125     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
126     vmathP3Prints( &a_Point3, "set Point3 with floats" );
127     vmathP3Prints( &b_Point3, "set Point3 with floats" );
128     vmathP3MakeFromScalar( &c_Point3, 0.0f );
129     vmathP3MakeFromScalar( &d_Point3, 0.0f );
130     vmathP3MakeFromScalar( &e_Point3, 0.0f );
131     vmathP3Prints( &c_Point3, "set Point3 elements to zero" );
132     vmathP3Prints( &d_Point3, "set Point3 elements to zero" );
133     vmathP3Prints( &e_Point3, "set Point3 elements to zero" );
134     rndflt1 = randfloat();
135     rndflt2 = randfloat();
136     rndflt3 = randfloat();
137     rndflt4 = randfloat();
138     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
139     rndflt1 = randfloat();
140     rndflt2 = randfloat();
141     rndflt3 = randfloat();
142     rndflt4 = randfloat();
143     vmathQMakeFromElems( &b_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
144     vmathQPrints( &a_Quat, "set Quat with floats" );
145     vmathQPrints( &b_Quat, "set Quat with floats" );
146     vmathQMakeFromScalar( &c_Quat, 0.0f );
147     vmathQMakeFromScalar( &d_Quat, 0.0f );
148     vmathQMakeFromScalar( &e_Quat, 0.0f );
149     vmathQPrints( &c_Quat, "set Quat elements to zero" );
150     vmathQPrints( &d_Quat, "set Quat elements to zero" );
151     vmathQPrints( &e_Quat, "set Quat elements to zero" );
152     vmathV3MakeFromP3( &a_Vector3, &a_Point3 );
153     vmathV3Prints( &a_Vector3, "construct Vector3 with Point3" );
154     vmathV3MakeFromScalar( &a_Vector3, randfloat() );
155     vmathV3Prints( &a_Vector3, "set Vector3 with float" );
156     vmathV3MakeFromScalar( &a_Vector3, randfloat() );
157     vmathV3Prints( &a_Vector3, "set Vector3 with float" );
158     vmathV3MakeFromElems( &aos_Vector3_0, 0.0f, 1.0f, 2.0f );
159     vmathV3MakeFromElems( &aos_Vector3_1, 3.0f, 4.0f, 5.0f );
160     vmathV3MakeFromElems( &aos_Vector3_2, 6.0f, 7.0f, 8.0f );
161     vmathV3MakeFromElems( &aos_Vector3_3, 9.0f, 10.0f, 11.0f );
162     vmathV3Prints( &aos_Vector3_3, "aos type 0" );
163     vmathV3Prints( &aos_Vector3_2, "aos type 1" );
164     vmathV3Prints( &aos_Vector3_1, "aos type 2" );
165     vmathV3Prints( &aos_Vector3_0, "aos type 3" );
166     vmathV3Select( &tmpV3_4, &a_Vector3, &b_Vector3, 0 );
167     vmathV3Prints( &tmpV3_4, "select 0" );
168     vmathV3Select( &tmpV3_5, &a_Vector3, &b_Vector3, 1 );
169     vmathV3Prints( &tmpV3_5, "select 1" );
170     vmathV3Select( &tmpV3_6, &a_Vector3, &b_Vector3, 0 );
171     vmathV3Prints( &tmpV3_6, "select 2" );
172     vmathV3Select( &tmpV3_7, &a_Vector3, &b_Vector3, (unsigned int)-1 );
173     vmathV3Prints( &tmpV3_7, "select 3" );
174     vmathV3MakeFromElems( &a_Vector3, xyz4[0], xyz4[1], xyz4[2] );
175     vmathV3Prints( &a_Vector3, "load XYZ array" );
176     xyz4[0] = -xyz4[0];
177     xyz4[1] = -xyz4[1];
178     xyz4[2] = -xyz4[2];
179     xyz4[3] = -xyz4[3];
180     xyz4[4] = -xyz4[4];
181     xyz4[5] = -xyz4[5];
182     xyz4[6] = -xyz4[6];
183     xyz4[7] = -xyz4[7];
184     xyz4[8] = -xyz4[8];
185     xyz4[9] = -xyz4[9];
186     xyz4[10] = -xyz4[10];
187     xyz4[11] = -xyz4[11];
188     vmathV4MakeFromElems( &aos_Vector4_0, xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
189     vmathV4MakeFromElems( &aos_Vector4_1, xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
190     vmathV4MakeFromElems( &aos_Vector4_2, xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
191     vmathV4Prints( &aos_Vector4_0, "xyzx" );
192     vmathV4Prints( &aos_Vector4_1, "yzxy" );
193     vmathV4Prints( &aos_Vector4_2, "zxyz" );
194 #ifndef _VECTORMATH_SCALAR_TEST
195     vmathV3LoadXYZArray( &aos_Vector3_0, &aos_Vector3_1, &aos_Vector3_2, &aos_Vector3_3, (const vec_float4 *)xyz4 );
196     xyz4[0] = 0;
197     xyz4[1] = 1;
198     xyz4[2] = 2;
199     xyz4[3] = 3;
200     xyz4[4] = 4;
201     xyz4[5] = 5;
202     xyz4[6] = 6;
203     xyz4[7] = 7;
204     xyz4[8] = 8;
205     xyz4[9] = 9;
206     xyz4[10] = 10;
207     xyz4[11] = 11;
208     vmathV3StoreXYZArray( &aos_Vector3_0, &aos_Vector3_1, &aos_Vector3_2, &aos_Vector3_3, (vec_float4 *)xyz4 );
209 #endif
210     vmathV4MakeFromElems( &aos_Vector4_0, xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
211     vmathV4MakeFromElems( &aos_Vector4_1, xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
212     vmathV4MakeFromElems( &aos_Vector4_2, xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
213     vmathV4Prints( &aos_Vector4_0, "xyzx" );
214     vmathV4Prints( &aos_Vector4_1, "yzxy" );
215     vmathV4Prints( &aos_Vector4_2, "zxyz" );
216 #ifdef _VECTORMATH_SCALAR_TEST
217     printf("storeXYZ:-1.0 -2.0 -3.0 0.4\n");
218 #else
219     quad = (vec_float4){-1.0f, -2.0f, -3.0f, -4.0f};
220     a_Vector3.vec128 = quad;
221     quad = (vec_float4){0.1f, 0.2f, 0.3f, 0.4f};
222     vmathV3StoreXYZ( &a_Vector3, &quad );
223     printf("storeXYZ:%f %f %f %f\n", ((float *)&quad)[0], ((float *)&quad)[1], ((float *)&quad)[2], ((float *)&quad)[3]);
224 #endif
225     vmathV3Copy( &a_Vector3, &b_Vector3 );
226     vmathV3Prints( &a_Vector3, "assign to Vector3 from Vector3" );
227     vmathV3MakeFromScalar( &a_Vector3, 0.0f );
228     vmathV3Prints( &a_Vector3, "set Vector3 elements to zero" );
229     vmathV3MakeXAxis( &a_Vector3 );
230     vmathV3Prints( &a_Vector3, "set to x axis" );
231     vmathV3MakeYAxis( &a_Vector3 );
232     vmathV3Prints( &a_Vector3, "set to y axis" );
233     vmathV3MakeZAxis( &a_Vector3 );
234     vmathV3Prints( &a_Vector3, "set to z axis" );
235     vmathV3SetElem( &a_Vector3, 0, randfloat() );
236     vmathV3Prints( &a_Vector3, "Vector3::set( 0, float )" );
237     vmathV3SetElem( &a_Vector3, 0, randfloat() );
238     vmathV3SetElem( &a_Vector3, 0, ( vmathV3GetElem( &a_Vector3, 0 ) * randfloat() ) );
239     vmathV3SetElem( &a_Vector3, 0, ( vmathV3GetElem( &a_Vector3, 0 ) / randfloat() ) );
240     vmathV3SetElem( &a_Vector3, 0, ( vmathV3GetElem( &a_Vector3, 0 ) + randfloat() ) );
241     vmathV3SetElem( &a_Vector3, 0, ( vmathV3GetElem( &a_Vector3, 0 ) - randfloat() ) );
242     vmathV3Prints( &a_Vector3, "Vector3::operator [](0)" );
243     vmathV3SetX( &a_Vector3, randfloat() );
244     vmathV3Prints( &a_Vector3, "Vector3::setX()" );
245     vmathV3SetElem( &a_Vector3, 1, randfloat() );
246     vmathV3Prints( &a_Vector3, "Vector3::set( 1, float )" );
247     vmathV3SetElem( &a_Vector3, 1, randfloat() );
248     vmathV3SetElem( &a_Vector3, 1, ( vmathV3GetElem( &a_Vector3, 1 ) * randfloat() ) );
249     vmathV3SetElem( &a_Vector3, 1, ( vmathV3GetElem( &a_Vector3, 1 ) / randfloat() ) );
250     vmathV3SetElem( &a_Vector3, 1, ( vmathV3GetElem( &a_Vector3, 1 ) + randfloat() ) );
251     vmathV3SetElem( &a_Vector3, 1, ( vmathV3GetElem( &a_Vector3, 1 ) - randfloat() ) );
252     vmathV3Prints( &a_Vector3, "Vector3::operator [](1)" );
253     vmathV3SetY( &a_Vector3, randfloat() );
254     vmathV3Prints( &a_Vector3, "Vector3::setY()" );
255     vmathV3SetElem( &a_Vector3, 2, randfloat() );
256     vmathV3Prints( &a_Vector3, "Vector3::set( 2, float )" );
257     vmathV3SetElem( &a_Vector3, 2, randfloat() );
258     vmathV3SetElem( &a_Vector3, 2, ( vmathV3GetElem( &a_Vector3, 2 ) * randfloat() ) );
259     vmathV3SetElem( &a_Vector3, 2, ( vmathV3GetElem( &a_Vector3, 2 ) / randfloat() ) );
260     vmathV3SetElem( &a_Vector3, 2, ( vmathV3GetElem( &a_Vector3, 2 ) + randfloat() ) );
261     vmathV3SetElem( &a_Vector3, 2, ( vmathV3GetElem( &a_Vector3, 2 ) - randfloat() ) );
262     vmathV3Prints( &a_Vector3, "Vector3::operator [](2)" );
263     vmathV3SetZ( &a_Vector3, randfloat() );
264     vmathV3Prints( &a_Vector3, "Vector3::setZ()" );
265     printf("Vector3::get( 0 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 0 )) );
266     printf("Vector3::operator []( 0 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 0 )) );
267     printf("Vector3::getX(): %f\n", getfloat(vmathV3GetX( &a_Vector3 )) );
268     printf("Vector3::get( 1 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 1 )) );
269     printf("Vector3::operator []( 1 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 1 )) );
270     printf("Vector3::getY(): %f\n", getfloat(vmathV3GetY( &a_Vector3 )) );
271     printf("Vector3::get( 2 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 2 )) );
272     printf("Vector3::operator []( 2 ): %f\n", getfloat(vmathV3GetElem( &a_Vector3, 2 )) );
273     printf("Vector3::getZ(): %f\n", getfloat(vmathV3GetZ( &a_Vector3 )) );
274     vmathV3Add( &tmpV3_8, &a_Vector3, &b_Vector3 );
275     vmathV3Prints( &tmpV3_8, "Vector3 + Vector3" );
276     vmathV3Sub( &tmpV3_9, &a_Vector3, &b_Vector3 );
277     vmathV3Prints( &tmpV3_9, "Vector3 - Vector3" );
278     vmathV3AddP3( &tmpP3_0, &a_Vector3, &b_Point3 );
279     vmathP3Prints( &tmpP3_0, "Vector3 + Point3" );
280     vmathV3ScalarMul( &tmpV3_10, &a_Vector3, randfloat() );
281     vmathV3Prints( &tmpV3_10, "Vector3 * float" );
282     vmathV3ScalarDiv( &tmpV3_11, &a_Vector3, randfloat() );
283     vmathV3Prints( &tmpV3_11, "Vector3 / float" );
284     vmathV3ScalarMul( &tmpV3_12, &a_Vector3, randfloat() );
285     vmathV3Prints( &tmpV3_12, "float * Vector3" );
286     vmathV3Neg( &tmpV3_13, &a_Vector3 );
287     vmathV3Prints( &tmpV3_13, "Vector3 negate" );
288     vmathV3MulPerElem( &tmpV3_14, &a_Vector3, &b_Vector3 );
289     vmathV3Prints( &tmpV3_14, "mulPerElem( Vector3, Vector3 )" );
290     vmathV3DivPerElem( &tmpV3_15, &a_Vector3, &b_Vector3 );
291     vmathV3Prints( &tmpV3_15, "divPerElem( Vector3, Vector3 )" );
292     vmathV3RecipPerElem( &tmpV3_16, &a_Vector3 );
293     vmathV3Prints( &tmpV3_16, "Vector3 recip" );
294     vmathV3AbsPerElem( &tmpV3_17, &a_Vector3 );
295     vmathV3SqrtPerElem( &tmpV3_18, &tmpV3_17 );
296     vmathV3Prints( &tmpV3_18, "Vector3 sqrt" );
297     vmathV3AbsPerElem( &tmpV3_19, &a_Vector3 );
298     vmathV3RsqrtPerElem( &tmpV3_20, &tmpV3_19 );
299     vmathV3Prints( &tmpV3_20, "Vector3 rsqrt" );
300     vmathV3AbsPerElem( &tmpV3_21, &a_Vector3 );
301     vmathV3Prints( &tmpV3_21, "Vector3 abs" );
302     vmathV3CopySignPerElem( &tmpV3_22, &a_Vector3, &b_Vector3 );
303     vmathV3Prints( &tmpV3_22, "Vector3 copySign" );
304     vmathV3MaxPerElem( &tmpV3_23, &a_Vector3, &b_Vector3 );
305     vmathV3Prints( &tmpV3_23, "Vector3 maximum Vector3" );
306     vmathV3MinPerElem( &tmpV3_24, &a_Vector3, &b_Vector3 );
307     vmathV3Prints( &tmpV3_24, "Vector3 minimum Vector3" );
308     printf("Vector3 maximum of elements: %f\n", getfloat(vmathV3MaxElem( &a_Vector3 )));
309     printf("Vector3 minimum of elements: %f\n", getfloat(vmathV3MinElem( &a_Vector3 )));
310     printf("Vector3 sum of elements: %f\n", getfloat(vmathV3Sum( &a_Vector3 )));
311     printf("Vector3 dot Vector3: %f\n", getfloat(vmathV3Dot( &a_Vector3, &b_Vector3 )));
312     printf("Vector3 lengthSqr: %f\n", getfloat(vmathV3LengthSqr( &a_Vector3 )));
313     printf("Vector3 length: %f\n", getfloat(vmathV3Length( &a_Vector3 )));
314     vmathV3Normalize( &tmpV3_25, &a_Vector3 );
315     vmathV3Prints( &tmpV3_25, "Vector3 normalized" );
316     rndflt1 = randfloat();
317     rndflt2 = randfloat();
318     rndflt3 = randfloat();
319     vmathV3MakeFromElems( &b_Vector3, rndflt1, rndflt2, rndflt3 );
320     rndflt1 = randfloat();
321     rndflt2 = randfloat();
322     rndflt3 = randfloat();
323     vmathV3MakeFromElems( &c_Vector3, rndflt1, rndflt2, rndflt3 );
324     rndflt1 = randfloat();
325     rndflt2 = randfloat();
326     rndflt3 = randfloat();
327     vmathV3MakeFromElems( &d_Vector3, rndflt1, rndflt2, rndflt3 );
328     rndflt1 = randfloat();
329     rndflt2 = randfloat();
330     rndflt3 = randfloat();
331     vmathV3MakeFromElems( &e_Vector3, rndflt1, rndflt2, rndflt3 );
332     vmathV3Normalize( &b_Vector3, &b_Vector3 );
333     vmathV3Normalize( &c_Vector3, &c_Vector3 );
334     vmathV3Normalize( &d_Vector3, &d_Vector3 );
335     vmathV3Normalize( &e_Vector3, &e_Vector3 );
336     vmathV3Lerp( &a_Vector3, randfloat(), &b_Vector3, &c_Vector3 );
337     vmathV3Prints( &a_Vector3, "Vector3 lerp" );
338     vmathV3Slerp( &a_Vector3, randfloat(), &b_Vector3, &c_Vector3 );
339     vmathV3Prints( &a_Vector3, "Vector3 slerp" );
340 }
341
342 void
343 Vector4_methods_test()
344 {
345     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
346     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
347     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
348     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
349     VmathVector4 tmpV4;
350     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3;
351     VmathVector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2, aos_Vector4_3, tmpV4_0, tmpV4_1, tmpV4_2, tmpV4_3;
352     VmathVector3 tmpV3_4;
353     VmathVector4 tmpV4_4, tmpV4_5, tmpV4_6, tmpV4_7, tmpV4_8, tmpV4_9, tmpV4_10, tmpV4_11, tmpV4_12, tmpV4_13, tmpV4_14, tmpV4_15, tmpV4_16, tmpV4_17, tmpV4_18, tmpV4_19, tmpV4_20, tmpV4_21;
354     float rndflt1, rndflt2, rndflt3, rndflt4, pad;
355     // set a pad value to detect invalid use of padding.
356     // this will be nan for scalar/ppu implementations, max. float for spu
357     union { float f; unsigned int u; } tmp;
358     tmp.u = 0x7fffffff;
359     pad = tmp.f;
360     rndflt1 = randfloat();
361     rndflt2 = randfloat();
362     rndflt3 = randfloat();
363     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
364     rndflt1 = randfloat();
365     rndflt2 = randfloat();
366     rndflt3 = randfloat();
367     vmathV3MakeFromElems( &b_Vector3, rndflt1, rndflt2, rndflt3 );
368     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
369     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
370     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
371     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
372     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
373     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
374     vmathV3MakeFromScalar( &c_Vector3, 0.0f );
375     vmathV3MakeFromScalar( &d_Vector3, 0.0f );
376     vmathV3MakeFromScalar( &e_Vector3, 0.0f );
377     vmathV3Prints( &c_Vector3, "set Vector3 elements to zero" );
378     vmathV3Prints( &d_Vector3, "set Vector3 elements to zero" );
379     vmathV3Prints( &e_Vector3, "set Vector3 elements to zero" );
380     rndflt1 = randfloat();
381     rndflt2 = randfloat();
382     rndflt3 = randfloat();
383     rndflt4 = randfloat();
384     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
385     rndflt1 = randfloat();
386     rndflt2 = randfloat();
387     rndflt3 = randfloat();
388     rndflt4 = randfloat();
389     vmathV4MakeFromElems( &b_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
390     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
391     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
392     vmathV4MakeFromScalar( &c_Vector4, 0.0f );
393     vmathV4MakeFromScalar( &d_Vector4, 0.0f );
394     vmathV4MakeFromScalar( &e_Vector4, 0.0f );
395     vmathV4Prints( &c_Vector4, "set Vector4 elements to zero" );
396     vmathV4Prints( &d_Vector4, "set Vector4 elements to zero" );
397     vmathV4Prints( &e_Vector4, "set Vector4 elements to zero" );
398     rndflt1 = randfloat();
399     rndflt2 = randfloat();
400     rndflt3 = randfloat();
401     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
402     rndflt1 = randfloat();
403     rndflt2 = randfloat();
404     rndflt3 = randfloat();
405     vmathP3MakeFromElems( &b_Point3, rndflt1, rndflt2, rndflt3 );
406     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
407     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
408     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
409     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
410     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
411     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
412     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
413     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
414     vmathP3Prints( &a_Point3, "set Point3 with floats" );
415     vmathP3Prints( &b_Point3, "set Point3 with floats" );
416     vmathP3MakeFromScalar( &c_Point3, 0.0f );
417     vmathP3MakeFromScalar( &d_Point3, 0.0f );
418     vmathP3MakeFromScalar( &e_Point3, 0.0f );
419     vmathP3Prints( &c_Point3, "set Point3 elements to zero" );
420     vmathP3Prints( &d_Point3, "set Point3 elements to zero" );
421     vmathP3Prints( &e_Point3, "set Point3 elements to zero" );
422     rndflt1 = randfloat();
423     rndflt2 = randfloat();
424     rndflt3 = randfloat();
425     rndflt4 = randfloat();
426     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
427     rndflt1 = randfloat();
428     rndflt2 = randfloat();
429     rndflt3 = randfloat();
430     rndflt4 = randfloat();
431     vmathQMakeFromElems( &b_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
432     vmathQPrints( &a_Quat, "set Quat with floats" );
433     vmathQPrints( &b_Quat, "set Quat with floats" );
434     vmathQMakeFromScalar( &c_Quat, 0.0f );
435     vmathQMakeFromScalar( &d_Quat, 0.0f );
436     vmathQMakeFromScalar( &e_Quat, 0.0f );
437     vmathQPrints( &c_Quat, "set Quat elements to zero" );
438     vmathQPrints( &d_Quat, "set Quat elements to zero" );
439     vmathQPrints( &e_Quat, "set Quat elements to zero" );
440     vmathV4MakeFromV3Scalar( &a_Vector4, &a_Vector3, randfloat() );
441     vmathV4Prints( &a_Vector4, "set Vector4 with Vector3, float" );
442     vmathV4MakeFromV3( &a_Vector4, &a_Vector3 );
443     vmathV4Prints( &a_Vector4, "set Vector4 with Vector3" );
444     vmathV4MakeFromP3( &a_Vector4, &a_Point3 );
445     vmathV4Prints( &a_Vector4, "set Vector4 with Point3" );
446     vmathV4MakeFromQ( &a_Vector4, &a_Quat );
447     vmathV4Prints( &a_Vector4, "construct Vector4 with Quat" );
448     vmathV4MakeFromScalar( &a_Vector4, randfloat() );
449     vmathV4Prints( &a_Vector4, "set Vector4 with float" );
450     vmathV4MakeFromScalar( &a_Vector4, randfloat() );
451     vmathV4Prints( &a_Vector4, "set Vector4 with float" );
452     vmathV4MakeFromElems( &aos_Vector4_0, 0.0f, 1.0f, 2.0f, 3.0f );
453     vmathV4MakeFromElems( &aos_Vector4_1, 4.0f, 5.0f, 6.0f, 7.0f );
454     vmathV4MakeFromElems( &aos_Vector4_2, 8.0f, 9.0f, 10.0f, 11.0f );
455     vmathV4MakeFromElems( &aos_Vector4_3, 12.0f, 13.0f, 14.0f, 15.0f );
456     vmathV4Prints( &aos_Vector4_3, "aos type 0" );
457     vmathV4Prints( &aos_Vector4_2, "aos type 1" );
458     vmathV4Prints( &aos_Vector4_1, "aos type 2" );
459     vmathV4Prints( &aos_Vector4_0, "aos type 3" );
460     vmathV4Select( &tmpV4_0, &a_Vector4, &b_Vector4, 0 );
461     vmathV4Prints( &tmpV4_0, "select 0" );
462     vmathV4Select( &tmpV4_1, &a_Vector4, &b_Vector4, 1 );
463     vmathV4Prints( &tmpV4_1, "select 1" );
464     vmathV4Select( &tmpV4_2, &a_Vector4, &b_Vector4, 0 );
465     vmathV4Prints( &tmpV4_2, "select 2" );
466     vmathV4Select( &tmpV4_3, &a_Vector4, &b_Vector4, (unsigned int)-1 );
467     vmathV4Prints( &tmpV4_3, "select 3" );
468     vmathV4Copy( &a_Vector4, &b_Vector4 );
469     vmathV4Prints( &a_Vector4, "assign to Vector4 from Vector4" );
470     vmathV4SetXYZ( &a_Vector4, &a_Vector3 );
471     vmathV4Prints( &a_Vector4, "set Vector4 xyz" );
472     vmathV4GetXYZ( &tmpV3_4, &a_Vector4 );
473     vmathV3Prints( &tmpV3_4, "get Vector4 xyz" );
474     vmathV4MakeFromScalar( &a_Vector4, 0.0f );
475     vmathV4Prints( &a_Vector4, "set Vector4 elements to zero" );
476     vmathV4MakeXAxis( &a_Vector4 );
477     vmathV4Prints( &a_Vector4, "set to x axis" );
478     vmathV4MakeYAxis( &a_Vector4 );
479     vmathV4Prints( &a_Vector4, "set to y axis" );
480     vmathV4MakeZAxis( &a_Vector4 );
481     vmathV4Prints( &a_Vector4, "set to z axis" );
482     vmathV4MakeWAxis( &a_Vector4 );
483     vmathV4Prints( &a_Vector4, "set to w axis" );
484     vmathV4SetElem( &a_Vector4, 0, randfloat() );
485     vmathV4Prints( &a_Vector4, "Vector4::set( 0, float )" );
486     vmathV4SetElem( &a_Vector4, 0, randfloat() );
487     vmathV4SetElem( &a_Vector4, 0, ( vmathV4GetElem( &a_Vector4, 0 ) * randfloat() ) );
488     vmathV4SetElem( &a_Vector4, 0, ( vmathV4GetElem( &a_Vector4, 0 ) / randfloat() ) );
489     vmathV4SetElem( &a_Vector4, 0, ( vmathV4GetElem( &a_Vector4, 0 ) + randfloat() ) );
490     vmathV4SetElem( &a_Vector4, 0, ( vmathV4GetElem( &a_Vector4, 0 ) - randfloat() ) );
491     vmathV4Prints( &a_Vector4, "Vector4::operator [](0)" );
492     vmathV4SetX( &a_Vector4, randfloat() );
493     vmathV4Prints( &a_Vector4, "Vector4::setX()" );
494     vmathV4SetElem( &a_Vector4, 1, randfloat() );
495     vmathV4Prints( &a_Vector4, "Vector4::set( 1, float )" );
496     vmathV4SetElem( &a_Vector4, 1, randfloat() );
497     vmathV4SetElem( &a_Vector4, 1, ( vmathV4GetElem( &a_Vector4, 1 ) * randfloat() ) );
498     vmathV4SetElem( &a_Vector4, 1, ( vmathV4GetElem( &a_Vector4, 1 ) / randfloat() ) );
499     vmathV4SetElem( &a_Vector4, 1, ( vmathV4GetElem( &a_Vector4, 1 ) + randfloat() ) );
500     vmathV4SetElem( &a_Vector4, 1, ( vmathV4GetElem( &a_Vector4, 1 ) - randfloat() ) );
501     vmathV4Prints( &a_Vector4, "Vector4::operator [](1)" );
502     vmathV4SetY( &a_Vector4, randfloat() );
503     vmathV4Prints( &a_Vector4, "Vector4::setY()" );
504     vmathV4SetElem( &a_Vector4, 2, randfloat() );
505     vmathV4Prints( &a_Vector4, "Vector4::set( 2, float )" );
506     vmathV4SetElem( &a_Vector4, 2, randfloat() );
507     vmathV4SetElem( &a_Vector4, 2, ( vmathV4GetElem( &a_Vector4, 2 ) * randfloat() ) );
508     vmathV4SetElem( &a_Vector4, 2, ( vmathV4GetElem( &a_Vector4, 2 ) / randfloat() ) );
509     vmathV4SetElem( &a_Vector4, 2, ( vmathV4GetElem( &a_Vector4, 2 ) + randfloat() ) );
510     vmathV4SetElem( &a_Vector4, 2, ( vmathV4GetElem( &a_Vector4, 2 ) - randfloat() ) );
511     vmathV4Prints( &a_Vector4, "Vector4::operator [](2)" );
512     vmathV4SetZ( &a_Vector4, randfloat() );
513     vmathV4Prints( &a_Vector4, "Vector4::setZ()" );
514     vmathV4SetElem( &a_Vector4, 3, randfloat() );
515     vmathV4Prints( &a_Vector4, "Vector4::set( 3, float )" );
516     vmathV4SetElem( &a_Vector4, 3, randfloat() );
517     vmathV4SetElem( &a_Vector4, 3, ( vmathV4GetElem( &a_Vector4, 3 ) * randfloat() ) );
518     vmathV4SetElem( &a_Vector4, 3, ( vmathV4GetElem( &a_Vector4, 3 ) / randfloat() ) );
519     vmathV4SetElem( &a_Vector4, 3, ( vmathV4GetElem( &a_Vector4, 3 ) + randfloat() ) );
520     vmathV4SetElem( &a_Vector4, 3, ( vmathV4GetElem( &a_Vector4, 3 ) - randfloat() ) );
521     vmathV4Prints( &a_Vector4, "Vector4::operator [](3)" );
522     vmathV4SetW( &a_Vector4, randfloat() );
523     vmathV4Prints( &a_Vector4, "Vector4::setW()" );
524     printf("Vector4::get( 0 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 0 )) );
525     printf("Vector4::operator []( 0 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 0 )) );
526     printf("Vector4::getX(): %f\n", getfloat(vmathV4GetX( &a_Vector4 )) );
527     printf("Vector4::get( 1 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 1 )) );
528     printf("Vector4::operator []( 1 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 1 )) );
529     printf("Vector4::getY(): %f\n", getfloat(vmathV4GetY( &a_Vector4 )) );
530     printf("Vector4::get( 2 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 2 )) );
531     printf("Vector4::operator []( 2 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 2 )) );
532     printf("Vector4::getZ(): %f\n", getfloat(vmathV4GetZ( &a_Vector4 )) );
533     printf("Vector4::get( 3 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 3 )) );
534     printf("Vector4::operator []( 3 ): %f\n", getfloat(vmathV4GetElem( &a_Vector4, 3 )) );
535     printf("Vector4::getW(): %f\n", getfloat(vmathV4GetW( &a_Vector4 )) );
536     vmathV4Add( &tmpV4_4, &a_Vector4, &b_Vector4 );
537     vmathV4Prints( &tmpV4_4, "Vector4 + Vector4" );
538     vmathV4Sub( &tmpV4_5, &a_Vector4, &b_Vector4 );
539     vmathV4Prints( &tmpV4_5, "Vector4 - Vector4" );
540     vmathV4ScalarMul( &tmpV4_6, &a_Vector4, randfloat() );
541     vmathV4Prints( &tmpV4_6, "Vector4 * float" );
542     vmathV4ScalarDiv( &tmpV4_7, &a_Vector4, randfloat() );
543     vmathV4Prints( &tmpV4_7, "Vector4 / float" );
544     vmathV4ScalarMul( &tmpV4_8, &a_Vector4, randfloat() );
545     vmathV4Prints( &tmpV4_8, "float * Vector4" );
546     vmathV4Neg( &tmpV4_9, &a_Vector4 );
547     vmathV4Prints( &tmpV4_9, "Vector4 negate" );
548     vmathV4MulPerElem( &tmpV4_10, &a_Vector4, &b_Vector4 );
549     vmathV4Prints( &tmpV4_10, "mulPerElem( Vector4, Vector4 )" );
550     vmathV4DivPerElem( &tmpV4_11, &a_Vector4, &b_Vector4 );
551     vmathV4Prints( &tmpV4_11, "divPerElem( Vector4, Vector4 )" );
552     vmathV4RecipPerElem( &tmpV4_12, &a_Vector4 );
553     vmathV4Prints( &tmpV4_12, "Vector4 recip" );
554     vmathV4AbsPerElem( &tmpV4_13, &a_Vector4 );
555     vmathV4SqrtPerElem( &tmpV4_14, &tmpV4_13 );
556     vmathV4Prints( &tmpV4_14, "Vector4 sqrt" );
557     vmathV4AbsPerElem( &tmpV4_15, &a_Vector4 );
558     vmathV4RsqrtPerElem( &tmpV4_16, &tmpV4_15 );
559     vmathV4Prints( &tmpV4_16, "Vector4 rsqrt" );
560     vmathV4AbsPerElem( &tmpV4_17, &a_Vector4 );
561     vmathV4Prints( &tmpV4_17, "Vector4 abs" );
562     vmathV4CopySignPerElem( &tmpV4_18, &a_Vector4, &b_Vector4 );
563     vmathV4Prints( &tmpV4_18, "Vector4 copySign" );
564     vmathV4MaxPerElem( &tmpV4_19, &a_Vector4, &b_Vector4 );
565     vmathV4Prints( &tmpV4_19, "Vector4 maximum Vector4" );
566     vmathV4MinPerElem( &tmpV4_20, &a_Vector4, &b_Vector4 );
567     vmathV4Prints( &tmpV4_20, "Vector4 minimum Vector4" );
568     printf("Vector4 maximum of elements: %f\n", getfloat(vmathV4MaxElem( &a_Vector4 )));
569     printf("Vector4 minimum of elements: %f\n", getfloat(vmathV4MinElem( &a_Vector4 )));
570     printf("Vector4 sum of elements: %f\n", getfloat(vmathV4Sum( &a_Vector4 )));
571     printf("Vector4 dot Vector4: %f\n", getfloat(vmathV4Dot( &a_Vector4, &b_Vector4 )));
572     printf("Vector4 lengthSqr: %f\n", getfloat(vmathV4LengthSqr( &a_Vector4 )));
573     printf("Vector4 length: %f\n", getfloat(vmathV4Length( &a_Vector4 )));
574     vmathV4Normalize( &tmpV4_21, &a_Vector4 );
575     vmathV4Prints( &tmpV4_21, "Vector4 normalized" );
576     rndflt1 = randfloat();
577     rndflt2 = randfloat();
578     rndflt3 = randfloat();
579     rndflt4 = randfloat();
580     vmathV4MakeFromElems( &b_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
581     rndflt1 = randfloat();
582     rndflt2 = randfloat();
583     rndflt3 = randfloat();
584     rndflt4 = randfloat();
585     vmathV4MakeFromElems( &c_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
586     rndflt1 = randfloat();
587     rndflt2 = randfloat();
588     rndflt3 = randfloat();
589     rndflt4 = randfloat();
590     vmathV4MakeFromElems( &d_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
591     rndflt1 = randfloat();
592     rndflt2 = randfloat();
593     rndflt3 = randfloat();
594     rndflt4 = randfloat();
595     vmathV4MakeFromElems( &e_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
596     vmathV4Normalize( &b_Vector4, &b_Vector4 );
597     vmathV4Normalize( &c_Vector4, &c_Vector4 );
598     vmathV4Normalize( &d_Vector4, &d_Vector4 );
599     vmathV4Normalize( &e_Vector4, &e_Vector4 );
600     vmathV4Lerp( &a_Vector4, randfloat(), &b_Vector4, &c_Vector4 );
601     vmathV4Prints( &a_Vector4, "Vector4 lerp" );
602     vmathV4Slerp( &a_Vector4, randfloat(), &b_Vector4, &c_Vector4 );
603     vmathV4Prints( &a_Vector4, "Vector4 slerp" );
604 }
605
606 void
607 Point3_methods_test()
608 {
609     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
610     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
611     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
612     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
613     VmathVector4 tmpV4;
614     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3;
615     VmathPoint3 aos_Point3_0, aos_Point3_1, aos_Point3_2, aos_Point3_3, tmpP3_0, tmpP3_1, tmpP3_2, tmpP3_3;
616     VmathVector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2;
617     VmathVector3 tmpV3_4;
618     VmathPoint3 tmpP3_4, tmpP3_5, tmpP3_6, tmpP3_7, tmpP3_8, tmpP3_9, tmpP3_10, tmpP3_11, tmpP3_12, tmpP3_13, tmpP3_14, tmpP3_15, tmpP3_16;
619     float rndflt1, rndflt2, rndflt3, rndflt4, pad;
620     float xyz4[12] __attribute__ ((aligned(16)));
621 #ifndef _VECTORMATH_SCALAR_TEST
622     vec_float4 quad;
623 #endif
624     xyz4[0] = randfloat();
625     xyz4[1] = randfloat();
626     xyz4[2] = randfloat();
627     xyz4[3] = randfloat();
628     xyz4[4] = randfloat();
629     xyz4[5] = randfloat();
630     xyz4[6] = randfloat();
631     xyz4[7] = randfloat();
632     xyz4[8] = randfloat();
633     xyz4[9] = randfloat();
634     xyz4[10] = randfloat();
635     xyz4[11] = randfloat();
636     // set a pad value to detect invalid use of padding.
637     // this will be nan for scalar/ppu implementations, max. float for spu
638     union { float f; unsigned int u; } tmp;
639     tmp.u = 0x7fffffff;
640     pad = tmp.f;
641     rndflt1 = randfloat();
642     rndflt2 = randfloat();
643     rndflt3 = randfloat();
644     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
645     rndflt1 = randfloat();
646     rndflt2 = randfloat();
647     rndflt3 = randfloat();
648     vmathV3MakeFromElems( &b_Vector3, rndflt1, rndflt2, rndflt3 );
649     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
650     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
651     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
652     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
653     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
654     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
655     vmathV3MakeFromScalar( &c_Vector3, 0.0f );
656     vmathV3MakeFromScalar( &d_Vector3, 0.0f );
657     vmathV3MakeFromScalar( &e_Vector3, 0.0f );
658     vmathV3Prints( &c_Vector3, "set Vector3 elements to zero" );
659     vmathV3Prints( &d_Vector3, "set Vector3 elements to zero" );
660     vmathV3Prints( &e_Vector3, "set Vector3 elements to zero" );
661     rndflt1 = randfloat();
662     rndflt2 = randfloat();
663     rndflt3 = randfloat();
664     rndflt4 = randfloat();
665     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
666     rndflt1 = randfloat();
667     rndflt2 = randfloat();
668     rndflt3 = randfloat();
669     rndflt4 = randfloat();
670     vmathV4MakeFromElems( &b_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
671     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
672     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
673     vmathV4MakeFromScalar( &c_Vector4, 0.0f );
674     vmathV4MakeFromScalar( &d_Vector4, 0.0f );
675     vmathV4MakeFromScalar( &e_Vector4, 0.0f );
676     vmathV4Prints( &c_Vector4, "set Vector4 elements to zero" );
677     vmathV4Prints( &d_Vector4, "set Vector4 elements to zero" );
678     vmathV4Prints( &e_Vector4, "set Vector4 elements to zero" );
679     rndflt1 = randfloat();
680     rndflt2 = randfloat();
681     rndflt3 = randfloat();
682     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
683     rndflt1 = randfloat();
684     rndflt2 = randfloat();
685     rndflt3 = randfloat();
686     vmathP3MakeFromElems( &b_Point3, rndflt1, rndflt2, rndflt3 );
687     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
688     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
689     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
690     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
691     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
692     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
693     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
694     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
695     vmathP3Prints( &a_Point3, "set Point3 with floats" );
696     vmathP3Prints( &b_Point3, "set Point3 with floats" );
697     vmathP3MakeFromScalar( &c_Point3, 0.0f );
698     vmathP3MakeFromScalar( &d_Point3, 0.0f );
699     vmathP3MakeFromScalar( &e_Point3, 0.0f );
700     vmathP3Prints( &c_Point3, "set Point3 elements to zero" );
701     vmathP3Prints( &d_Point3, "set Point3 elements to zero" );
702     vmathP3Prints( &e_Point3, "set Point3 elements to zero" );
703     rndflt1 = randfloat();
704     rndflt2 = randfloat();
705     rndflt3 = randfloat();
706     rndflt4 = randfloat();
707     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
708     rndflt1 = randfloat();
709     rndflt2 = randfloat();
710     rndflt3 = randfloat();
711     rndflt4 = randfloat();
712     vmathQMakeFromElems( &b_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
713     vmathQPrints( &a_Quat, "set Quat with floats" );
714     vmathQPrints( &b_Quat, "set Quat with floats" );
715     vmathQMakeFromScalar( &c_Quat, 0.0f );
716     vmathQMakeFromScalar( &d_Quat, 0.0f );
717     vmathQMakeFromScalar( &e_Quat, 0.0f );
718     vmathQPrints( &c_Quat, "set Quat elements to zero" );
719     vmathQPrints( &d_Quat, "set Quat elements to zero" );
720     vmathQPrints( &e_Quat, "set Quat elements to zero" );
721     vmathP3MakeFromV3( &a_Point3, &a_Vector3 );
722     vmathP3Prints( &a_Point3, "construct Point3 with Vector3" );
723     vmathP3MakeFromScalar( &a_Point3, randfloat() );
724     vmathP3Prints( &a_Point3, "set Point3 with float" );
725     vmathP3MakeFromScalar( &a_Point3, randfloat() );
726     vmathP3Prints( &a_Point3, "set Point3 with float" );
727     vmathP3MakeFromElems( &aos_Point3_0, 0.0f, 1.0f, 2.0f );
728     vmathP3MakeFromElems( &aos_Point3_1, 3.0f, 4.0f, 5.0f );
729     vmathP3MakeFromElems( &aos_Point3_2, 6.0f, 7.0f, 8.0f );
730     vmathP3MakeFromElems( &aos_Point3_3, 9.0f, 10.0f, 11.0f );
731     vmathP3Prints( &aos_Point3_3, "aos type 0" );
732     vmathP3Prints( &aos_Point3_2, "aos type 1" );
733     vmathP3Prints( &aos_Point3_1, "aos type 2" );
734     vmathP3Prints( &aos_Point3_0, "aos type 3" );
735     vmathP3Select( &tmpP3_0, &a_Point3, &b_Point3, 0 );
736     vmathP3Prints( &tmpP3_0, "select 0" );
737     vmathP3Select( &tmpP3_1, &a_Point3, &b_Point3, 1 );
738     vmathP3Prints( &tmpP3_1, "select 1" );
739     vmathP3Select( &tmpP3_2, &a_Point3, &b_Point3, 0 );
740     vmathP3Prints( &tmpP3_2, "select 2" );
741     vmathP3Select( &tmpP3_3, &a_Point3, &b_Point3, (unsigned int)-1 );
742     vmathP3Prints( &tmpP3_3, "select 3" );
743     vmathP3MakeFromElems( &a_Point3, xyz4[0], xyz4[1], xyz4[2] );
744     vmathP3Prints( &a_Point3, "load XYZ array" );
745     xyz4[0] = -xyz4[0];
746     xyz4[1] = -xyz4[1];
747     xyz4[2] = -xyz4[2];
748     xyz4[3] = -xyz4[3];
749     xyz4[4] = -xyz4[4];
750     xyz4[5] = -xyz4[5];
751     xyz4[6] = -xyz4[6];
752     xyz4[7] = -xyz4[7];
753     xyz4[8] = -xyz4[8];
754     xyz4[9] = -xyz4[9];
755     xyz4[10] = -xyz4[10];
756     xyz4[11] = -xyz4[11];
757     vmathV4MakeFromElems( &aos_Vector4_0, xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
758     vmathV4MakeFromElems( &aos_Vector4_1, xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
759     vmathV4MakeFromElems( &aos_Vector4_2, xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
760     vmathV4Prints( &aos_Vector4_0, "xyzx" );
761     vmathV4Prints( &aos_Vector4_1, "yzxy" );
762     vmathV4Prints( &aos_Vector4_2, "zxyz" );
763 #ifndef _VECTORMATH_SCALAR_TEST
764     vmathP3LoadXYZArray( &aos_Point3_0, &aos_Point3_1, &aos_Point3_2, &aos_Point3_3, (const vec_float4 *)xyz4 );
765     xyz4[0] = 0;
766     xyz4[1] = 1;
767     xyz4[2] = 2;
768     xyz4[3] = 3;
769     xyz4[4] = 4;
770     xyz4[5] = 5;
771     xyz4[6] = 6;
772     xyz4[7] = 7;
773     xyz4[8] = 8;
774     xyz4[9] = 9;
775     xyz4[10] = 10;
776     xyz4[11] = 11;
777     vmathP3StoreXYZArray( &aos_Point3_0, &aos_Point3_1, &aos_Point3_2, &aos_Point3_3, (vec_float4 *)xyz4 );
778 #endif
779     vmathV4MakeFromElems( &aos_Vector4_0, xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
780     vmathV4MakeFromElems( &aos_Vector4_1, xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
781     vmathV4MakeFromElems( &aos_Vector4_2, xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
782     vmathV4Prints( &aos_Vector4_0, "xyzx" );
783     vmathV4Prints( &aos_Vector4_1, "yzxy" );
784     vmathV4Prints( &aos_Vector4_2, "zxyz" );
785 #ifdef _VECTORMATH_SCALAR_TEST
786     printf("storeXYZ:-1.0 -2.0 -3.0 0.4\n");
787 #else
788     quad = (vec_float4){-1.0f, -2.0f, -3.0f, -4.0f};
789     a_Point3.vec128 = quad;
790     quad = (vec_float4){0.1f, 0.2f, 0.3f, 0.4f};
791     vmathP3StoreXYZ( &a_Point3, &quad );
792     printf("storeXYZ:%f %f %f %f\n", ((float *)&quad)[0], ((float *)&quad)[1], ((float *)&quad)[2], ((float *)&quad)[3]);
793 #endif
794     vmathP3Copy( &a_Point3, &b_Point3 );
795     vmathP3Prints( &a_Point3, "assign to Point3 from Point3" );
796     vmathP3MakeFromScalar( &a_Point3, 0.0f );
797     vmathP3Prints( &a_Point3, "set Point3 elements to zero" );
798     vmathP3SetElem( &a_Point3, 0, randfloat() );
799     vmathP3Prints( &a_Point3, "Point3::set( 0, float )" );
800     vmathP3SetElem( &a_Point3, 0, randfloat() );
801     vmathP3SetElem( &a_Point3, 0, ( vmathP3GetElem( &a_Point3, 0 ) * randfloat() ) );
802     vmathP3SetElem( &a_Point3, 0, ( vmathP3GetElem( &a_Point3, 0 ) / randfloat() ) );
803     vmathP3SetElem( &a_Point3, 0, ( vmathP3GetElem( &a_Point3, 0 ) + randfloat() ) );
804     vmathP3SetElem( &a_Point3, 0, ( vmathP3GetElem( &a_Point3, 0 ) - randfloat() ) );
805     vmathP3Prints( &a_Point3, "Point3::operator [](0)" );
806     vmathP3SetX( &a_Point3, randfloat() );
807     vmathP3Prints( &a_Point3, "Point3::setX()" );
808     vmathP3SetElem( &a_Point3, 1, randfloat() );
809     vmathP3Prints( &a_Point3, "Point3::set( 1, float )" );
810     vmathP3SetElem( &a_Point3, 1, randfloat() );
811     vmathP3SetElem( &a_Point3, 1, ( vmathP3GetElem( &a_Point3, 1 ) * randfloat() ) );
812     vmathP3SetElem( &a_Point3, 1, ( vmathP3GetElem( &a_Point3, 1 ) / randfloat() ) );
813     vmathP3SetElem( &a_Point3, 1, ( vmathP3GetElem( &a_Point3, 1 ) + randfloat() ) );
814     vmathP3SetElem( &a_Point3, 1, ( vmathP3GetElem( &a_Point3, 1 ) - randfloat() ) );
815     vmathP3Prints( &a_Point3, "Point3::operator [](1)" );
816     vmathP3SetY( &a_Point3, randfloat() );
817     vmathP3Prints( &a_Point3, "Point3::setY()" );
818     vmathP3SetElem( &a_Point3, 2, randfloat() );
819     vmathP3Prints( &a_Point3, "Point3::set( 2, float )" );
820     vmathP3SetElem( &a_Point3, 2, randfloat() );
821     vmathP3SetElem( &a_Point3, 2, ( vmathP3GetElem( &a_Point3, 2 ) * randfloat() ) );
822     vmathP3SetElem( &a_Point3, 2, ( vmathP3GetElem( &a_Point3, 2 ) / randfloat() ) );
823     vmathP3SetElem( &a_Point3, 2, ( vmathP3GetElem( &a_Point3, 2 ) + randfloat() ) );
824     vmathP3SetElem( &a_Point3, 2, ( vmathP3GetElem( &a_Point3, 2 ) - randfloat() ) );
825     vmathP3Prints( &a_Point3, "Point3::operator [](2)" );
826     vmathP3SetZ( &a_Point3, randfloat() );
827     vmathP3Prints( &a_Point3, "Point3::setZ()" );
828     printf("Point3::get( 0 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 0 )) );
829     printf("Point3::operator []( 0 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 0 )) );
830     printf("Point3::getX(): %f\n", getfloat(vmathP3GetX( &a_Point3 )) );
831     printf("Point3::get( 1 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 1 )) );
832     printf("Point3::operator []( 1 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 1 )) );
833     printf("Point3::getY(): %f\n", getfloat(vmathP3GetY( &a_Point3 )) );
834     printf("Point3::get( 2 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 2 )) );
835     printf("Point3::operator []( 2 ): %f\n", getfloat(vmathP3GetElem( &a_Point3, 2 )) );
836     printf("Point3::getZ(): %f\n", getfloat(vmathP3GetZ( &a_Point3 )) );
837     vmathP3Sub( &tmpV3_4, &a_Point3, &b_Point3 );
838     vmathV3Prints( &tmpV3_4, "Point3 - Point3" );
839     vmathP3AddV3( &tmpP3_4, &a_Point3, &b_Vector3 );
840     vmathP3Prints( &tmpP3_4, "Point3 + Vector3" );
841     vmathP3SubV3( &tmpP3_5, &a_Point3, &b_Vector3 );
842     vmathP3Prints( &tmpP3_5, "Point3 - Vector3" );
843     vmathP3MulPerElem( &tmpP3_6, &a_Point3, &b_Point3 );
844     vmathP3Prints( &tmpP3_6, "mulPerElem( Point3, Point3 )" );
845     vmathP3DivPerElem( &tmpP3_7, &a_Point3, &b_Point3 );
846     vmathP3Prints( &tmpP3_7, "divPerElem( Point3, Point3 )" );
847     vmathP3RecipPerElem( &tmpP3_8, &a_Point3 );
848     vmathP3Prints( &tmpP3_8, "Point3 recip" );
849     vmathP3AbsPerElem( &tmpP3_9, &a_Point3 );
850     vmathP3SqrtPerElem( &tmpP3_10, &tmpP3_9 );
851     vmathP3Prints( &tmpP3_10, "Point3 sqrt" );
852     vmathP3AbsPerElem( &tmpP3_11, &a_Point3 );
853     vmathP3RsqrtPerElem( &tmpP3_12, &tmpP3_11 );
854     vmathP3Prints( &tmpP3_12, "Point3 rsqrt" );
855     vmathP3AbsPerElem( &tmpP3_13, &a_Point3 );
856     vmathP3Prints( &tmpP3_13, "Point3 abs" );
857     vmathP3CopySignPerElem( &tmpP3_14, &a_Point3, &b_Point3 );
858     vmathP3Prints( &tmpP3_14, "Point3 copySign" );
859     vmathP3MaxPerElem( &tmpP3_15, &a_Point3, &b_Point3 );
860     vmathP3Prints( &tmpP3_15, "Point3 maximum Point3" );
861     vmathP3MinPerElem( &tmpP3_16, &a_Point3, &b_Point3 );
862     vmathP3Prints( &tmpP3_16, "Point3 minimum Point3" );
863     printf("Point3 maximum of elements: %f\n", getfloat(vmathP3MaxElem( &a_Point3 )));
864     printf("Point3 minimum of elements: %f\n", getfloat(vmathP3MinElem( &a_Point3 )));
865     printf("Point3 sum of elements: %f\n", getfloat(vmathP3Sum( &a_Point3 )));
866     printf("Point projection: %f\n", getfloat(vmathP3Projection( &a_Point3, &b_Vector3 )));
867     printf("Point distSqrFromOrigin: %f\n", getfloat(vmathP3DistSqrFromOrigin( &a_Point3 )) );
868     printf("Point distFromOrigin: %f\n", getfloat(vmathP3DistFromOrigin( &a_Point3 )) );
869     printf("Point distSqr: %f\n", getfloat(vmathP3DistSqr( &a_Point3, &b_Point3 )) );
870     printf("Point dist: %f\n", getfloat(vmathP3Dist( &a_Point3, &b_Point3 )) );
871     rndflt1 = randfloat();
872     rndflt2 = randfloat();
873     rndflt3 = randfloat();
874     vmathP3MakeFromElems( &b_Point3, rndflt1, rndflt2, rndflt3 );
875     rndflt1 = randfloat();
876     rndflt2 = randfloat();
877     rndflt3 = randfloat();
878     vmathP3MakeFromElems( &c_Point3, rndflt1, rndflt2, rndflt3 );
879     rndflt1 = randfloat();
880     rndflt2 = randfloat();
881     rndflt3 = randfloat();
882     vmathP3MakeFromElems( &d_Point3, rndflt1, rndflt2, rndflt3 );
883     rndflt1 = randfloat();
884     rndflt2 = randfloat();
885     rndflt3 = randfloat();
886     vmathP3MakeFromElems( &e_Point3, rndflt1, rndflt2, rndflt3 );
887     vmathP3Lerp( &a_Point3, randfloat(), &b_Point3, &c_Point3 );
888     vmathP3Prints( &a_Point3, "Point3 lerp" );
889 }
890
891 void
892 Quat_methods_test()
893 {
894     VmathVector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
895     VmathVector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
896     VmathPoint3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
897     VmathQuat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
898     VmathVector4 tmpV4;
899     VmathVector3 tmpV3_0, tmpV3_1, tmpV3_2, tmpV3_3;
900     VmathQuat aos_Quat_0, aos_Quat_1, aos_Quat_2, aos_Quat_3, tmpQ_0, tmpQ_1, tmpQ_2, tmpQ_3;
901     VmathVector3 tmpV3_4;
902     VmathQuat tmpQ_4, tmpQ_5, tmpQ_6, tmpQ_7, tmpQ_8, tmpQ_9, tmpQ_10, tmpQ_11;
903     VmathVector3 tmpV3_5;
904     VmathQuat tmpQ_12;
905     float rndflt1, rndflt2, rndflt3, rndflt4, pad;
906     // set a pad value to detect invalid use of padding.
907     // this will be nan for scalar/ppu implementations, max. float for spu
908     union { float f; unsigned int u; } tmp;
909     tmp.u = 0x7fffffff;
910     pad = tmp.f;
911     rndflt1 = randfloat();
912     rndflt2 = randfloat();
913     rndflt3 = randfloat();
914     vmathV3MakeFromElems( &a_Vector3, rndflt1, rndflt2, rndflt3 );
915     rndflt1 = randfloat();
916     rndflt2 = randfloat();
917     rndflt3 = randfloat();
918     vmathV3MakeFromElems( &b_Vector3, rndflt1, rndflt2, rndflt3 );
919     vmathV4MakeFromV3Scalar( &tmpV4, &a_Vector3, pad );
920     vmathV4GetXYZ( &a_Vector3, &tmpV4 );
921     vmathV4MakeFromV3Scalar( &tmpV4, &b_Vector3, pad );
922     vmathV4GetXYZ( &b_Vector3, &tmpV4 );
923     vmathV3Prints( &a_Vector3, "set Vector3 with floats" );
924     vmathV3Prints( &b_Vector3, "set Vector3 with floats" );
925     vmathV3MakeFromScalar( &c_Vector3, 0.0f );
926     vmathV3MakeFromScalar( &d_Vector3, 0.0f );
927     vmathV3MakeFromScalar( &e_Vector3, 0.0f );
928     vmathV3Prints( &c_Vector3, "set Vector3 elements to zero" );
929     vmathV3Prints( &d_Vector3, "set Vector3 elements to zero" );
930     vmathV3Prints( &e_Vector3, "set Vector3 elements to zero" );
931     rndflt1 = randfloat();
932     rndflt2 = randfloat();
933     rndflt3 = randfloat();
934     rndflt4 = randfloat();
935     vmathV4MakeFromElems( &a_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
936     rndflt1 = randfloat();
937     rndflt2 = randfloat();
938     rndflt3 = randfloat();
939     rndflt4 = randfloat();
940     vmathV4MakeFromElems( &b_Vector4, rndflt1, rndflt2, rndflt3, rndflt4 );
941     vmathV4Prints( &a_Vector4, "set Vector4 with floats" );
942     vmathV4Prints( &b_Vector4, "set Vector4 with floats" );
943     vmathV4MakeFromScalar( &c_Vector4, 0.0f );
944     vmathV4MakeFromScalar( &d_Vector4, 0.0f );
945     vmathV4MakeFromScalar( &e_Vector4, 0.0f );
946     vmathV4Prints( &c_Vector4, "set Vector4 elements to zero" );
947     vmathV4Prints( &d_Vector4, "set Vector4 elements to zero" );
948     vmathV4Prints( &e_Vector4, "set Vector4 elements to zero" );
949     rndflt1 = randfloat();
950     rndflt2 = randfloat();
951     rndflt3 = randfloat();
952     vmathP3MakeFromElems( &a_Point3, rndflt1, rndflt2, rndflt3 );
953     rndflt1 = randfloat();
954     rndflt2 = randfloat();
955     rndflt3 = randfloat();
956     vmathP3MakeFromElems( &b_Point3, rndflt1, rndflt2, rndflt3 );
957     vmathV3MakeFromP3( &tmpV3_0, &a_Point3 );
958     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_0, pad );
959     vmathV4GetXYZ( &tmpV3_1, &tmpV4 );
960     vmathP3MakeFromV3( &a_Point3, &tmpV3_1 );
961     vmathV3MakeFromP3( &tmpV3_2, &b_Point3 );
962     vmathV4MakeFromV3Scalar( &tmpV4, &tmpV3_2, pad );
963     vmathV4GetXYZ( &tmpV3_3, &tmpV4 );
964     vmathP3MakeFromV3( &b_Point3, &tmpV3_3 );
965     vmathP3Prints( &a_Point3, "set Point3 with floats" );
966     vmathP3Prints( &b_Point3, "set Point3 with floats" );
967     vmathP3MakeFromScalar( &c_Point3, 0.0f );
968     vmathP3MakeFromScalar( &d_Point3, 0.0f );
969     vmathP3MakeFromScalar( &e_Point3, 0.0f );
970     vmathP3Prints( &c_Point3, "set Point3 elements to zero" );
971     vmathP3Prints( &d_Point3, "set Point3 elements to zero" );
972     vmathP3Prints( &e_Point3, "set Point3 elements to zero" );
973     rndflt1 = randfloat();
974     rndflt2 = randfloat();
975     rndflt3 = randfloat();
976     rndflt4 = randfloat();
977     vmathQMakeFromElems( &a_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
978     rndflt1 = randfloat();
979     rndflt2 = randfloat();
980     rndflt3 = randfloat();
981     rndflt4 = randfloat();
982     vmathQMakeFromElems( &b_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
983     vmathQPrints( &a_Quat, "set Quat with floats" );
984     vmathQPrints( &b_Quat, "set Quat with floats" );
985     vmathQMakeFromScalar( &c_Quat, 0.0f );
986     vmathQMakeFromScalar( &d_Quat, 0.0f );
987     vmathQMakeFromScalar( &e_Quat, 0.0f );
988     vmathQPrints( &c_Quat, "set Quat elements to zero" );
989     vmathQPrints( &d_Quat, "set Quat elements to zero" );
990     vmathQPrints( &e_Quat, "set Quat elements to zero" );
991     vmathQMakeFromV3Scalar( &a_Quat, &a_Vector3, randfloat() );
992     vmathQPrints( &a_Quat, "set Quat with Vector3, float" );
993     vmathQMakeFromV4( &a_Quat, &a_Vector4 );
994     vmathQPrints( &a_Quat, "construct Quat with Vector4" );
995     vmathQMakeFromScalar( &a_Quat, randfloat() );
996     vmathQPrints( &a_Quat, "set Quat with float" );
997     vmathQMakeFromScalar( &a_Quat, randfloat() );
998     vmathQPrints( &a_Quat, "set Quat with float" );
999     vmathQMakeFromElems( &aos_Quat_0, 0.0f, 1.0f, 2.0f, 3.0f );
1000     vmathQMakeFromElems( &aos_Quat_1, 4.0f, 5.0f, 6.0f, 7.0f );
1001     vmathQMakeFromElems( &aos_Quat_2, 8.0f, 9.0f, 10.0f, 11.0f );
1002     vmathQMakeFromElems( &aos_Quat_3, 12.0f, 13.0f, 14.0f, 15.0f );
1003     vmathQPrints( &aos_Quat_3, "aos type 0" );
1004     vmathQPrints( &aos_Quat_2, "aos type 1" );
1005     vmathQPrints( &aos_Quat_1, "aos type 2" );
1006     vmathQPrints( &aos_Quat_0, "aos type 3" );
1007     vmathQSelect( &tmpQ_0, &a_Quat, &b_Quat, 0 );
1008     vmathQPrints( &tmpQ_0, "select 0" );
1009     vmathQSelect( &tmpQ_1, &a_Quat, &b_Quat, 1 );
1010     vmathQPrints( &tmpQ_1, "select 1" );
1011     vmathQSelect( &tmpQ_2, &a_Quat, &b_Quat, 0 );
1012     vmathQPrints( &tmpQ_2, "select 2" );
1013     vmathQSelect( &tmpQ_3, &a_Quat, &b_Quat, (unsigned int)-1 );
1014     vmathQPrints( &tmpQ_3, "select 3" );
1015     vmathQCopy( &a_Quat, &b_Quat );
1016     vmathQPrints( &a_Quat, "assign to Quat from Quat" );
1017     vmathQSetXYZ( &a_Quat, &a_Vector3 );
1018     vmathQPrints( &a_Quat, "set Quat xyz" );
1019     vmathQGetXYZ( &tmpV3_4, &a_Quat );
1020     vmathV3Prints( &tmpV3_4, "get Quat xyz" );
1021     vmathQMakeFromScalar( &a_Quat, 0.0f );
1022     vmathQPrints( &a_Quat, "set Quat elements to zero" );
1023     vmathQSetElem( &a_Quat, 0, randfloat() );
1024     vmathQPrints( &a_Quat, "Quat::set( 0, float )" );
1025     vmathQSetElem( &a_Quat, 0, randfloat() );
1026     vmathQSetElem( &a_Quat, 0, ( vmathQGetElem( &a_Quat, 0 ) * randfloat() ) );
1027     vmathQSetElem( &a_Quat, 0, ( vmathQGetElem( &a_Quat, 0 ) / randfloat() ) );
1028     vmathQSetElem( &a_Quat, 0, ( vmathQGetElem( &a_Quat, 0 ) + randfloat() ) );
1029     vmathQSetElem( &a_Quat, 0, ( vmathQGetElem( &a_Quat, 0 ) - randfloat() ) );
1030     vmathQPrints( &a_Quat, "Quat::operator [](0)" );
1031     vmathQSetX( &a_Quat, randfloat() );
1032     vmathQPrints( &a_Quat, "Quat::setX()" );
1033     vmathQSetElem( &a_Quat, 1, randfloat() );
1034     vmathQPrints( &a_Quat, "Quat::set( 1, float )" );
1035     vmathQSetElem( &a_Quat, 1, randfloat() );
1036     vmathQSetElem( &a_Quat, 1, ( vmathQGetElem( &a_Quat, 1 ) * randfloat() ) );
1037     vmathQSetElem( &a_Quat, 1, ( vmathQGetElem( &a_Quat, 1 ) / randfloat() ) );
1038     vmathQSetElem( &a_Quat, 1, ( vmathQGetElem( &a_Quat, 1 ) + randfloat() ) );
1039     vmathQSetElem( &a_Quat, 1, ( vmathQGetElem( &a_Quat, 1 ) - randfloat() ) );
1040     vmathQPrints( &a_Quat, "Quat::operator [](1)" );
1041     vmathQSetY( &a_Quat, randfloat() );
1042     vmathQPrints( &a_Quat, "Quat::setY()" );
1043     vmathQSetElem( &a_Quat, 2, randfloat() );
1044     vmathQPrints( &a_Quat, "Quat::set( 2, float )" );
1045     vmathQSetElem( &a_Quat, 2, randfloat() );
1046     vmathQSetElem( &a_Quat, 2, ( vmathQGetElem( &a_Quat, 2 ) * randfloat() ) );
1047     vmathQSetElem( &a_Quat, 2, ( vmathQGetElem( &a_Quat, 2 ) / randfloat() ) );
1048     vmathQSetElem( &a_Quat, 2, ( vmathQGetElem( &a_Quat, 2 ) + randfloat() ) );
1049     vmathQSetElem( &a_Quat, 2, ( vmathQGetElem( &a_Quat, 2 ) - randfloat() ) );
1050     vmathQPrints( &a_Quat, "Quat::operator [](2)" );
1051     vmathQSetZ( &a_Quat, randfloat() );
1052     vmathQPrints( &a_Quat, "Quat::setZ()" );
1053     vmathQSetElem( &a_Quat, 3, randfloat() );
1054     vmathQPrints( &a_Quat, "Quat::set( 3, float )" );
1055     vmathQSetElem( &a_Quat, 3, randfloat() );
1056     vmathQSetElem( &a_Quat, 3, ( vmathQGetElem( &a_Quat, 3 ) * randfloat() ) );
1057     vmathQSetElem( &a_Quat, 3, ( vmathQGetElem( &a_Quat, 3 ) / randfloat() ) );
1058     vmathQSetElem( &a_Quat, 3, ( vmathQGetElem( &a_Quat, 3 ) + randfloat() ) );
1059     vmathQSetElem( &a_Quat, 3, ( vmathQGetElem( &a_Quat, 3 ) - randfloat() ) );
1060     vmathQPrints( &a_Quat, "Quat::operator [](3)" );
1061     vmathQSetW( &a_Quat, randfloat() );
1062     vmathQPrints( &a_Quat, "Quat::setW()" );
1063     printf("Quat::get( 0 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 0 )) );
1064     printf("Quat::operator []( 0 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 0 )) );
1065     printf("Quat::getX(): %f\n", getfloat(vmathQGetX( &a_Quat )) );
1066     printf("Quat::get( 1 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 1 )) );
1067     printf("Quat::operator []( 1 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 1 )) );
1068     printf("Quat::getY(): %f\n", getfloat(vmathQGetY( &a_Quat )) );
1069     printf("Quat::get( 2 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 2 )) );
1070     printf("Quat::operator []( 2 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 2 )) );
1071     printf("Quat::getZ(): %f\n", getfloat(vmathQGetZ( &a_Quat )) );
1072     printf("Quat::get( 3 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 3 )) );
1073     printf("Quat::operator []( 3 ): %f\n", getfloat(vmathQGetElem( &a_Quat, 3 )) );
1074     printf("Quat::getW(): %f\n", getfloat(vmathQGetW( &a_Quat )) );
1075     vmathQAdd( &tmpQ_4, &a_Quat, &b_Quat );
1076     vmathQPrints( &tmpQ_4, "Quat + Quat" );
1077     vmathQSub( &tmpQ_5, &a_Quat, &b_Quat );
1078     vmathQPrints( &tmpQ_5, "Quat - Quat" );
1079     vmathQMul( &tmpQ_6, &a_Quat, &b_Quat );
1080     vmathQPrints( &tmpQ_6, "Quat * Quat" );
1081     vmathQScalarMul( &tmpQ_7, &a_Quat, randfloat() );
1082     vmathQPrints( &tmpQ_7, "Quat * float" );
1083     vmathQScalarDiv( &tmpQ_8, &a_Quat, randfloat() );
1084     vmathQPrints( &tmpQ_8, "Quat / float" );
1085     vmathQScalarMul( &tmpQ_9, &a_Quat, randfloat() );
1086     vmathQPrints( &tmpQ_9, "float * Quat" );
1087     vmathQNeg( &tmpQ_10, &a_Quat );
1088     vmathQPrints( &tmpQ_10, "Quat negate" );
1089     printf("Quat dot Quat: %f\n", getfloat(vmathQDot( &a_Quat, &b_Quat )));
1090     printf("Quat lengthSqr: %f\n", getfloat(vmathQNorm( &a_Quat )));
1091     printf("Quat length: %f\n", getfloat(vmathQLength( &a_Quat )));
1092     vmathQNormalize( &tmpQ_11, &a_Quat );
1093     vmathQPrints( &tmpQ_11, "Quat normalized" );
1094     vmathQMakeIdentity( &a_Quat );
1095     vmathQPrints( &a_Quat, "set to identity" );
1096     vmathQMakeRotationArc( &a_Quat, &a_Vector3, &b_Vector3 );
1097     vmathQPrints( &a_Quat, "Quat rotation between vectors" );
1098     vmathQMakeRotationAxis( &a_Quat, randfloat(), &a_Vector3 );
1099     vmathQPrints( &a_Quat, "Quat rotation axis angle" );
1100     vmathQMakeRotationX( &a_Quat, randfloat() );
1101     vmathQPrints( &a_Quat, "Quat rotationX" );
1102     vmathQMakeRotationY( &a_Quat, randfloat() );
1103     vmathQPrints( &a_Quat, "Quat rotationY" );
1104     vmathQMakeRotationZ( &a_Quat, randfloat() );
1105     vmathQPrints( &a_Quat, "Quat rotationZ" );
1106     vmathQRotate( &tmpV3_5, &a_Quat, &a_Vector3 );
1107     vmathV3Prints( &tmpV3_5, "Quat rotate Vector3" );
1108     vmathQConj( &tmpQ_12, &a_Quat );
1109     vmathQPrints( &tmpQ_12, "Quat conj" );
1110     rndflt1 = randfloat();
1111     rndflt2 = randfloat();
1112     rndflt3 = randfloat();
1113     rndflt4 = randfloat();
1114     vmathQMakeFromElems( &b_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
1115     rndflt1 = randfloat();
1116     rndflt2 = randfloat();
1117     rndflt3 = randfloat();
1118     rndflt4 = randfloat();
1119     vmathQMakeFromElems( &c_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
1120     rndflt1 = randfloat();
1121     rndflt2 = randfloat();
1122     rndflt3 = randfloat();
1123     rndflt4 = randfloat();
1124     vmathQMakeFromElems( &d_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
1125     rndflt1 = randfloat();
1126     rndflt2 = randfloat();
1127     rndflt3 = randfloat();
1128     rndflt4 = randfloat();
1129     vmathQMakeFromElems( &e_Quat, rndflt1, rndflt2, rndflt3, rndflt4 );
1130     vmathQNormalize( &b_Quat, &b_Quat );
1131     vmathQNormalize( &c_Quat, &c_Quat );
1132     vmathQNormalize( &d_Quat, &d_Quat );
1133     vmathQNormalize( &e_Quat, &e_Quat );
1134     vmathQLerp( &a_Quat, randfloat(), &b_Quat, &c_Quat );
1135     vmathQPrints( &a_Quat, "Quat lerp" );
1136     vmathQSlerp( &a_Quat, randfloat(), &b_Quat, &c_Quat );
1137     vmathQPrints( &a_Quat, "Quat slerp" );
1138     vmathQSquad( &a_Quat, randfloat(), &b_Quat, &c_Quat, &d_Quat, &e_Quat );
1139     vmathQPrints( &a_Quat, "Quat squad" );
1140 }
1141
1142 int main()
1143 {
1144     printf("\n __begin__ \n");
1145     for ( iteration = 0; iteration < 2; iteration++ ) {
1146         Vector3_methods_test();
1147         Vector4_methods_test();
1148         Point3_methods_test();
1149         Quat_methods_test();
1150     }
1151     printf("\n __end__ \n");
1152     return 0;
1153 }