Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / vectormathlibrary / tests / test1_soa_cpp.cpp
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_SOA_TEST
31
32 #include "vectormath_soa.h"
33 #include "test.h"
34
35 int iteration = 0;
36
37 using namespace Vectormath;
38 using namespace Vectormath::Soa;
39
40 void
41 Vector3_methods_test()
42 {
43     Vector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
44     Vector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
45     Point3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
46     Quat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
47     Aos::Vector3 aos_Vector3_0, aos_Vector3_1, aos_Vector3_2, aos_Vector3_3;
48     Vector3 soa_Vector3;
49     Aos::Vector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2;
50     vec_float4 rndflt1, rndflt2, rndflt3, rndflt4;
51     float xyz4[12] __attribute__ ((aligned(16)));
52     xyz4[0] = getfloat(randfloat());
53     xyz4[1] = getfloat(randfloat());
54     xyz4[2] = getfloat(randfloat());
55     xyz4[3] = getfloat(randfloat());
56     xyz4[4] = getfloat(randfloat());
57     xyz4[5] = getfloat(randfloat());
58     xyz4[6] = getfloat(randfloat());
59     xyz4[7] = getfloat(randfloat());
60     xyz4[8] = getfloat(randfloat());
61     xyz4[9] = getfloat(randfloat());
62     xyz4[10] = getfloat(randfloat());
63     xyz4[11] = getfloat(randfloat());
64     rndflt1 = randfloat();
65     rndflt2 = randfloat();
66     rndflt3 = randfloat();
67     a_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
68     rndflt1 = randfloat();
69     rndflt2 = randfloat();
70     rndflt3 = randfloat();
71     b_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
72     print( a_Vector3, "set Vector3 with floats" );
73     print( b_Vector3, "set Vector3 with floats" );
74     c_Vector3 = Vector3( (vec_float4){0.0f} );
75     d_Vector3 = Vector3( (vec_float4){0.0f} );
76     e_Vector3 = Vector3( (vec_float4){0.0f} );
77     print( c_Vector3, "set Vector3 elements to zero" );
78     print( d_Vector3, "set Vector3 elements to zero" );
79     print( e_Vector3, "set Vector3 elements to zero" );
80     rndflt1 = randfloat();
81     rndflt2 = randfloat();
82     rndflt3 = randfloat();
83     rndflt4 = randfloat();
84     a_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
85     rndflt1 = randfloat();
86     rndflt2 = randfloat();
87     rndflt3 = randfloat();
88     rndflt4 = randfloat();
89     b_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
90     print( a_Vector4, "set Vector4 with floats" );
91     print( b_Vector4, "set Vector4 with floats" );
92     c_Vector4 = Vector4( (vec_float4){0.0f} );
93     d_Vector4 = Vector4( (vec_float4){0.0f} );
94     e_Vector4 = Vector4( (vec_float4){0.0f} );
95     print( c_Vector4, "set Vector4 elements to zero" );
96     print( d_Vector4, "set Vector4 elements to zero" );
97     print( e_Vector4, "set Vector4 elements to zero" );
98     rndflt1 = randfloat();
99     rndflt2 = randfloat();
100     rndflt3 = randfloat();
101     a_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
102     rndflt1 = randfloat();
103     rndflt2 = randfloat();
104     rndflt3 = randfloat();
105     b_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
106     print( a_Point3, "set Point3 with floats" );
107     print( b_Point3, "set Point3 with floats" );
108     c_Point3 = Point3( (vec_float4){0.0f} );
109     d_Point3 = Point3( (vec_float4){0.0f} );
110     e_Point3 = Point3( (vec_float4){0.0f} );
111     print( c_Point3, "set Point3 elements to zero" );
112     print( d_Point3, "set Point3 elements to zero" );
113     print( e_Point3, "set Point3 elements to zero" );
114     rndflt1 = randfloat();
115     rndflt2 = randfloat();
116     rndflt3 = randfloat();
117     rndflt4 = randfloat();
118     a_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
119     rndflt1 = randfloat();
120     rndflt2 = randfloat();
121     rndflt3 = randfloat();
122     rndflt4 = randfloat();
123     b_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
124     print( a_Quat, "set Quat with floats" );
125     print( b_Quat, "set Quat with floats" );
126     c_Quat = Quat( (vec_float4){0.0f} );
127     d_Quat = Quat( (vec_float4){0.0f} );
128     e_Quat = Quat( (vec_float4){0.0f} );
129     print( c_Quat, "set Quat elements to zero" );
130     print( d_Quat, "set Quat elements to zero" );
131     print( e_Quat, "set Quat elements to zero" );
132     a_Vector3 = Vector3( a_Point3 );
133     print( a_Vector3, "construct Vector3 with Point3" );
134     a_Vector3 = Vector3( randfloat() );
135     print( a_Vector3, "set Vector3 with float" );
136     a_Vector3 = Vector3( randfloat() );
137     print( a_Vector3, "set Vector3 with float" );
138     aos_Vector3_0 = Aos::Vector3( 0.0f, 1.0f, 2.0f );
139     aos_Vector3_1 = Aos::Vector3( 3.0f, 4.0f, 5.0f );
140     aos_Vector3_2 = Aos::Vector3( 6.0f, 7.0f, 8.0f );
141     aos_Vector3_3 = Aos::Vector3( 9.0f, 10.0f, 11.0f );
142     soa_Vector3 = Vector3( aos_Vector3_0, aos_Vector3_1, aos_Vector3_2, aos_Vector3_3 );
143     soa_Vector3.get4Aos( aos_Vector3_3, aos_Vector3_2, aos_Vector3_1, aos_Vector3_0 );
144     Aos::print( aos_Vector3_0, "aos type 0" );
145     Aos::print( aos_Vector3_1, "aos type 1" );
146     Aos::print( aos_Vector3_2, "aos type 2" );
147     Aos::print( aos_Vector3_3, "aos type 3" );
148     a_Vector3 = select( a_Vector3, b_Vector3, ((vec_uint4){0,0xffffffff,0,0xffffffff}) );
149     a_Vector3.get4Aos( aos_Vector3_0, aos_Vector3_1, aos_Vector3_2, aos_Vector3_3 );
150     Aos::print( aos_Vector3_0, "select 0" );
151     Aos::print( aos_Vector3_1, "select 1" );
152     Aos::print( aos_Vector3_2, "select 2" );
153     Aos::print( aos_Vector3_3, "select 3" );
154     loadXYZArray( a_Vector3, (const vec_float4 *)xyz4 );
155     print( a_Vector3, "load XYZ array" );
156     a_Vector3 = Vector3( ( -Vector3( a_Vector3 ) ) );
157     storeXYZArray( a_Vector3, (vec_float4 *)xyz4 );
158     aos_Vector4_0 = Aos::Vector4( xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
159     aos_Vector4_1 = Aos::Vector4( xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
160     aos_Vector4_2 = Aos::Vector4( xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
161     Aos::print( aos_Vector4_0, "xyzx" );
162     Aos::print( aos_Vector4_1, "yzxy" );
163     Aos::print( aos_Vector4_2, "zxyz" );
164     Aos::print( aos_Vector4_0, "xyzx" );
165     Aos::print( aos_Vector4_1, "yzxy" );
166     Aos::print( aos_Vector4_2, "zxyz" );
167     printf("storeXYZ:-1.0 -2.0 -3.0 0.4\n");
168     a_Vector3 = b_Vector3;
169     print( a_Vector3, "assign to Vector3 from Vector3" );
170     a_Vector3 = Vector3( (vec_float4){0.0f} );
171     print( a_Vector3, "set Vector3 elements to zero" );
172     a_Vector3 = Vector3::xAxis( );
173     print( a_Vector3, "set to x axis" );
174     a_Vector3 = Vector3::yAxis( );
175     print( a_Vector3, "set to y axis" );
176     a_Vector3 = Vector3::zAxis( );
177     print( a_Vector3, "set to z axis" );
178     a_Vector3.setElem( 0, randfloat() );
179     print( a_Vector3, "Vector3::set( 0, float )" );
180     a_Vector3[0] = randfloat();
181     a_Vector3[0] = vec_mul_float( a_Vector3[0], randfloat() );
182     a_Vector3[0] = divf4( a_Vector3[0], randfloat() );
183     a_Vector3[0] = vec_add_float( a_Vector3[0], randfloat() );
184     a_Vector3[0] = vec_sub_float( a_Vector3[0], randfloat() );
185     print( a_Vector3, "Vector3::operator [](0)" );
186     a_Vector3.setX( randfloat() );
187     print( a_Vector3, "Vector3::setX()" );
188     a_Vector3.setElem( 1, randfloat() );
189     print( a_Vector3, "Vector3::set( 1, float )" );
190     a_Vector3[1] = randfloat();
191     a_Vector3[1] = vec_mul_float( a_Vector3[1], randfloat() );
192     a_Vector3[1] = divf4( a_Vector3[1], randfloat() );
193     a_Vector3[1] = vec_add_float( a_Vector3[1], randfloat() );
194     a_Vector3[1] = vec_sub_float( a_Vector3[1], randfloat() );
195     print( a_Vector3, "Vector3::operator [](1)" );
196     a_Vector3.setY( randfloat() );
197     print( a_Vector3, "Vector3::setY()" );
198     a_Vector3.setElem( 2, randfloat() );
199     print( a_Vector3, "Vector3::set( 2, float )" );
200     a_Vector3[2] = randfloat();
201     a_Vector3[2] = vec_mul_float( a_Vector3[2], randfloat() );
202     a_Vector3[2] = divf4( a_Vector3[2], randfloat() );
203     a_Vector3[2] = vec_add_float( a_Vector3[2], randfloat() );
204     a_Vector3[2] = vec_sub_float( a_Vector3[2], randfloat() );
205     print( a_Vector3, "Vector3::operator [](2)" );
206     a_Vector3.setZ( randfloat() );
207     print( a_Vector3, "Vector3::setZ()" );
208     printf("Vector3::get( 0 ): %f\n", getfloat(a_Vector3.getElem( 0 )) );
209     printf("Vector3::operator []( 0 ): %f\n", getfloat((vec_float4)a_Vector3[0]) );
210     printf("Vector3::getX(): %f\n", getfloat(a_Vector3.getX( )) );
211     printf("Vector3::get( 1 ): %f\n", getfloat(a_Vector3.getElem( 1 )) );
212     printf("Vector3::operator []( 1 ): %f\n", getfloat((vec_float4)a_Vector3[1]) );
213     printf("Vector3::getY(): %f\n", getfloat(a_Vector3.getY( )) );
214     printf("Vector3::get( 2 ): %f\n", getfloat(a_Vector3.getElem( 2 )) );
215     printf("Vector3::operator []( 2 ): %f\n", getfloat((vec_float4)a_Vector3[2]) );
216     printf("Vector3::getZ(): %f\n", getfloat(a_Vector3.getZ( )) );
217     print( ( a_Vector3 + b_Vector3 ), "Vector3 + Vector3" );
218     print( ( a_Vector3 - b_Vector3 ), "Vector3 - Vector3" );
219     print( ( a_Vector3 + b_Point3 ), "Vector3 + Point3" );
220     print( ( a_Vector3 * randfloat() ), "Vector3 * float" );
221     print( ( a_Vector3 / randfloat() ), "Vector3 / float" );
222     print( ( randfloat() * a_Vector3 ), "float * Vector3" );
223     print( ( -a_Vector3 ), "Vector3 negate" );
224     print( mulPerElem( a_Vector3, b_Vector3 ), "mulPerElem( Vector3, Vector3 )" );
225     print( divPerElem( a_Vector3, b_Vector3 ), "divPerElem( Vector3, Vector3 )" );
226     print( recipPerElem( a_Vector3 ), "Vector3 recip" );
227     print( sqrtPerElem( absPerElem( a_Vector3 ) ), "Vector3 sqrt" );
228     print( rsqrtPerElem( absPerElem( a_Vector3 ) ), "Vector3 rsqrt" );
229     print( absPerElem( a_Vector3 ), "Vector3 abs" );
230     print( copySignPerElem( a_Vector3, b_Vector3 ), "Vector3 copySign" );
231     print( maxPerElem( a_Vector3, b_Vector3 ), "Vector3 maximum Vector3" );
232     print( minPerElem( a_Vector3, b_Vector3 ), "Vector3 minimum Vector3" );
233     printf("Vector3 maximum of elements: %f\n", getfloat(maxElem( a_Vector3 )));
234     printf("Vector3 minimum of elements: %f\n", getfloat(minElem( a_Vector3 )));
235     printf("Vector3 sum of elements: %f\n", getfloat(sum( a_Vector3 )));
236     printf("Vector3 dot Vector3: %f\n", getfloat(dot( a_Vector3, b_Vector3 )));
237     printf("Vector3 lengthSqr: %f\n", getfloat(lengthSqr( a_Vector3 )));
238     printf("Vector3 length: %f\n", getfloat(length( a_Vector3 )));
239     print( normalize( a_Vector3 ), "Vector3 normalized" );
240     rndflt1 = randfloat();
241     rndflt2 = randfloat();
242     rndflt3 = randfloat();
243     b_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
244     rndflt1 = randfloat();
245     rndflt2 = randfloat();
246     rndflt3 = randfloat();
247     c_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
248     rndflt1 = randfloat();
249     rndflt2 = randfloat();
250     rndflt3 = randfloat();
251     d_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
252     rndflt1 = randfloat();
253     rndflt2 = randfloat();
254     rndflt3 = randfloat();
255     e_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
256     b_Vector3 = normalize( b_Vector3 );
257     c_Vector3 = normalize( c_Vector3 );
258     d_Vector3 = normalize( d_Vector3 );
259     e_Vector3 = normalize( e_Vector3 );
260     a_Vector3 = lerp( randfloat(), b_Vector3, c_Vector3 );
261     print( a_Vector3, "Vector3 lerp" );
262     a_Vector3 = slerp( randfloat(), b_Vector3, c_Vector3 );
263     print( a_Vector3, "Vector3 slerp" );
264 }
265
266 void
267 Vector4_methods_test()
268 {
269     Vector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
270     Vector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
271     Point3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
272     Quat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
273     Aos::Vector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2, aos_Vector4_3;
274     Vector4 soa_Vector4;
275     vec_float4 rndflt1, rndflt2, rndflt3, rndflt4;
276     rndflt1 = randfloat();
277     rndflt2 = randfloat();
278     rndflt3 = randfloat();
279     a_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
280     rndflt1 = randfloat();
281     rndflt2 = randfloat();
282     rndflt3 = randfloat();
283     b_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
284     print( a_Vector3, "set Vector3 with floats" );
285     print( b_Vector3, "set Vector3 with floats" );
286     c_Vector3 = Vector3( (vec_float4){0.0f} );
287     d_Vector3 = Vector3( (vec_float4){0.0f} );
288     e_Vector3 = Vector3( (vec_float4){0.0f} );
289     print( c_Vector3, "set Vector3 elements to zero" );
290     print( d_Vector3, "set Vector3 elements to zero" );
291     print( e_Vector3, "set Vector3 elements to zero" );
292     rndflt1 = randfloat();
293     rndflt2 = randfloat();
294     rndflt3 = randfloat();
295     rndflt4 = randfloat();
296     a_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
297     rndflt1 = randfloat();
298     rndflt2 = randfloat();
299     rndflt3 = randfloat();
300     rndflt4 = randfloat();
301     b_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
302     print( a_Vector4, "set Vector4 with floats" );
303     print( b_Vector4, "set Vector4 with floats" );
304     c_Vector4 = Vector4( (vec_float4){0.0f} );
305     d_Vector4 = Vector4( (vec_float4){0.0f} );
306     e_Vector4 = Vector4( (vec_float4){0.0f} );
307     print( c_Vector4, "set Vector4 elements to zero" );
308     print( d_Vector4, "set Vector4 elements to zero" );
309     print( e_Vector4, "set Vector4 elements to zero" );
310     rndflt1 = randfloat();
311     rndflt2 = randfloat();
312     rndflt3 = randfloat();
313     a_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
314     rndflt1 = randfloat();
315     rndflt2 = randfloat();
316     rndflt3 = randfloat();
317     b_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
318     print( a_Point3, "set Point3 with floats" );
319     print( b_Point3, "set Point3 with floats" );
320     c_Point3 = Point3( (vec_float4){0.0f} );
321     d_Point3 = Point3( (vec_float4){0.0f} );
322     e_Point3 = Point3( (vec_float4){0.0f} );
323     print( c_Point3, "set Point3 elements to zero" );
324     print( d_Point3, "set Point3 elements to zero" );
325     print( e_Point3, "set Point3 elements to zero" );
326     rndflt1 = randfloat();
327     rndflt2 = randfloat();
328     rndflt3 = randfloat();
329     rndflt4 = randfloat();
330     a_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
331     rndflt1 = randfloat();
332     rndflt2 = randfloat();
333     rndflt3 = randfloat();
334     rndflt4 = randfloat();
335     b_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
336     print( a_Quat, "set Quat with floats" );
337     print( b_Quat, "set Quat with floats" );
338     c_Quat = Quat( (vec_float4){0.0f} );
339     d_Quat = Quat( (vec_float4){0.0f} );
340     e_Quat = Quat( (vec_float4){0.0f} );
341     print( c_Quat, "set Quat elements to zero" );
342     print( d_Quat, "set Quat elements to zero" );
343     print( e_Quat, "set Quat elements to zero" );
344     a_Vector4 = Vector4( a_Vector3, randfloat() );
345     print( a_Vector4, "set Vector4 with Vector3, float" );
346     a_Vector4 = Vector4( a_Vector3 );
347     print( a_Vector4, "set Vector4 with Vector3" );
348     a_Vector4 = Vector4( a_Point3 );
349     print( a_Vector4, "set Vector4 with Point3" );
350     a_Vector4 = Vector4( a_Quat );
351     print( a_Vector4, "construct Vector4 with Quat" );
352     a_Vector4 = Vector4( randfloat() );
353     print( a_Vector4, "set Vector4 with float" );
354     a_Vector4 = Vector4( randfloat() );
355     print( a_Vector4, "set Vector4 with float" );
356     aos_Vector4_0 = Aos::Vector4( 0.0f, 1.0f, 2.0f, 3.0f );
357     aos_Vector4_1 = Aos::Vector4( 4.0f, 5.0f, 6.0f, 7.0f );
358     aos_Vector4_2 = Aos::Vector4( 8.0f, 9.0f, 10.0f, 11.0f );
359     aos_Vector4_3 = Aos::Vector4( 12.0f, 13.0f, 14.0f, 15.0f );
360     soa_Vector4 = Vector4( aos_Vector4_0, aos_Vector4_1, aos_Vector4_2, aos_Vector4_3 );
361     soa_Vector4.get4Aos( aos_Vector4_3, aos_Vector4_2, aos_Vector4_1, aos_Vector4_0 );
362     Aos::print( aos_Vector4_0, "aos type 0" );
363     Aos::print( aos_Vector4_1, "aos type 1" );
364     Aos::print( aos_Vector4_2, "aos type 2" );
365     Aos::print( aos_Vector4_3, "aos type 3" );
366     a_Vector4 = select( a_Vector4, b_Vector4, ((vec_uint4){0,0xffffffff,0,0xffffffff}) );
367     a_Vector4.get4Aos( aos_Vector4_0, aos_Vector4_1, aos_Vector4_2, aos_Vector4_3 );
368     Aos::print( aos_Vector4_0, "select 0" );
369     Aos::print( aos_Vector4_1, "select 1" );
370     Aos::print( aos_Vector4_2, "select 2" );
371     Aos::print( aos_Vector4_3, "select 3" );
372     a_Vector4 = b_Vector4;
373     print( a_Vector4, "assign to Vector4 from Vector4" );
374     a_Vector4.setXYZ( a_Vector3 );
375     print( a_Vector4, "set Vector4 xyz" );
376     print( a_Vector4.getXYZ( ), "get Vector4 xyz" );
377     a_Vector4 = Vector4( (vec_float4){0.0f} );
378     print( a_Vector4, "set Vector4 elements to zero" );
379     a_Vector4 = Vector4::xAxis( );
380     print( a_Vector4, "set to x axis" );
381     a_Vector4 = Vector4::yAxis( );
382     print( a_Vector4, "set to y axis" );
383     a_Vector4 = Vector4::zAxis( );
384     print( a_Vector4, "set to z axis" );
385     a_Vector4 = Vector4::wAxis( );
386     print( a_Vector4, "set to w axis" );
387     a_Vector4.setElem( 0, randfloat() );
388     print( a_Vector4, "Vector4::set( 0, float )" );
389     a_Vector4[0] = randfloat();
390     a_Vector4[0] = vec_mul_float( a_Vector4[0], randfloat() );
391     a_Vector4[0] = divf4( a_Vector4[0], randfloat() );
392     a_Vector4[0] = vec_add_float( a_Vector4[0], randfloat() );
393     a_Vector4[0] = vec_sub_float( a_Vector4[0], randfloat() );
394     print( a_Vector4, "Vector4::operator [](0)" );
395     a_Vector4.setX( randfloat() );
396     print( a_Vector4, "Vector4::setX()" );
397     a_Vector4.setElem( 1, randfloat() );
398     print( a_Vector4, "Vector4::set( 1, float )" );
399     a_Vector4[1] = randfloat();
400     a_Vector4[1] = vec_mul_float( a_Vector4[1], randfloat() );
401     a_Vector4[1] = divf4( a_Vector4[1], randfloat() );
402     a_Vector4[1] = vec_add_float( a_Vector4[1], randfloat() );
403     a_Vector4[1] = vec_sub_float( a_Vector4[1], randfloat() );
404     print( a_Vector4, "Vector4::operator [](1)" );
405     a_Vector4.setY( randfloat() );
406     print( a_Vector4, "Vector4::setY()" );
407     a_Vector4.setElem( 2, randfloat() );
408     print( a_Vector4, "Vector4::set( 2, float )" );
409     a_Vector4[2] = randfloat();
410     a_Vector4[2] = vec_mul_float( a_Vector4[2], randfloat() );
411     a_Vector4[2] = divf4( a_Vector4[2], randfloat() );
412     a_Vector4[2] = vec_add_float( a_Vector4[2], randfloat() );
413     a_Vector4[2] = vec_sub_float( a_Vector4[2], randfloat() );
414     print( a_Vector4, "Vector4::operator [](2)" );
415     a_Vector4.setZ( randfloat() );
416     print( a_Vector4, "Vector4::setZ()" );
417     a_Vector4.setElem( 3, randfloat() );
418     print( a_Vector4, "Vector4::set( 3, float )" );
419     a_Vector4[3] = randfloat();
420     a_Vector4[3] = vec_mul_float( a_Vector4[3], randfloat() );
421     a_Vector4[3] = divf4( a_Vector4[3], randfloat() );
422     a_Vector4[3] = vec_add_float( a_Vector4[3], randfloat() );
423     a_Vector4[3] = vec_sub_float( a_Vector4[3], randfloat() );
424     print( a_Vector4, "Vector4::operator [](3)" );
425     a_Vector4.setW( randfloat() );
426     print( a_Vector4, "Vector4::setW()" );
427     printf("Vector4::get( 0 ): %f\n", getfloat(a_Vector4.getElem( 0 )) );
428     printf("Vector4::operator []( 0 ): %f\n", getfloat((vec_float4)a_Vector4[0]) );
429     printf("Vector4::getX(): %f\n", getfloat(a_Vector4.getX( )) );
430     printf("Vector4::get( 1 ): %f\n", getfloat(a_Vector4.getElem( 1 )) );
431     printf("Vector4::operator []( 1 ): %f\n", getfloat((vec_float4)a_Vector4[1]) );
432     printf("Vector4::getY(): %f\n", getfloat(a_Vector4.getY( )) );
433     printf("Vector4::get( 2 ): %f\n", getfloat(a_Vector4.getElem( 2 )) );
434     printf("Vector4::operator []( 2 ): %f\n", getfloat((vec_float4)a_Vector4[2]) );
435     printf("Vector4::getZ(): %f\n", getfloat(a_Vector4.getZ( )) );
436     printf("Vector4::get( 3 ): %f\n", getfloat(a_Vector4.getElem( 3 )) );
437     printf("Vector4::operator []( 3 ): %f\n", getfloat((vec_float4)a_Vector4[3]) );
438     printf("Vector4::getW(): %f\n", getfloat(a_Vector4.getW( )) );
439     print( ( a_Vector4 + b_Vector4 ), "Vector4 + Vector4" );
440     print( ( a_Vector4 - b_Vector4 ), "Vector4 - Vector4" );
441     print( ( a_Vector4 * randfloat() ), "Vector4 * float" );
442     print( ( a_Vector4 / randfloat() ), "Vector4 / float" );
443     print( ( randfloat() * a_Vector4 ), "float * Vector4" );
444     print( ( -a_Vector4 ), "Vector4 negate" );
445     print( mulPerElem( a_Vector4, b_Vector4 ), "mulPerElem( Vector4, Vector4 )" );
446     print( divPerElem( a_Vector4, b_Vector4 ), "divPerElem( Vector4, Vector4 )" );
447     print( recipPerElem( a_Vector4 ), "Vector4 recip" );
448     print( sqrtPerElem( absPerElem( a_Vector4 ) ), "Vector4 sqrt" );
449     print( rsqrtPerElem( absPerElem( a_Vector4 ) ), "Vector4 rsqrt" );
450     print( absPerElem( a_Vector4 ), "Vector4 abs" );
451     print( copySignPerElem( a_Vector4, b_Vector4 ), "Vector4 copySign" );
452     print( maxPerElem( a_Vector4, b_Vector4 ), "Vector4 maximum Vector4" );
453     print( minPerElem( a_Vector4, b_Vector4 ), "Vector4 minimum Vector4" );
454     printf("Vector4 maximum of elements: %f\n", getfloat(maxElem( a_Vector4 )));
455     printf("Vector4 minimum of elements: %f\n", getfloat(minElem( a_Vector4 )));
456     printf("Vector4 sum of elements: %f\n", getfloat(sum( a_Vector4 )));
457     printf("Vector4 dot Vector4: %f\n", getfloat(dot( a_Vector4, b_Vector4 )));
458     printf("Vector4 lengthSqr: %f\n", getfloat(lengthSqr( a_Vector4 )));
459     printf("Vector4 length: %f\n", getfloat(length( a_Vector4 )));
460     print( normalize( a_Vector4 ), "Vector4 normalized" );
461     rndflt1 = randfloat();
462     rndflt2 = randfloat();
463     rndflt3 = randfloat();
464     rndflt4 = randfloat();
465     b_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
466     rndflt1 = randfloat();
467     rndflt2 = randfloat();
468     rndflt3 = randfloat();
469     rndflt4 = randfloat();
470     c_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
471     rndflt1 = randfloat();
472     rndflt2 = randfloat();
473     rndflt3 = randfloat();
474     rndflt4 = randfloat();
475     d_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
476     rndflt1 = randfloat();
477     rndflt2 = randfloat();
478     rndflt3 = randfloat();
479     rndflt4 = randfloat();
480     e_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
481     b_Vector4 = normalize( b_Vector4 );
482     c_Vector4 = normalize( c_Vector4 );
483     d_Vector4 = normalize( d_Vector4 );
484     e_Vector4 = normalize( e_Vector4 );
485     a_Vector4 = lerp( randfloat(), b_Vector4, c_Vector4 );
486     print( a_Vector4, "Vector4 lerp" );
487     a_Vector4 = slerp( randfloat(), b_Vector4, c_Vector4 );
488     print( a_Vector4, "Vector4 slerp" );
489 }
490
491 void
492 Point3_methods_test()
493 {
494     Vector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
495     Vector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
496     Point3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
497     Quat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
498     Aos::Point3 aos_Point3_0, aos_Point3_1, aos_Point3_2, aos_Point3_3;
499     Point3 soa_Point3;
500     Aos::Vector4 aos_Vector4_0, aos_Vector4_1, aos_Vector4_2;
501     vec_float4 rndflt1, rndflt2, rndflt3, rndflt4;
502     float xyz4[12] __attribute__ ((aligned(16)));
503     xyz4[0] = getfloat(randfloat());
504     xyz4[1] = getfloat(randfloat());
505     xyz4[2] = getfloat(randfloat());
506     xyz4[3] = getfloat(randfloat());
507     xyz4[4] = getfloat(randfloat());
508     xyz4[5] = getfloat(randfloat());
509     xyz4[6] = getfloat(randfloat());
510     xyz4[7] = getfloat(randfloat());
511     xyz4[8] = getfloat(randfloat());
512     xyz4[9] = getfloat(randfloat());
513     xyz4[10] = getfloat(randfloat());
514     xyz4[11] = getfloat(randfloat());
515     rndflt1 = randfloat();
516     rndflt2 = randfloat();
517     rndflt3 = randfloat();
518     a_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
519     rndflt1 = randfloat();
520     rndflt2 = randfloat();
521     rndflt3 = randfloat();
522     b_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
523     print( a_Vector3, "set Vector3 with floats" );
524     print( b_Vector3, "set Vector3 with floats" );
525     c_Vector3 = Vector3( (vec_float4){0.0f} );
526     d_Vector3 = Vector3( (vec_float4){0.0f} );
527     e_Vector3 = Vector3( (vec_float4){0.0f} );
528     print( c_Vector3, "set Vector3 elements to zero" );
529     print( d_Vector3, "set Vector3 elements to zero" );
530     print( e_Vector3, "set Vector3 elements to zero" );
531     rndflt1 = randfloat();
532     rndflt2 = randfloat();
533     rndflt3 = randfloat();
534     rndflt4 = randfloat();
535     a_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
536     rndflt1 = randfloat();
537     rndflt2 = randfloat();
538     rndflt3 = randfloat();
539     rndflt4 = randfloat();
540     b_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
541     print( a_Vector4, "set Vector4 with floats" );
542     print( b_Vector4, "set Vector4 with floats" );
543     c_Vector4 = Vector4( (vec_float4){0.0f} );
544     d_Vector4 = Vector4( (vec_float4){0.0f} );
545     e_Vector4 = Vector4( (vec_float4){0.0f} );
546     print( c_Vector4, "set Vector4 elements to zero" );
547     print( d_Vector4, "set Vector4 elements to zero" );
548     print( e_Vector4, "set Vector4 elements to zero" );
549     rndflt1 = randfloat();
550     rndflt2 = randfloat();
551     rndflt3 = randfloat();
552     a_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
553     rndflt1 = randfloat();
554     rndflt2 = randfloat();
555     rndflt3 = randfloat();
556     b_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
557     print( a_Point3, "set Point3 with floats" );
558     print( b_Point3, "set Point3 with floats" );
559     c_Point3 = Point3( (vec_float4){0.0f} );
560     d_Point3 = Point3( (vec_float4){0.0f} );
561     e_Point3 = Point3( (vec_float4){0.0f} );
562     print( c_Point3, "set Point3 elements to zero" );
563     print( d_Point3, "set Point3 elements to zero" );
564     print( e_Point3, "set Point3 elements to zero" );
565     rndflt1 = randfloat();
566     rndflt2 = randfloat();
567     rndflt3 = randfloat();
568     rndflt4 = randfloat();
569     a_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
570     rndflt1 = randfloat();
571     rndflt2 = randfloat();
572     rndflt3 = randfloat();
573     rndflt4 = randfloat();
574     b_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
575     print( a_Quat, "set Quat with floats" );
576     print( b_Quat, "set Quat with floats" );
577     c_Quat = Quat( (vec_float4){0.0f} );
578     d_Quat = Quat( (vec_float4){0.0f} );
579     e_Quat = Quat( (vec_float4){0.0f} );
580     print( c_Quat, "set Quat elements to zero" );
581     print( d_Quat, "set Quat elements to zero" );
582     print( e_Quat, "set Quat elements to zero" );
583     a_Point3 = Point3( a_Vector3 );
584     print( a_Point3, "construct Point3 with Vector3" );
585     a_Point3 = Point3( randfloat() );
586     print( a_Point3, "set Point3 with float" );
587     a_Point3 = Point3( randfloat() );
588     print( a_Point3, "set Point3 with float" );
589     aos_Point3_0 = Aos::Point3( 0.0f, 1.0f, 2.0f );
590     aos_Point3_1 = Aos::Point3( 3.0f, 4.0f, 5.0f );
591     aos_Point3_2 = Aos::Point3( 6.0f, 7.0f, 8.0f );
592     aos_Point3_3 = Aos::Point3( 9.0f, 10.0f, 11.0f );
593     soa_Point3 = Point3( aos_Point3_0, aos_Point3_1, aos_Point3_2, aos_Point3_3 );
594     soa_Point3.get4Aos( aos_Point3_3, aos_Point3_2, aos_Point3_1, aos_Point3_0 );
595     Aos::print( aos_Point3_0, "aos type 0" );
596     Aos::print( aos_Point3_1, "aos type 1" );
597     Aos::print( aos_Point3_2, "aos type 2" );
598     Aos::print( aos_Point3_3, "aos type 3" );
599     a_Point3 = select( a_Point3, b_Point3, ((vec_uint4){0,0xffffffff,0,0xffffffff}) );
600     a_Point3.get4Aos( aos_Point3_0, aos_Point3_1, aos_Point3_2, aos_Point3_3 );
601     Aos::print( aos_Point3_0, "select 0" );
602     Aos::print( aos_Point3_1, "select 1" );
603     Aos::print( aos_Point3_2, "select 2" );
604     Aos::print( aos_Point3_3, "select 3" );
605     loadXYZArray( a_Point3, (const vec_float4 *)xyz4 );
606     print( a_Point3, "load XYZ array" );
607     a_Point3 = Point3( ( -Vector3( a_Point3 ) ) );
608     storeXYZArray( a_Point3, (vec_float4 *)xyz4 );
609     aos_Vector4_0 = Aos::Vector4( xyz4[0], xyz4[1], xyz4[2], xyz4[3] );
610     aos_Vector4_1 = Aos::Vector4( xyz4[4], xyz4[5], xyz4[6], xyz4[7] );
611     aos_Vector4_2 = Aos::Vector4( xyz4[8], xyz4[9], xyz4[10], xyz4[11] );
612     Aos::print( aos_Vector4_0, "xyzx" );
613     Aos::print( aos_Vector4_1, "yzxy" );
614     Aos::print( aos_Vector4_2, "zxyz" );
615     Aos::print( aos_Vector4_0, "xyzx" );
616     Aos::print( aos_Vector4_1, "yzxy" );
617     Aos::print( aos_Vector4_2, "zxyz" );
618     printf("storeXYZ:-1.0 -2.0 -3.0 0.4\n");
619     a_Point3 = b_Point3;
620     print( a_Point3, "assign to Point3 from Point3" );
621     a_Point3 = Point3( (vec_float4){0.0f} );
622     print( a_Point3, "set Point3 elements to zero" );
623     a_Point3.setElem( 0, randfloat() );
624     print( a_Point3, "Point3::set( 0, float )" );
625     a_Point3[0] = randfloat();
626     a_Point3[0] = vec_mul_float( a_Point3[0], randfloat() );
627     a_Point3[0] = divf4( a_Point3[0], randfloat() );
628     a_Point3[0] = vec_add_float( a_Point3[0], randfloat() );
629     a_Point3[0] = vec_sub_float( a_Point3[0], randfloat() );
630     print( a_Point3, "Point3::operator [](0)" );
631     a_Point3.setX( randfloat() );
632     print( a_Point3, "Point3::setX()" );
633     a_Point3.setElem( 1, randfloat() );
634     print( a_Point3, "Point3::set( 1, float )" );
635     a_Point3[1] = randfloat();
636     a_Point3[1] = vec_mul_float( a_Point3[1], randfloat() );
637     a_Point3[1] = divf4( a_Point3[1], randfloat() );
638     a_Point3[1] = vec_add_float( a_Point3[1], randfloat() );
639     a_Point3[1] = vec_sub_float( a_Point3[1], randfloat() );
640     print( a_Point3, "Point3::operator [](1)" );
641     a_Point3.setY( randfloat() );
642     print( a_Point3, "Point3::setY()" );
643     a_Point3.setElem( 2, randfloat() );
644     print( a_Point3, "Point3::set( 2, float )" );
645     a_Point3[2] = randfloat();
646     a_Point3[2] = vec_mul_float( a_Point3[2], randfloat() );
647     a_Point3[2] = divf4( a_Point3[2], randfloat() );
648     a_Point3[2] = vec_add_float( a_Point3[2], randfloat() );
649     a_Point3[2] = vec_sub_float( a_Point3[2], randfloat() );
650     print( a_Point3, "Point3::operator [](2)" );
651     a_Point3.setZ( randfloat() );
652     print( a_Point3, "Point3::setZ()" );
653     printf("Point3::get( 0 ): %f\n", getfloat(a_Point3.getElem( 0 )) );
654     printf("Point3::operator []( 0 ): %f\n", getfloat((vec_float4)a_Point3[0]) );
655     printf("Point3::getX(): %f\n", getfloat(a_Point3.getX( )) );
656     printf("Point3::get( 1 ): %f\n", getfloat(a_Point3.getElem( 1 )) );
657     printf("Point3::operator []( 1 ): %f\n", getfloat((vec_float4)a_Point3[1]) );
658     printf("Point3::getY(): %f\n", getfloat(a_Point3.getY( )) );
659     printf("Point3::get( 2 ): %f\n", getfloat(a_Point3.getElem( 2 )) );
660     printf("Point3::operator []( 2 ): %f\n", getfloat((vec_float4)a_Point3[2]) );
661     printf("Point3::getZ(): %f\n", getfloat(a_Point3.getZ( )) );
662     print( ( a_Point3 - b_Point3 ), "Point3 - Point3" );
663     print( ( a_Point3 + b_Vector3 ), "Point3 + Vector3" );
664     print( ( a_Point3 - b_Vector3 ), "Point3 - Vector3" );
665     print( mulPerElem( a_Point3, b_Point3 ), "mulPerElem( Point3, Point3 )" );
666     print( divPerElem( a_Point3, b_Point3 ), "divPerElem( Point3, Point3 )" );
667     print( recipPerElem( a_Point3 ), "Point3 recip" );
668     print( sqrtPerElem( absPerElem( a_Point3 ) ), "Point3 sqrt" );
669     print( rsqrtPerElem( absPerElem( a_Point3 ) ), "Point3 rsqrt" );
670     print( absPerElem( a_Point3 ), "Point3 abs" );
671     print( copySignPerElem( a_Point3, b_Point3 ), "Point3 copySign" );
672     print( maxPerElem( a_Point3, b_Point3 ), "Point3 maximum Point3" );
673     print( minPerElem( a_Point3, b_Point3 ), "Point3 minimum Point3" );
674     printf("Point3 maximum of elements: %f\n", getfloat(maxElem( a_Point3 )));
675     printf("Point3 minimum of elements: %f\n", getfloat(minElem( a_Point3 )));
676     printf("Point3 sum of elements: %f\n", getfloat(sum( a_Point3 )));
677     printf("Point projection: %f\n", getfloat(projection( a_Point3, b_Vector3 )));
678     printf("Point distSqrFromOrigin: %f\n", getfloat(distSqrFromOrigin( a_Point3 )) );
679     printf("Point distFromOrigin: %f\n", getfloat(distFromOrigin( a_Point3 )) );
680     printf("Point distSqr: %f\n", getfloat(distSqr( a_Point3, b_Point3 )) );
681     printf("Point dist: %f\n", getfloat(dist( a_Point3, b_Point3 )) );
682     rndflt1 = randfloat();
683     rndflt2 = randfloat();
684     rndflt3 = randfloat();
685     b_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
686     rndflt1 = randfloat();
687     rndflt2 = randfloat();
688     rndflt3 = randfloat();
689     c_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
690     rndflt1 = randfloat();
691     rndflt2 = randfloat();
692     rndflt3 = randfloat();
693     d_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
694     rndflt1 = randfloat();
695     rndflt2 = randfloat();
696     rndflt3 = randfloat();
697     e_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
698     a_Point3 = lerp( randfloat(), b_Point3, c_Point3 );
699     print( a_Point3, "Point3 lerp" );
700 }
701
702 void
703 Quat_methods_test()
704 {
705     Vector3 a_Vector3, b_Vector3, c_Vector3, d_Vector3, e_Vector3;
706     Vector4 a_Vector4, b_Vector4, c_Vector4, d_Vector4, e_Vector4;
707     Point3 a_Point3, b_Point3, c_Point3, d_Point3, e_Point3;
708     Quat a_Quat, b_Quat, c_Quat, d_Quat, e_Quat;
709     Aos::Quat aos_Quat_0, aos_Quat_1, aos_Quat_2, aos_Quat_3;
710     Quat soa_Quat;
711     vec_float4 rndflt1, rndflt2, rndflt3, rndflt4;
712     rndflt1 = randfloat();
713     rndflt2 = randfloat();
714     rndflt3 = randfloat();
715     a_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
716     rndflt1 = randfloat();
717     rndflt2 = randfloat();
718     rndflt3 = randfloat();
719     b_Vector3 = Vector3( rndflt1, rndflt2, rndflt3 );
720     print( a_Vector3, "set Vector3 with floats" );
721     print( b_Vector3, "set Vector3 with floats" );
722     c_Vector3 = Vector3( (vec_float4){0.0f} );
723     d_Vector3 = Vector3( (vec_float4){0.0f} );
724     e_Vector3 = Vector3( (vec_float4){0.0f} );
725     print( c_Vector3, "set Vector3 elements to zero" );
726     print( d_Vector3, "set Vector3 elements to zero" );
727     print( e_Vector3, "set Vector3 elements to zero" );
728     rndflt1 = randfloat();
729     rndflt2 = randfloat();
730     rndflt3 = randfloat();
731     rndflt4 = randfloat();
732     a_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
733     rndflt1 = randfloat();
734     rndflt2 = randfloat();
735     rndflt3 = randfloat();
736     rndflt4 = randfloat();
737     b_Vector4 = Vector4( rndflt1, rndflt2, rndflt3, rndflt4 );
738     print( a_Vector4, "set Vector4 with floats" );
739     print( b_Vector4, "set Vector4 with floats" );
740     c_Vector4 = Vector4( (vec_float4){0.0f} );
741     d_Vector4 = Vector4( (vec_float4){0.0f} );
742     e_Vector4 = Vector4( (vec_float4){0.0f} );
743     print( c_Vector4, "set Vector4 elements to zero" );
744     print( d_Vector4, "set Vector4 elements to zero" );
745     print( e_Vector4, "set Vector4 elements to zero" );
746     rndflt1 = randfloat();
747     rndflt2 = randfloat();
748     rndflt3 = randfloat();
749     a_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
750     rndflt1 = randfloat();
751     rndflt2 = randfloat();
752     rndflt3 = randfloat();
753     b_Point3 = Point3( rndflt1, rndflt2, rndflt3 );
754     print( a_Point3, "set Point3 with floats" );
755     print( b_Point3, "set Point3 with floats" );
756     c_Point3 = Point3( (vec_float4){0.0f} );
757     d_Point3 = Point3( (vec_float4){0.0f} );
758     e_Point3 = Point3( (vec_float4){0.0f} );
759     print( c_Point3, "set Point3 elements to zero" );
760     print( d_Point3, "set Point3 elements to zero" );
761     print( e_Point3, "set Point3 elements to zero" );
762     rndflt1 = randfloat();
763     rndflt2 = randfloat();
764     rndflt3 = randfloat();
765     rndflt4 = randfloat();
766     a_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
767     rndflt1 = randfloat();
768     rndflt2 = randfloat();
769     rndflt3 = randfloat();
770     rndflt4 = randfloat();
771     b_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
772     print( a_Quat, "set Quat with floats" );
773     print( b_Quat, "set Quat with floats" );
774     c_Quat = Quat( (vec_float4){0.0f} );
775     d_Quat = Quat( (vec_float4){0.0f} );
776     e_Quat = Quat( (vec_float4){0.0f} );
777     print( c_Quat, "set Quat elements to zero" );
778     print( d_Quat, "set Quat elements to zero" );
779     print( e_Quat, "set Quat elements to zero" );
780     a_Quat = Quat( a_Vector3, randfloat() );
781     print( a_Quat, "set Quat with Vector3, float" );
782     a_Quat = Quat( a_Vector4 );
783     print( a_Quat, "construct Quat with Vector4" );
784     a_Quat = Quat( randfloat() );
785     print( a_Quat, "set Quat with float" );
786     a_Quat = Quat( randfloat() );
787     print( a_Quat, "set Quat with float" );
788     aos_Quat_0 = Aos::Quat( 0.0f, 1.0f, 2.0f, 3.0f );
789     aos_Quat_1 = Aos::Quat( 4.0f, 5.0f, 6.0f, 7.0f );
790     aos_Quat_2 = Aos::Quat( 8.0f, 9.0f, 10.0f, 11.0f );
791     aos_Quat_3 = Aos::Quat( 12.0f, 13.0f, 14.0f, 15.0f );
792     soa_Quat = Quat( aos_Quat_0, aos_Quat_1, aos_Quat_2, aos_Quat_3 );
793     soa_Quat.get4Aos( aos_Quat_3, aos_Quat_2, aos_Quat_1, aos_Quat_0 );
794     Aos::print( aos_Quat_0, "aos type 0" );
795     Aos::print( aos_Quat_1, "aos type 1" );
796     Aos::print( aos_Quat_2, "aos type 2" );
797     Aos::print( aos_Quat_3, "aos type 3" );
798     a_Quat = select( a_Quat, b_Quat, ((vec_uint4){0,0xffffffff,0,0xffffffff}) );
799     a_Quat.get4Aos( aos_Quat_0, aos_Quat_1, aos_Quat_2, aos_Quat_3 );
800     Aos::print( aos_Quat_0, "select 0" );
801     Aos::print( aos_Quat_1, "select 1" );
802     Aos::print( aos_Quat_2, "select 2" );
803     Aos::print( aos_Quat_3, "select 3" );
804     a_Quat = b_Quat;
805     print( a_Quat, "assign to Quat from Quat" );
806     a_Quat.setXYZ( a_Vector3 );
807     print( a_Quat, "set Quat xyz" );
808     print( a_Quat.getXYZ( ), "get Quat xyz" );
809     a_Quat = Quat( (vec_float4){0.0f} );
810     print( a_Quat, "set Quat elements to zero" );
811     a_Quat.setElem( 0, randfloat() );
812     print( a_Quat, "Quat::set( 0, float )" );
813     a_Quat[0] = randfloat();
814     a_Quat[0] = vec_mul_float( a_Quat[0], randfloat() );
815     a_Quat[0] = divf4( a_Quat[0], randfloat() );
816     a_Quat[0] = vec_add_float( a_Quat[0], randfloat() );
817     a_Quat[0] = vec_sub_float( a_Quat[0], randfloat() );
818     print( a_Quat, "Quat::operator [](0)" );
819     a_Quat.setX( randfloat() );
820     print( a_Quat, "Quat::setX()" );
821     a_Quat.setElem( 1, randfloat() );
822     print( a_Quat, "Quat::set( 1, float )" );
823     a_Quat[1] = randfloat();
824     a_Quat[1] = vec_mul_float( a_Quat[1], randfloat() );
825     a_Quat[1] = divf4( a_Quat[1], randfloat() );
826     a_Quat[1] = vec_add_float( a_Quat[1], randfloat() );
827     a_Quat[1] = vec_sub_float( a_Quat[1], randfloat() );
828     print( a_Quat, "Quat::operator [](1)" );
829     a_Quat.setY( randfloat() );
830     print( a_Quat, "Quat::setY()" );
831     a_Quat.setElem( 2, randfloat() );
832     print( a_Quat, "Quat::set( 2, float )" );
833     a_Quat[2] = randfloat();
834     a_Quat[2] = vec_mul_float( a_Quat[2], randfloat() );
835     a_Quat[2] = divf4( a_Quat[2], randfloat() );
836     a_Quat[2] = vec_add_float( a_Quat[2], randfloat() );
837     a_Quat[2] = vec_sub_float( a_Quat[2], randfloat() );
838     print( a_Quat, "Quat::operator [](2)" );
839     a_Quat.setZ( randfloat() );
840     print( a_Quat, "Quat::setZ()" );
841     a_Quat.setElem( 3, randfloat() );
842     print( a_Quat, "Quat::set( 3, float )" );
843     a_Quat[3] = randfloat();
844     a_Quat[3] = vec_mul_float( a_Quat[3], randfloat() );
845     a_Quat[3] = divf4( a_Quat[3], randfloat() );
846     a_Quat[3] = vec_add_float( a_Quat[3], randfloat() );
847     a_Quat[3] = vec_sub_float( a_Quat[3], randfloat() );
848     print( a_Quat, "Quat::operator [](3)" );
849     a_Quat.setW( randfloat() );
850     print( a_Quat, "Quat::setW()" );
851     printf("Quat::get( 0 ): %f\n", getfloat(a_Quat.getElem( 0 )) );
852     printf("Quat::operator []( 0 ): %f\n", getfloat((vec_float4)a_Quat[0]) );
853     printf("Quat::getX(): %f\n", getfloat(a_Quat.getX( )) );
854     printf("Quat::get( 1 ): %f\n", getfloat(a_Quat.getElem( 1 )) );
855     printf("Quat::operator []( 1 ): %f\n", getfloat((vec_float4)a_Quat[1]) );
856     printf("Quat::getY(): %f\n", getfloat(a_Quat.getY( )) );
857     printf("Quat::get( 2 ): %f\n", getfloat(a_Quat.getElem( 2 )) );
858     printf("Quat::operator []( 2 ): %f\n", getfloat((vec_float4)a_Quat[2]) );
859     printf("Quat::getZ(): %f\n", getfloat(a_Quat.getZ( )) );
860     printf("Quat::get( 3 ): %f\n", getfloat(a_Quat.getElem( 3 )) );
861     printf("Quat::operator []( 3 ): %f\n", getfloat((vec_float4)a_Quat[3]) );
862     printf("Quat::getW(): %f\n", getfloat(a_Quat.getW( )) );
863     print( ( a_Quat + b_Quat ), "Quat + Quat" );
864     print( ( a_Quat - b_Quat ), "Quat - Quat" );
865     print( ( a_Quat * b_Quat ), "Quat * Quat" );
866     print( ( a_Quat * randfloat() ), "Quat * float" );
867     print( ( a_Quat / randfloat() ), "Quat / float" );
868     print( ( randfloat() * a_Quat ), "float * Quat" );
869     print( ( -a_Quat ), "Quat negate" );
870     printf("Quat dot Quat: %f\n", getfloat(dot( a_Quat, b_Quat )));
871     printf("Quat lengthSqr: %f\n", getfloat(norm( a_Quat )));
872     printf("Quat length: %f\n", getfloat(length( a_Quat )));
873     print( normalize( a_Quat ), "Quat normalized" );
874     a_Quat = Quat::identity( );
875     print( a_Quat, "set to identity" );
876     a_Quat = Quat::rotation( a_Vector3, b_Vector3 );
877     print( a_Quat, "Quat rotation between vectors" );
878     a_Quat = Quat::rotation( randfloat(), a_Vector3 );
879     print( a_Quat, "Quat rotation axis angle" );
880     a_Quat = Quat::rotationX( randfloat() );
881     print( a_Quat, "Quat rotationX" );
882     a_Quat = Quat::rotationY( randfloat() );
883     print( a_Quat, "Quat rotationY" );
884     a_Quat = Quat::rotationZ( randfloat() );
885     print( a_Quat, "Quat rotationZ" );
886     print( rotate( a_Quat, a_Vector3 ), "Quat rotate Vector3" );
887     print( conj( a_Quat ), "Quat conj" );
888     rndflt1 = randfloat();
889     rndflt2 = randfloat();
890     rndflt3 = randfloat();
891     rndflt4 = randfloat();
892     b_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
893     rndflt1 = randfloat();
894     rndflt2 = randfloat();
895     rndflt3 = randfloat();
896     rndflt4 = randfloat();
897     c_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
898     rndflt1 = randfloat();
899     rndflt2 = randfloat();
900     rndflt3 = randfloat();
901     rndflt4 = randfloat();
902     d_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
903     rndflt1 = randfloat();
904     rndflt2 = randfloat();
905     rndflt3 = randfloat();
906     rndflt4 = randfloat();
907     e_Quat = Quat( rndflt1, rndflt2, rndflt3, rndflt4 );
908     b_Quat = normalize( b_Quat );
909     c_Quat = normalize( c_Quat );
910     d_Quat = normalize( d_Quat );
911     e_Quat = normalize( e_Quat );
912     a_Quat = lerp( randfloat(), b_Quat, c_Quat );
913     print( a_Quat, "Quat lerp" );
914     a_Quat = slerp( randfloat(), b_Quat, c_Quat );
915     print( a_Quat, "Quat slerp" );
916     a_Quat = squad( randfloat(), b_Quat, c_Quat, d_Quat, e_Quat );
917     print( a_Quat, "Quat squad" );
918 }
919
920 int main()
921 {
922     printf("\n __begin__ \n");
923     for ( iteration = 0; iteration < 2; iteration++ ) {
924         Vector3_methods_test();
925         Vector4_methods_test();
926         Point3_methods_test();
927         Quat_methods_test();
928     }
929     printf("\n __end__ \n");
930     return 0;
931 }