1 /*
2  * Copyright 2008 David Adam
3  * Copyright 2008 Luis Busquets
4  * Copyright 2008 Philip Nilsson
5  * Copyright 2008 Henri Verbeet
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include "wine/test.h"
23 #include "d3dx9.h"
24 #include <math.h>
25 
26 static BOOL compare_float(float f, float g, unsigned int ulps)
27 {
28     int x = *(int *)&f;
29     int y = *(int *)&g;
30 
31     if (x < 0)
32         x = INT_MIN - x;
33     if (y < 0)
34         y = INT_MIN - y;
35 
36     if (abs(x - y) > ulps)
37         return FALSE;
38 
39     return TRUE;
40 }
41 
42 static BOOL compare_vec2(const D3DXVECTOR2 *v1, const D3DXVECTOR2 *v2, unsigned int ulps)
43 {
44     return compare_float(v1->x, v2->x, ulps) && compare_float(v1->y, v2->y, ulps);
45 }
46 
47 static BOOL compare_vec3(const D3DXVECTOR3 *v1, const D3DXVECTOR3 *v2, unsigned int ulps)
48 {
49     return compare_float(v1->x, v2->x, ulps)
50             && compare_float(v1->y, v2->y, ulps)
51             && compare_float(v1->z, v2->z, ulps);
52 }
53 
54 static BOOL compare_vec4(const D3DXVECTOR4 *v1, const D3DXVECTOR4 *v2, unsigned int ulps)
55 {
56     return compare_float(v1->x, v2->x, ulps)
57             && compare_float(v1->y, v2->y, ulps)
58             && compare_float(v1->z, v2->z, ulps)
59             && compare_float(v1->w, v2->w, ulps);
60 }
61 
62 static BOOL compare_color(const D3DXCOLOR *c1, const D3DXCOLOR *c2, unsigned int ulps)
63 {
64     return compare_float(c1->r, c2->r, ulps)
65             && compare_float(c1->g, c2->g, ulps)
66             && compare_float(c1->b, c2->b, ulps)
67             && compare_float(c1->a, c2->a, ulps);
68 }
69 
70 static BOOL compare_plane(const D3DXPLANE *p1, const D3DXPLANE *p2, unsigned int ulps)
71 {
72     return compare_float(p1->a, p2->a, ulps)
73             && compare_float(p1->b, p2->b, ulps)
74             && compare_float(p1->c, p2->c, ulps)
75             && compare_float(p1->d, p2->d, ulps);
76 }
77 
78 static BOOL compare_quaternion(const D3DXQUATERNION *q1, const D3DXQUATERNION *q2, unsigned int ulps)
79 {
80     return compare_float(q1->x, q2->x, ulps)
81             && compare_float(q1->y, q2->y, ulps)
82             && compare_float(q1->z, q2->z, ulps)
83             && compare_float(q1->w, q2->w, ulps);
84 }
85 
86 static BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2, unsigned int ulps)
87 {
88     unsigned int i, j;
89 
90     for (i = 0; i < 4; ++i)
91     {
92         for (j = 0; j < 4; ++j)
93         {
94             if (!compare_float(U(*m1).m[i][j], U(*m2).m[i][j], ulps))
95                 return FALSE;
96         }
97     }
98 
99     return TRUE;
100 }
101 
102 #define expect_vec2(expected, vector, ulps) expect_vec2_(__LINE__, expected, vector, ulps)
103 static void expect_vec2_(unsigned int line, const D3DXVECTOR2 *expected, const D3DXVECTOR2 *vector, unsigned int ulps)
104 {
105     BOOL equal = compare_vec2(expected, vector, ulps);
106     ok_(__FILE__, line)(equal,
107             "Got unexpected vector {%.8e, %.8e}, expected {%.8e, %.8e}.\n",
108             vector->x, vector->y, expected->x, expected->y);
109 }
110 
111 #define expect_vec3(expected, vector, ulps) expect_vec3_(__LINE__, expected, vector, ulps)
112 static void expect_vec3_(unsigned int line, const D3DXVECTOR3 *expected, const D3DXVECTOR3 *vector, unsigned int ulps)
113 {
114     BOOL equal = compare_vec3(expected, vector, ulps);
115     ok_(__FILE__, line)(equal,
116             "Got unexpected vector {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
117             vector->x, vector->y, vector->z, expected->x, expected->y, expected->z);
118 }
119 
120 #define expect_vec4(expected, vector, ulps) expect_vec4_(__LINE__, expected, vector, ulps)
121 static void expect_vec4_(unsigned int line, const D3DXVECTOR4 *expected, const D3DXVECTOR4 *vector, unsigned int ulps)
122 {
123     BOOL equal = compare_vec4(expected, vector, ulps);
124     ok_(__FILE__, line)(equal,
125             "Got unexpected vector {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
126             vector->x, vector->y, vector->z, vector->w, expected->x, expected->y, expected->z, expected->w);
127 }
128 
129 #define expect_color(expected, color, ulps) expect_color_(__LINE__, expected, color, ulps)
130 static void expect_color_(unsigned int line, const D3DXCOLOR *expected, const D3DXCOLOR *color, unsigned int ulps)
131 {
132     BOOL equal = compare_color(expected, color, ulps);
133     ok_(__FILE__, line)(equal,
134             "Got unexpected color {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
135             color->r, color->g, color->b, color->a, expected->r, expected->g, expected->b, expected->a);
136 }
137 
138 #define expect_plane(expected, plane, ulps) expect_plane_(__LINE__, expected, plane, ulps)
139 static void expect_plane_(unsigned int line, const D3DXPLANE *expected, const D3DXPLANE *plane, unsigned int ulps)
140 {
141     BOOL equal = compare_plane(expected, plane, ulps);
142     ok_(__FILE__, line)(equal,
143             "Got unexpected plane {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
144             plane->a, plane->b, plane->c, plane->d, expected->a, expected->b, expected->c, expected->d);
145 }
146 
147 #define expect_quaternion(expected, quaternion, ulps) expect_quaternion_(__LINE__, expected, quaternion, ulps)
148 static void expect_quaternion_(unsigned int line, const D3DXQUATERNION *expected,
149         const D3DXQUATERNION *quaternion, unsigned int ulps)
150 {
151     BOOL equal = compare_quaternion(expected, quaternion, ulps);
152     ok_(__FILE__, line)(equal,
153             "Got unexpected quaternion {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
154             quaternion->x, quaternion->y, quaternion->z, quaternion->w,
155             expected->x, expected->y, expected->z, expected->w);
156 }
157 
158 #define expect_matrix(expected, matrix, ulps) expect_matrix_(__LINE__, expected, matrix, ulps)
159 static void expect_matrix_(unsigned int line, const D3DXMATRIX *expected, const D3DXMATRIX *matrix, unsigned int ulps)
160 {
161     BOOL equal = compare_matrix(expected, matrix, ulps);
162     ok_(__FILE__, line)(equal,
163             "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, "
164             "%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e}, "
165             "expected {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, "
166             "%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
167             U(*matrix).m[0][0], U(*matrix).m[0][1], U(*matrix).m[0][2], U(*matrix).m[0][3],
168             U(*matrix).m[1][0], U(*matrix).m[1][1], U(*matrix).m[1][2], U(*matrix).m[1][3],
169             U(*matrix).m[2][0], U(*matrix).m[2][1], U(*matrix).m[2][2], U(*matrix).m[2][3],
170             U(*matrix).m[3][0], U(*matrix).m[3][1], U(*matrix).m[3][2], U(*matrix).m[3][3],
171             U(*expected).m[0][0], U(*expected).m[0][1], U(*expected).m[0][2], U(*expected).m[0][3],
172             U(*expected).m[1][0], U(*expected).m[1][1], U(*expected).m[1][2], U(*expected).m[1][3],
173             U(*expected).m[2][0], U(*expected).m[2][1], U(*expected).m[2][2], U(*expected).m[2][3],
174             U(*expected).m[3][0], U(*expected).m[3][1], U(*expected).m[3][2], U(*expected).m[3][3]);
175 }
176 
177 #define expect_vec4_array(count, expected, vector, ulps) expect_vec4_array_(__LINE__, count, expected, vector, ulps)
178 static void expect_vec4_array_(unsigned int line, unsigned int count, const D3DXVECTOR4 *expected,
179         const D3DXVECTOR4 *vector, unsigned int ulps)
180 {
181     BOOL equal;
182     unsigned int i;
183 
184     for (i = 0; i < count; ++i)
185     {
186         equal = compare_vec4(&expected[i], &vector[i], ulps);
187         ok_(__FILE__, line)(equal,
188                 "Got unexpected vector {%.8e, %.8e, %.8e, %.8e} at index %u, expected {%.8e, %.8e, %.8e, %.8e}.\n",
189                 vector[i].x, vector[i].y, vector[i].z, vector[i].w, i,
190                 expected[i].x, expected[i].y, expected[i].z, expected[i].w);
191         if (!equal)
192             break;
193     }
194 }
195 
196 static void set_matrix(D3DXMATRIX* mat,
197         float m00, float m01, float m02, float m03,
198         float m10, float m11, float m12, float m13,
199         float m20, float m21, float m22, float m23,
200         float m30, float m31, float m32, float m33)
201 {
202     U(mat)->m[0][0] = m00; U(mat)->m[0][1] = m01; U(mat)->m[0][2] = m02; U(mat)->m[0][3] = m03;
203     U(mat)->m[1][0] = m10; U(mat)->m[1][1] = m11; U(mat)->m[1][2] = m12; U(mat)->m[1][3] = m13;
204     U(mat)->m[2][0] = m20; U(mat)->m[2][1] = m21; U(mat)->m[2][2] = m22; U(mat)->m[2][3] = m23;
205     U(mat)->m[3][0] = m30; U(mat)->m[3][1] = m31; U(mat)->m[3][2] = m32; U(mat)->m[3][3] = m33;
206 }
207 
208 static void D3DXColorTest(void)
209 {
210     D3DXCOLOR color, color1, color2, expected, got;
211     LPD3DXCOLOR funcpointer;
212     FLOAT scale;
213 
214     color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
215     color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
216     color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
217 
218     scale = 0.3f;
219 
220 /*_______________D3DXColorAdd________________*/
221     expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
222     D3DXColorAdd(&got,&color1,&color2);
223     expect_color(&expected, &got, 1);
224     /* Test the NULL case */
225     funcpointer = D3DXColorAdd(&got,NULL,&color2);
226     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
227     funcpointer = D3DXColorAdd(NULL,NULL,&color2);
228     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
229     funcpointer = D3DXColorAdd(NULL,NULL,NULL);
230     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
231 
232 /*_______________D3DXColorAdjustContrast______*/
233     expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
234     D3DXColorAdjustContrast(&got,&color,scale);
235     expect_color(&expected, &got, 0);
236 
237 /*_______________D3DXColorAdjustSaturation______*/
238     expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
239     D3DXColorAdjustSaturation(&got,&color,scale);
240     expect_color(&expected, &got, 16);
241 
242 /*_______________D3DXColorLerp________________*/
243     expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
244     D3DXColorLerp(&got,&color,&color1,scale);
245     expect_color(&expected, &got, 0);
246     /* Test the NULL case */
247     funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
248     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
249     funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
250     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
251     funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
252     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
253 
254 /*_______________D3DXColorModulate________________*/
255     expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
256     D3DXColorModulate(&got,&color1,&color2);
257     expect_color(&expected, &got, 0);
258     /* Test the NULL case */
259     funcpointer = D3DXColorModulate(&got,NULL,&color2);
260     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
261     funcpointer = D3DXColorModulate(NULL,NULL,&color2);
262     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
263     funcpointer = D3DXColorModulate(NULL,NULL,NULL);
264     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
265 
266 /*_______________D3DXColorNegative________________*/
267     expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
268     D3DXColorNegative(&got,&color);
269     expect_color(&expected, &got, 1);
270     /* Test the greater than 1 case */
271     color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
272     expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
273     D3DXColorNegative(&got,&color1);
274     expect_color(&expected, &got, 1);
275     /* Test the negative case */
276     color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
277     expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
278     D3DXColorNegative(&got,&color1);
279     expect_color(&expected, &got, 1);
280     /* Test the NULL case */
281     funcpointer = D3DXColorNegative(&got,NULL);
282     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
283     funcpointer = D3DXColorNegative(NULL,NULL);
284     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
285 
286 /*_______________D3DXColorScale________________*/
287     expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
288     D3DXColorScale(&got,&color,scale);
289     expect_color(&expected, &got, 1);
290     /* Test the NULL case */
291     funcpointer = D3DXColorScale(&got,NULL,scale);
292     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
293     funcpointer = D3DXColorScale(NULL,NULL,scale);
294     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
295 
296 /*_______________D3DXColorSubtract_______________*/
297     expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
298     D3DXColorSubtract(&got,&color,&color2);
299     expect_color(&expected, &got, 1);
300     /* Test the NULL case */
301     funcpointer = D3DXColorSubtract(&got,NULL,&color2);
302     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
303     funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
304     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
305     funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
306     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
307 }
308 
309 static void D3DXFresnelTest(void)
310 {
311     float fresnel;
312     BOOL equal;
313 
314     fresnel = D3DXFresnelTerm(0.5f, 1.5f);
315     equal = compare_float(fresnel, 8.91867128e-02f, 1);
316     ok(equal, "Got unexpected Fresnel term %.8e.\n", fresnel);
317 }
318 
319 static void D3DXMatrixTest(void)
320 {
321     D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
322     BOOL expected, got, equal;
323     float angle, determinant;
324     D3DXMATRIX *funcpointer;
325     D3DXPLANE plane;
326     D3DXQUATERNION q, r;
327     D3DXVECTOR3 at, axis, eye, last;
328     D3DXVECTOR4 light;
329 
330     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
331     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
332     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
333     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
334     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
335     U(mat).m[3][3] = -40.0f;
336 
337     U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
338     U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
339     U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
340     U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
341     U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
342     U(mat2).m[3][3] = -1.0f;
343 
344     plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
345 
346     q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
347     r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
348 
349     at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
350     axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
351     eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
352     last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
353 
354     light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
355 
356     angle = D3DX_PI/3.0f;
357 
358 /*____________D3DXMatrixAffineTransformation______*/
359     set_matrix(&expectedmat,
360             -459.239990f, -576.719971f, -263.440002f, 0.0f,
361             519.760010f, -352.440002f, -277.679993f, 0.0f,
362             363.119995f, -121.040001f, -117.479996f, 0.0f,
363             -1239.0f, 667.0f, 567.0f, 1.0f);
364     D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, &axis);
365     expect_matrix(&expectedmat, &gotmat, 0);
366 
367     /* Test the NULL case */
368     U(expectedmat).m[3][0] = 1.0f; U(expectedmat).m[3][1] = -3.0f; U(expectedmat).m[3][2] = 7.0f; U(expectedmat).m[3][3] = 1.0f;
369     D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, &axis);
370     expect_matrix(&expectedmat, &gotmat, 0);
371 
372     U(expectedmat).m[3][0] = -1240.0f; U(expectedmat).m[3][1] = 670.0f; U(expectedmat).m[3][2] = 560.0f; U(expectedmat).m[3][3] = 1.0f;
373     D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, NULL);
374     expect_matrix(&expectedmat, &gotmat, 0);
375 
376     U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 0.0f; U(expectedmat).m[3][3] = 1.0f;
377     D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, NULL);
378     expect_matrix(&expectedmat, &gotmat, 0);
379 
380     set_matrix(&expectedmat,
381             3.56f, 0.0f, 0.0f, 0.0f,
382             0.0f, 3.56f, 0.0f, 0.0f,
383             0.0f, 0.0f, 3.56f, 0.0f,
384             1.0f, -3.0f, 7.0f, 1.0f);
385     D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, &axis);
386     expect_matrix(&expectedmat, &gotmat, 0);
387 
388     D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, &axis);
389     expect_matrix(&expectedmat, &gotmat, 0);
390 
391     U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 0.0f; U(expectedmat).m[3][3] = 1.0f;
392     D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, NULL);
393     expect_matrix(&expectedmat, &gotmat, 0);
394 
395     D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, NULL);
396     expect_matrix(&expectedmat, &gotmat, 0);
397 
398 /*____________D3DXMatrixfDeterminant_____________*/
399     determinant = D3DXMatrixDeterminant(&mat);
400     equal = compare_float(determinant, -147888.0f, 0);
401     ok(equal, "Got unexpected determinant %.8e.\n", determinant);
402 
403 /*____________D3DXMatrixInverse______________*/
404     set_matrix(&expectedmat,
405             16067.0f/73944.0f, -10165.0f/147888.0f, -2729.0f/147888.0f, -1631.0f/49296.0f,
406             -565.0f/36972.0f, 2723.0f/73944.0f, -1073.0f/73944.0f, 289.0f/24648.0f,
407             -389.0f/2054.0f, 337.0f/4108.0f, 181.0f/4108.0f, 317.0f/4108.0f,
408             163.0f/5688.0f, -101.0f/11376.0f, -73.0f/11376.0f, -127.0f/3792.0f);
409     D3DXMatrixInverse(&gotmat, &determinant, &mat);
410     expect_matrix(&expectedmat, &gotmat, 1);
411     equal = compare_float(determinant, -147888.0f, 0);
412     ok(equal, "Got unexpected determinant %.8e.\n", determinant);
413     funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
414     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
415 
416 /*____________D3DXMatrixIsIdentity______________*/
417     expected = FALSE;
418     memset(&mat3, 0, sizeof(mat3));
419     got = D3DXMatrixIsIdentity(&mat3);
420     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
421     D3DXMatrixIdentity(&mat3);
422     expected = TRUE;
423     got = D3DXMatrixIsIdentity(&mat3);
424     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
425     U(mat3).m[0][0] = 0.000009f;
426     expected = FALSE;
427     got = D3DXMatrixIsIdentity(&mat3);
428     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
429     /* Test the NULL case */
430     expected = FALSE;
431     got = D3DXMatrixIsIdentity(NULL);
432     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
433 
434 /*____________D3DXMatrixLookAtLH_______________*/
435     set_matrix(&expectedmat,
436             -0.82246518f, -0.40948939f, -0.39480308f, 0.0f,
437             -0.55585691f, 0.43128574f, 0.71064550f, 0.0f,
438             -0.12072885f, 0.80393475f, -0.58233452f, 0.0f,
439             4.4946337f, 0.80971903f, 10.060076f, 1.0f);
440     D3DXMatrixLookAtLH(&gotmat, &eye, &at, &axis);
441     expect_matrix(&expectedmat, &gotmat, 32);
442 
443 /*____________D3DXMatrixLookAtRH_______________*/
444     set_matrix(&expectedmat,
445             0.82246518f, -0.40948939f, 0.39480308f, 0.0f,
446             0.55585691f, 0.43128574f, -0.71064550f, 0.0f,
447             0.12072885f, 0.80393475f, 0.58233452f, 0.0f,
448             -4.4946337f, 0.80971903f, -10.060076f, 1.0f);
449     D3DXMatrixLookAtRH(&gotmat, &eye, &at, &axis);
450     expect_matrix(&expectedmat, &gotmat, 32);
451 
452 /*____________D3DXMatrixMultiply______________*/
453     set_matrix(&expectedmat,
454             73.0f, 193.0f, -197.0f, -77.0f,
455             231.0f, 551.0f, -489.0f, -169.0f,
456             239.0f, 523.0f, -400.0f, -116.0f,
457             -164.0f, -320.0f, 187.0f, 31.0f);
458     D3DXMatrixMultiply(&gotmat, &mat, &mat2);
459     expect_matrix(&expectedmat, &gotmat, 0);
460 
461 /*____________D3DXMatrixMultiplyTranspose____*/
462     set_matrix(&expectedmat,
463             73.0f, 231.0f, 239.0f, -164.0f,
464             193.0f, 551.0f, 523.0f, -320.0f,
465             -197.0f, -489.0f, -400.0f, 187.0f,
466             -77.0f, -169.0f, -116.0f, 31.0f);
467     D3DXMatrixMultiplyTranspose(&gotmat, &mat, &mat2);
468     expect_matrix(&expectedmat, &gotmat, 0);
469 
470 /*____________D3DXMatrixOrthoLH_______________*/
471     set_matrix(&expectedmat,
472             0.8f, 0.0f, 0.0f, 0.0f,
473             0.0f, 0.27027027f, 0.0f, 0.0f,
474             0.0f, 0.0f, -0.15151515f, 0.0f,
475             0.0f, 0.0f, -0.48484848f, 1.0f);
476     D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
477     expect_matrix(&expectedmat, &gotmat, 16);
478 
479 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
480     set_matrix(&expectedmat,
481             3.6363636f, 0.0f, 0.0f, 0.0f,
482             0.0f, 0.18018018f, 0.0f, 0.0f,
483             0.0f, 0.0f, -0.045662100f, 0.0f,
484             -1.7272727f, -0.56756757f, 0.42465753f, 1.0f);
485     D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
486     expect_matrix(&expectedmat, &gotmat, 32);
487 
488 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
489     set_matrix(&expectedmat,
490             3.6363636f, 0.0f, 0.0f, 0.0f,
491             0.0f, 0.18018018f, 0.0f, 0.0f,
492             0.0f, 0.0f, 0.045662100f, 0.0f,
493             -1.7272727f, -0.56756757f, 0.42465753f, 1.0f);
494     D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
495     expect_matrix(&expectedmat, &gotmat, 32);
496 
497 /*____________D3DXMatrixOrthoRH_______________*/
498     set_matrix(&expectedmat,
499             0.8f, 0.0f, 0.0f, 0.0f,
500             0.0f, 0.27027027f, 0.0f, 0.0f,
501             0.0f, 0.0f, 0.15151515f, 0.0f,
502             0.0f, 0.0f, -0.48484848f, 1.0f);
503     D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
504     expect_matrix(&expectedmat, &gotmat, 16);
505 
506 /*____________D3DXMatrixPerspectiveFovLH_______________*/
507     set_matrix(&expectedmat,
508             13.288858f, 0.0f, 0.0f, 0.0f,
509             0.0f, 9.9666444f, 0.0f, 0.0f,
510             0.0f, 0.0f, 0.78378378f, 1.0f,
511             0.0f, 0.0f, 1.8810811f, 0.0f);
512     D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
513     expect_matrix(&expectedmat, &gotmat, 4);
514 
515 /*____________D3DXMatrixPerspectiveFovRH_______________*/
516     set_matrix(&expectedmat,
517             13.288858f, 0.0f, 0.0f, 0.0f,
518             0.0f, 9.9666444f, 0.0f, 0.0f,
519             0.0f, 0.0f, -0.78378378f, -1.0f,
520             0.0f, 0.0f, 1.8810811f, 0.0f);
521     D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
522     expect_matrix(&expectedmat, &gotmat, 4);
523 
524 /*____________D3DXMatrixPerspectiveLH_______________*/
525     set_matrix(&expectedmat,
526             -24.0f, 0.0f, 0.0f, 0.0f,
527             0.0f, -6.4f, 0.0f, 0.0f,
528             0.0f, 0.0f, 0.78378378f, 1.0f,
529             0.0f, 0.0f, 1.8810811f, 0.0f);
530     D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
531     expect_matrix(&expectedmat, &gotmat, 4);
532 
533 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
534     set_matrix(&expectedmat,
535             11.636364f, 0.0f, 0.0f, 0.0f,
536             0.0f, 0.57657658f, 0.0f, 0.0f,
537             -1.7272727f, -0.56756757f, 0.84079602f, 1.0f,
538             0.0f, 0.0f, -2.6905473f, 0.0f);
539     D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
540     expect_matrix(&expectedmat, &gotmat, 8);
541 
542 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
543     set_matrix(&expectedmat,
544             11.636364f, 0.0f, 0.0f, 0.0f,
545             0.0f, 0.57657658f, 0.0f, 0.0f,
546             1.7272727f, 0.56756757f, -0.84079602f, -1.0f,
547             0.0f, 0.0f, -2.6905473f, 0.0f);
548     D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
549     expect_matrix(&expectedmat, &gotmat, 8);
550 
551 /*____________D3DXMatrixPerspectiveRH_______________*/
552     set_matrix(&expectedmat,
553             -24.0f, -0.0f, 0.0f, 0.0f,
554             0.0f, -6.4f, 0.0f, 0.0f,
555             0.0f, 0.0f, -0.78378378f, -1.0f,
556             0.0f, 0.0f, 1.8810811f, 0.0f);
557     D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
558     expect_matrix(&expectedmat, &gotmat, 4);
559 
560 /*____________D3DXMatrixReflect______________*/
561     set_matrix(&expectedmat,
562             0.30769235f, -0.23076922f, 0.92307687f, 0.0f,
563             -0.23076922, 0.92307693f, 0.30769232f, 0.0f,
564             0.92307687f, 0.30769232f, -0.23076922f, 0.0f,
565             1.6153846f, 0.53846157f, -2.1538463f, 1.0f);
566     D3DXMatrixReflect(&gotmat, &plane);
567     expect_matrix(&expectedmat, &gotmat, 32);
568 
569 /*____________D3DXMatrixRotationAxis_____*/
570     set_matrix(&expectedmat,
571             0.50847453f, 0.76380461f, 0.39756277f, 0.0f,
572             -0.81465209f, 0.57627118f, -0.065219201f, 0.0f,
573             -0.27891868f, -0.29071301f, 0.91525424f, 0.0f,
574             0.0f, 0.0f, 0.0f, 1.0f);
575     D3DXMatrixRotationAxis(&gotmat, &axis, angle);
576     expect_matrix(&expectedmat, &gotmat, 32);
577 
578 /*____________D3DXMatrixRotationQuaternion______________*/
579     set_matrix(&expectedmat,
580             -129.0f, -162.0f, -74.0f, 0.0f,
581             146.0f, -99.0f, -78.0f, 0.0f,
582             102.0f, -34.0f, -33.0f, 0.0f,
583             0.0f, 0.0f, 0.0f, 1.0f);
584     D3DXMatrixRotationQuaternion(&gotmat, &q);
585     expect_matrix(&expectedmat, &gotmat, 0);
586 
587 /*____________D3DXMatrixRotationX______________*/
588     set_matrix(&expectedmat,
589             1.0f, 0.0f, 0.0f, 0.0f,
590             0.0f, 0.5f, sqrt(3.0f)/2.0f, 0.0f,
591             0.0f, -sqrt(3.0f)/2.0f, 0.5f, 0.0f,
592             0.0f, 0.0f, 0.0f, 1.0f);
593     D3DXMatrixRotationX(&gotmat, angle);
594     expect_matrix(&expectedmat, &gotmat, 1);
595 
596 /*____________D3DXMatrixRotationY______________*/
597     set_matrix(&expectedmat,
598             0.5f, 0.0f, -sqrt(3.0f)/2.0f, 0.0f,
599             0.0f, 1.0f, 0.0f, 0.0f,
600             sqrt(3.0f)/2.0f, 0.0f, 0.5f, 0.0f,
601             0.0f, 0.0f, 0.0f, 1.0f);
602     D3DXMatrixRotationY(&gotmat, angle);
603     expect_matrix(&expectedmat, &gotmat, 1);
604 
605 /*____________D3DXMatrixRotationYawPitchRoll____*/
606     set_matrix(&expectedmat,
607             0.88877726f, 0.091874748f, -0.44903678f, 0.0f,
608             0.35171318f, 0.49148652f, 0.79670501f, 0.0f,
609             0.29389259f, -0.86602545f, 0.40450847f, 0.0f,
610             0.0f, 0.0f, 0.0f, 1.0f);
611     D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f * angle / 5.0f, angle, 3.0f * angle / 17.0f);
612     expect_matrix(&expectedmat, &gotmat, 64);
613 
614 /*____________D3DXMatrixRotationZ______________*/
615     set_matrix(&expectedmat,
616             0.5f, sqrt(3.0f)/2.0f, 0.0f, 0.0f,
617             -sqrt(3.0f)/2.0f, 0.5f, 0.0f, 0.0f,
618             0.0f, 0.0f, 1.0f, 0.0f,
619             0.0f, 0.0f, 0.0f, 1.0f);
620     D3DXMatrixRotationZ(&gotmat, angle);
621     expect_matrix(&expectedmat, &gotmat, 1);
622 
623 /*____________D3DXMatrixScaling______________*/
624     set_matrix(&expectedmat,
625             0.69f, 0.0f, 0.0f, 0.0f,
626             0.0f, 0.53f, 0.0f, 0.0f,
627             0.0f, 0.0f, 4.11f, 0.0f,
628             0.0f, 0.0f, 0.0f, 1.0f);
629     D3DXMatrixScaling(&gotmat, 0.69f, 0.53f, 4.11f);
630     expect_matrix(&expectedmat, &gotmat, 0);
631 
632 /*____________D3DXMatrixShadow______________*/
633     set_matrix(&expectedmat,
634             12.786773f, 5.0009613f, 4.3537784f, 3.7065949f,
635             1.8827150f, 8.8056154f, 1.4512594f, 1.2355317f,
636             -7.5308599f, -6.6679487f, 1.3335901f, -4.9421268f,
637             -13.179006f, -11.668910f, -10.158816f, -1.5100943f);
638     D3DXMatrixShadow(&gotmat, &light, &plane);
639     expect_matrix(&expectedmat, &gotmat, 8);
640 
641 /*____________D3DXMatrixTransformation______________*/
642     set_matrix(&expectedmat,
643             1.0f, 0.0f, 0.0f, 0.0f,
644             0.0f, 1.0f, 0.0f, 0.0f,
645             0.0f, 0.0f, 1.0f, 0.0f,
646             0.0f, 0.0f, 0.0f, 1.0f);
647     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, NULL, NULL, NULL);
648     expect_matrix(&expectedmat, &gotmat, 0);
649 
650     set_matrix(&expectedmat,
651             1.0f, 0.0f, 0.0f, 0.0f,
652             0.0f, 1.0f, 0.0f, 0.0f,
653             0.0f, 0.0f, 1.0f, 0.0f,
654             9.7f, -8.6f, 1.3f, 1.0f);
655     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, NULL, NULL, &last);
656     expect_matrix(&expectedmat, &gotmat, 0);
657 
658     set_matrix(&expectedmat,
659             -0.2148f, 1.3116f, 0.4752f, 0.0f,
660             0.9504f, -0.8836f, 0.9244f, 0.0f,
661             1.0212f, 0.1936f, -1.3588f, 0.0f,
662             0.0f, 0.0f, 0.0f, 1.0f);
663     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, NULL, &r, NULL);
664     expect_matrix(&expectedmat, &gotmat, 8);
665 
666     set_matrix(&expectedmat,
667             1.0f, 0.0f, 0.0f, 0.0f,
668             0.0f, 1.0f, 0.0f, 0.0f,
669             0.0f, 0.0f, 1.0f, 0.0f,
670             0.0f, 0.0f, 0.0f, 1.0f);
671     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, &eye, NULL, NULL);
672     expect_matrix(&expectedmat, &gotmat, 0);
673 
674     set_matrix(&expectedmat,
675             1.0f, 0.0f, 0.0f, 0.0f,
676             0.0f, -3.0f, 0.0f, 0.0f,
677             0.0f, 0.0f, 7.0f, 0.0f,
678             0.0f, 0.0f, 0.0f, 1.0f);
679     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, NULL, NULL, NULL);
680     expect_matrix(&expectedmat, &gotmat, 0);
681 
682     set_matrix(&expectedmat,
683             1.0f, 0.0f, 0.0f, 0.0f,
684             0.0f, 1.0f, 0.0f, 0.0f,
685             0.0f, 0.0f, 1.0f, 0.0f,
686             0.0f, 0.0f, 0.0f, 1.0f);
687     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, NULL, NULL, NULL);
688     expect_matrix(&expectedmat, &gotmat, 0);
689 
690     set_matrix(&expectedmat,
691             1.0f, 0.0f, 0.0f, 0.0f,
692             0.0f, 1.0f, 0.0f, 0.0f,
693             0.0f, 0.0f, 1.0f, 0.0f,
694             0.0f, 0.0f, 0.0f, 1.0f);
695     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, NULL, NULL, NULL);
696     expect_matrix(&expectedmat, &gotmat, 0);
697 
698     set_matrix(&expectedmat,
699             -0.2148f, 1.3116f, 0.4752f, 0.0f,
700             0.9504f, -0.8836f, 0.9244f, 0.0f,
701             1.0212f, 0.1936f, -1.3588f, 0.0f,
702             9.7f, -8.6f, 1.3f, 1.0f);
703     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, NULL, &r, &last);
704     expect_matrix(&expectedmat, &gotmat, 8);
705 
706     set_matrix(&expectedmat,
707             1.0f, 0.0f, 0.0f, 0.0f,
708             0.0f, 1.0f, 0.0f, 0.0f,
709             0.0f, 0.0f, 1.0f, 0.0f,
710             9.7f, -8.6f, 1.3f, 1.0f);
711     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, &eye, NULL, &last);
712     expect_matrix(&expectedmat, &gotmat, 0);
713 
714     set_matrix(&expectedmat,
715             1.0f, 0.0f, 0.0f, 0.0f,
716             0.0f, -3.0f, 0.0f, 0.0f,
717             0.0f, 0.0f, 7.0f, 0.0f,
718             9.7f, -8.6f, 1.3f, 1.0f);
719     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, NULL, NULL, &last);
720     expect_matrix(&expectedmat, &gotmat, 0);
721 
722     set_matrix(&expectedmat,
723             1.0f, 0.0f, 0.0f, 0.0f,
724             0.0f, 1.0f, 0.0f, 0.0f,
725             0.0f, 0.0f, 1.0f, 0.0f,
726             9.7f, -8.6f, 1.3f, 1.0f);
727     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, NULL, NULL, &last);
728     expect_matrix(&expectedmat, &gotmat, 0);
729 
730     set_matrix(&expectedmat,
731             1.0f, 0.0f, 0.0f, 0.0f,
732             0.0f, 1.0f, 0.0f, 0.0f,
733             0.0f, 0.0f, 1.0f, 0.0f,
734             9.7f, -8.6f, 1.3f, 1.0f);
735     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, NULL, NULL, &last);
736     expect_matrix(&expectedmat, &gotmat, 0);
737 
738     set_matrix(&expectedmat,
739             -0.2148f, 1.3116f, 0.4752f, 0.0f,
740             0.9504f, -0.8836f, 0.9244f, 0.0f,
741             1.0212f, 0.1936f, -1.3588f, 0.0f,
742             8.5985f, -21.024f, 14.383499, 1.0f);
743     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, &eye, &r, NULL);
744     expect_matrix(&expectedmat, &gotmat, 8);
745 
746     set_matrix(&expectedmat,
747             -0.2148f, 1.3116f, 0.4752f, 0.0f,
748             -2.8512f, 2.6508f, -2.7732f, 0.0f,
749             7.148399f, 1.3552f, -9.5116f, 0.0f,
750             0.0f, 0.0f, 0.0f, 1.0f);
751     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, NULL, &r, NULL);
752     expect_matrix(&expectedmat, &gotmat, 8);
753 
754     set_matrix(&expectedmat,
755             -0.2148f, 1.3116f, 0.4752f, 0.0f,
756             0.9504f, -0.8836f, 0.9244f, 0.0f,
757             1.0212f, 0.1936f, -1.3588f, 0.0f,
758             0.0f, 0.0f, 0.0f, 1.0f);
759     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, NULL, &r, NULL);
760     expect_matrix(&expectedmat, &gotmat, 8);
761 
762     set_matrix(&expectedmat,
763             -0.2148f, 1.3116f, 0.4752f, 0.0f,
764             0.9504f, -0.8836f, 0.9244f, 0.0f,
765             1.0212f, 0.1936f, -1.3588f, 0.0f,
766             0.0f, 0.0f, 0.0f, 1.0f);
767     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, NULL, &r, NULL);
768     expect_matrix(&expectedmat, &gotmat, 8);
769 
770     set_matrix(&expectedmat,
771             1.0f, 0.0f, 0.0f, 0.0f,
772             0.0f, -3.0f, 0.0f, 0.0f,
773             0.0f, 0.0f, 7.0f, 0.0f,
774             0.0f, 0.0f, 0.0f, 1.0f);
775     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, &eye, NULL, NULL);
776     expect_matrix(&expectedmat, &gotmat, 0);
777 
778     set_matrix(&expectedmat,
779             1.0f, 0.0f, 0.0f, 0.0f,
780             0.0f, 1.0f, 0.0f, 0.0f,
781             0.0f, 0.0f, 1.0f, 0.0f,
782             0.0f, 0.0f, 0.0f, 1.0f);
783     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, &eye, NULL, NULL);
784     expect_matrix(&expectedmat, &gotmat, 0);
785 
786     set_matrix(&expectedmat,
787             1.0f, 0.0f, 0.0f, 0.0f,
788             0.0f, 1.0f, 0.0f, 0.0f,
789             0.0f, 0.0f, 1.0f, 0.0f,
790             0.0f, 0.0f, 0.0f, 1.0f);
791     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, &eye, NULL, NULL);
792     expect_matrix(&expectedmat, &gotmat, 0);
793 
794     set_matrix(&expectedmat,
795             25521.0f, 39984.0f, 20148.0f, 0.0f,
796             39984.0f, 4933.0f, -3324.0f, 0.0f,
797             20148.0f, -3324.0f, -5153.0f, 0.0f,
798             0.0f, 0.0f, 0.0f, 1.0f);
799     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
800     expect_matrix(&expectedmat, &gotmat, 0);
801 
802     set_matrix(&expectedmat,
803             1.0f, 0.0f, 0.0f, 0.0f,
804             0.0f, -3.0f, 0.0f, 0.0f,
805             0.0f, 0.0f, 7.0f, 0.0f,
806             0.0f, 52.0f, 54.0f, 1.0f);
807     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, NULL, NULL, NULL);
808     expect_matrix(&expectedmat, &gotmat, 0);
809 
810     set_matrix(&expectedmat,
811             1.0f, 0.0f, 0.0f, 0.0f,
812             0.0f, 1.0f, 0.0f, 0.0f,
813             0.0f, 0.0f, 1.0f, 0.0f,
814             0.0f, 0.0f, 0.0f, 1.0f);
815     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, NULL, NULL, NULL);
816     expect_matrix(&expectedmat, &gotmat, 0);
817 
818     set_matrix(&expectedmat,
819             -0.2148f, 1.3116f, 0.4752f, 0.0f,
820             0.9504f, -0.8836f, 0.9244f, 0.0f,
821             1.0212f, 0.1936f, -1.3588f, 0.0f,
822             18.2985f, -29.624001f, 15.683499f, 1.0f);
823     D3DXMatrixTransformation(&gotmat, NULL, NULL, NULL, &eye, &r, &last);
824     expect_matrix(&expectedmat, &gotmat, 8);
825 
826     set_matrix(&expectedmat,
827             -0.2148f, 1.3116f, 0.4752f, 0.0f,
828             -2.8512f, 2.6508f, -2.7732f, 0.0f,
829             7.148399f, 1.3552f, -9.5116f, 0.0f,
830             9.7f, -8.6f, 1.3f, 1.0f);
831     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, NULL, &r, &last);
832     expect_matrix(&expectedmat, &gotmat, 8);
833 
834     set_matrix(&expectedmat,
835             -0.2148f, 1.3116f, 0.4752f, 0.0f,
836             0.9504f, -0.8836f, 0.9244f, 0.0f,
837             1.0212f, 0.1936f, -1.3588f, 0.0f,
838             9.7f, -8.6f, 1.3f, 1.0f);
839     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, NULL, &r, &last);
840     expect_matrix(&expectedmat, &gotmat, 8);
841 
842     set_matrix(&expectedmat,
843             -0.2148f, 1.3116f, 0.4752f, 0.0f,
844             0.9504f, -0.8836f, 0.9244f, 0.0f,
845             1.0212f, 0.1936f, -1.3588f, 0.0f,
846             9.7f, -8.6f, 1.3f, 1.0f);
847     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, NULL, &r, &last);
848     expect_matrix(&expectedmat, &gotmat, 8);
849 
850     set_matrix(&expectedmat,
851             1.0f, 0.0f, 0.0f, 0.0f,
852             0.0f, -3.0f, 0.0f, 0.0f,
853             0.0f, 0.0f, 7.0f, 0.0f,
854             9.7f, -8.6f, 1.3f, 1.0f);
855     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, &eye, NULL, &last);
856     expect_matrix(&expectedmat, &gotmat, 0);
857 
858     set_matrix(&expectedmat,
859             1.0f, 0.0f, 0.0f, 0.0f,
860             0.0f, 1.0f, 0.0f, 0.0f,
861             0.0f, 0.0f, 1.0f, 0.0f,
862             9.7f, -8.6f, 1.3f, 1.0f);
863     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, &eye, NULL, &last);
864     expect_matrix(&expectedmat, &gotmat, 0);
865 
866     set_matrix(&expectedmat,
867             1.0f, 0.0f, 0.0f, 0.0f,
868             0.0f, 1.0f, 0.0f, 0.0f,
869             0.0f, 0.0f, 1.0f, 0.0f,
870             9.7f, -8.6f, 1.3f, 1.0f);
871     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, &eye, NULL, &last);
872     expect_matrix(&expectedmat, &gotmat, 0);
873 
874     set_matrix(&expectedmat,
875             25521.0f, 39984.0f, 20148.0f, 0.0f,
876             39984.0f, 4933.0f, -3324.0f, 0.0f,
877             20148.0f, -3324.0f, -5153.0f, 0.0f,
878             9.7f, -8.6f, 1.3f, 1.0f);
879     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, &last);
880     expect_matrix(&expectedmat, &gotmat, 0);
881 
882     set_matrix(&expectedmat,
883             1.0f, 0.0f, 0.0f, 0.0f,
884             0.0f, -3.0f, 0.0f, 0.0f,
885             0.0f, 0.0f, 7.0f, 0.0f,
886             9.7f, 43.400002f, 55.299999f, 1.0f);
887     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, NULL, NULL, &last);
888     expect_matrix(&expectedmat, &gotmat, 0);
889 
890     set_matrix(&expectedmat,
891             1.0f, 0.0f, 0.0f, 0.0f,
892             0.0f, 1.0f, 0.0f, 0.0f,
893             0.0f, 0.0f, 1.0f, 0.0f,
894             9.7f, -8.6f, 1.3f, 1.0f);
895     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, NULL, NULL, &last);
896     expect_matrix(&expectedmat, &gotmat, 0);
897 
898     set_matrix(&expectedmat,
899             -0.2148f, 1.3116f, 0.4752f, 0.0f,
900             -2.8512f, 2.6508f, -2.7732f, 0.0f,
901             7.148399f, 1.3552f, -9.5116f, 0.0f,
902             8.5985f, -21.024f, 14.383499, 1.0f);
903     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, &eye, &r, NULL);
904     expect_matrix(&expectedmat, &gotmat, 8);
905 
906     set_matrix(&expectedmat,
907             -0.2148f, 1.3116f, 0.4752f, 0.0f,
908             0.9504f, -0.8836f, 0.9244f, 0.0f,
909             1.0212f, 0.1936f, -1.3588f, 0.0f,
910             8.5985f, -21.024f, 14.383499, 1.0f);
911     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, &eye, &r, NULL);
912     expect_matrix(&expectedmat, &gotmat, 8);
913 
914     set_matrix(&expectedmat,
915             -0.2148f, 1.3116f, 0.4752f, 0.0f,
916             0.9504f, -0.8836f, 0.9244f, 0.0f,
917             1.0212f, 0.1936f, -1.3588f, 0.0f,
918             8.5985f, -21.024f, 14.383499, 1.0f);
919     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, &eye, &r, NULL);
920     expect_matrix(&expectedmat, &gotmat, 8);
921 
922     set_matrix(&expectedmat,
923             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
924             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
925             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
926             0.0f, 0.0f, 0.0f, 1.0f);
927     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, &r, NULL);
928     expect_matrix(&expectedmat, &gotmat, 32);
929 
930     set_matrix(&expectedmat,
931             -0.2148f, 1.3116f, 0.4752f, 0.0f,
932             -2.8512f, 2.6508f, -2.7732f, 0.0f,
933             7.148399f, 1.3552f, -9.5116f, 0.0f,
934             104.565598f, -35.492798f, -25.306400f, 1.0f);
935     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, NULL, &r, NULL);
936     expect_matrix(&expectedmat, &gotmat, 8);
937 
938     set_matrix(&expectedmat,
939             -0.2148f, 1.3116f, 0.4752f, 0.0f,
940             0.9504f, -0.8836f, 0.9244f, 0.0f,
941             1.0212f, 0.1936f, -1.3588f, 0.0f,
942             0.0f, 0.0f, 0.0f, 1.0f);
943     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, NULL, &r, NULL);
944     expect_matrix(&expectedmat, &gotmat, 8);
945 
946     set_matrix(&expectedmat,
947             25521.0f, 39984.0f, 20148.0f, 0.0f,
948             39984.0f, 4933.0f, -3324.0f, 0.0f,
949             20148.0f, -3324.0f, -5153.0f, 0.0f,
950             0.0f, 0.0f, 0.0f, 1.0f);
951     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, &eye, NULL, NULL);
952     expect_matrix(&expectedmat, &gotmat, 0);
953 
954     set_matrix(&expectedmat,
955             1.0f, 0.0f, 0.0f, 0.0f,
956             0.0f, -3.0f, 0.0f, 0.0f,
957             0.0f, 0.0f, 7.0f, 0.0f,
958             0.0f, 52.0f, 54.0f, 1.0f);
959     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, &eye, NULL, NULL);
960     expect_matrix(&expectedmat, &gotmat, 0);
961 
962     set_matrix(&expectedmat,
963             1.0f, 0.0f, 0.0f, 0.0f,
964             0.0f, 1.0f, 0.0f, 0.0f,
965             0.0f, 0.0f, 1.0f, 0.0f,
966             0.0f, 0.0f, 0.0f, 1.0f);
967     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, &eye, NULL, NULL);
968     expect_matrix(&expectedmat, &gotmat, 0);
969 
970     set_matrix(&expectedmat,
971             25521.0f, 39984.0f, 20148.0f, 0.0f,
972             39984.0f, 4933.0f, -3324.0f, 0.0f,
973             20148.0f, -3324.0f, -5153.0f, 0.0f,
974             -287420.0f, -14064.0f, 37122.0f, 1.0f);
975     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, NULL, NULL, NULL);
976     expect_matrix(&expectedmat, &gotmat, 0);
977 
978     set_matrix(&expectedmat,
979             -0.2148f, 1.3116f, 0.4752f, 0.0f,
980             -2.8512f, 2.6508f, -2.7732f, 0.0f,
981             7.148399f, 1.3552f, -9.5116f, 0.0f,
982             18.2985f, -29.624001f, 15.683499f, 1.0f);
983     D3DXMatrixTransformation(&gotmat, NULL, NULL, &axis, &eye, &r, &last);
984     expect_matrix(&expectedmat, &gotmat, 8);
985 
986     set_matrix(&expectedmat,
987             -0.2148f, 1.3116f, 0.4752f, 0.0f,
988             0.9504f, -0.8836f, 0.9244f, 0.0f,
989             1.0212f, 0.1936f, -1.3588f, 0.0f,
990             18.2985f, -29.624001f, 15.683499f, 1.0f);
991     D3DXMatrixTransformation(&gotmat, NULL, &q, NULL, &eye, &r, &last);
992     expect_matrix(&expectedmat, &gotmat, 8);
993 
994     set_matrix(&expectedmat,
995             -0.2148f, 1.3116f, 0.4752f, 0.0f,
996             0.9504f, -0.8836f, 0.9244f, 0.0f,
997             1.0212f, 0.1936f, -1.3588f, 0.0f,
998             18.2985f, -29.624001f, 15.683499f, 1.0f);
999     D3DXMatrixTransformation(&gotmat, &at, NULL, NULL, &eye, &r, &last);
1000     expect_matrix(&expectedmat, &gotmat, 8);
1001 
1002     set_matrix(&expectedmat,
1003             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1004             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1005             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1006             9.7f, -8.6f, 1.3f, 1.0f);
1007     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, &r, &last);
1008     expect_matrix(&expectedmat, &gotmat, 32);
1009 
1010     set_matrix(&expectedmat,
1011             -0.2148f, 1.3116f, 0.4752f, 0.0f,
1012             -2.8512f, 2.6508f, -2.7732f, 0.0f,
1013             7.148399f, 1.3552f, -9.5116f, 0.0f,
1014             114.265594f, -44.092796f, -24.006401f, 1.0f);
1015     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, NULL, &r, &last);
1016     expect_matrix(&expectedmat, &gotmat, 8);
1017 
1018     set_matrix(&expectedmat,
1019             -0.2148f, 1.3116f, 0.4752f, 0.0f,
1020             0.9504f, -0.8836f, 0.9244f, 0.0f,
1021             1.0212f, 0.1936f, -1.3588f, 0.0f,
1022             9.7f, -8.6f, 1.3f, 1.0f);
1023     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, NULL, &r, &last);
1024     expect_matrix(&expectedmat, &gotmat, 8);
1025 
1026     set_matrix(&expectedmat,
1027             25521.0f, 39984.0f, 20148.0f, 0.0f,
1028             39984.0f, 4933.0f, -3324.0f, 0.0f,
1029             20148.0f, -3324.0f, -5153.0f, 0.0f,
1030             9.7f, -8.6f, 1.3f, 1.0f);
1031     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, &eye, NULL, &last);
1032     expect_matrix(&expectedmat, &gotmat, 0);
1033 
1034     set_matrix(&expectedmat,
1035             1.0f, 0.0f, 0.0f, 0.0f,
1036             0.0f, -3.0f, 0.0f, 0.0f,
1037             0.0f, 0.0f, 7.0f, 0.0f,
1038             9.7f, 43.400002f, 55.299999f, 1.0f);
1039     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, &eye, NULL, &last);
1040     expect_matrix(&expectedmat, &gotmat, 0);
1041 
1042     set_matrix(&expectedmat,
1043             1.0f, 0.0f, 0.0f, 0.0f,
1044             0.0f, 1.0f, 0.0f, 0.0f,
1045             0.0f, 0.0f, 1.0f, 0.0f,
1046             9.7f, -8.6f, 1.3f, 1.0f);
1047     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, &eye, NULL, &last);
1048     expect_matrix(&expectedmat, &gotmat, 0);
1049 
1050     set_matrix(&expectedmat,
1051             25521.0f, 39984.0f, 20148.0f, 0.0f,
1052             39984.0f, 4933.0f, -3324.0f, 0.0f,
1053             20148.0f, -3324.0f, -5153.0f, 0.0f,
1054             -287410.3125f, -14072.599609f, 37123.300781f, 1.0f);
1055     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, NULL, NULL, &last);
1056     expect_matrix(&expectedmat, &gotmat, 0);
1057 
1058     set_matrix(&expectedmat,
1059             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1060             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1061             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1062             8.598499f, -21.024f, 14.383499f, 1.0f);
1063     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, &eye, &r, NULL);
1064     expect_matrix(&expectedmat, &gotmat, 32);
1065 
1066     set_matrix(&expectedmat,
1067             -0.2148f, 1.3116f, 0.4752f, 0.0f,
1068             -2.8512f, 2.6508f, -2.7732f, 0.0f,
1069             7.148399f, 1.3552f, -9.5116f, 0.0f,
1070             113.164093f, -56.5168f, -10.922897f, 1.0f);
1071     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, &eye, &r, NULL);
1072     expect_matrix(&expectedmat, &gotmat, 8);
1073 
1074     set_matrix(&expectedmat,
1075             -0.2148f, 1.3116f, 0.4752f, 0.0f,
1076             0.9504f, -0.8836f, 0.9244f, 0.0f,
1077             1.0212f, 0.1936f, -1.3588f, 0.0f,
1078             8.5985f, -21.024f, 14.383499, 1.0f);
1079     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, &eye, &r, NULL);
1080     expect_matrix(&expectedmat, &gotmat, 8);
1081 
1082     set_matrix(&expectedmat,
1083             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1084             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1085             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1086             86280.34375f, -357366.3125f, -200024.125f, 1.0f);
1087     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, NULL, &r, NULL);
1088     expect_matrix(&expectedmat, &gotmat, 32);
1089 
1090     set_matrix(&expectedmat,
1091             25521.0f, 39984.0f, 20148.0f, 0.0f,
1092             39984.0f, 4933.0f, -3324.0f, 0.0f,
1093             20148.0f, -3324.0f, -5153.0f, 0.0f,
1094             -287410.3125f, -14064.0f, 37122.0f, 1.0f);
1095     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, &eye, NULL, NULL);
1096     expect_matrix(&expectedmat, &gotmat, 512);
1097 
1098     set_matrix(&expectedmat,
1099             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1100             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1101             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1102             86280.34375f, -357366.3125f, -200009.75f, 1.0f);
1103     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, &eye, &r, NULL);
1104     expect_matrix(&expectedmat, &gotmat, 2048);
1105 
1106     set_matrix(&expectedmat,
1107             25521.0f, 39984.0f, 20148.0f, 0.0f,
1108             39984.0f, 4933.0f, -3324.0f, 0.0f,
1109             20148.0f, -3324.0f, -5153.0f, 0.0f,
1110             -287410.3125f, -14072.599609f, 37123.300781f, 1.0f);
1111     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, &eye, NULL, &last);
1112     expect_matrix(&expectedmat, &gotmat, 0);
1113 
1114     set_matrix(&expectedmat,
1115             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1116             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1117             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1118             86290.046875f, -357374.90625f, -200022.828125f, 1.0f);
1119     D3DXMatrixTransformation(&gotmat, &at, &q, &axis, NULL, &r, &last);
1120     expect_matrix(&expectedmat, &gotmat, 32);
1121 
1122     set_matrix(&expectedmat,
1123             -0.21480007f, 1.3116000f, 0.47520003f, 0.0f,
1124             0.95040143f, -0.88360137f, 0.92439979f, 0.0f,
1125             1.0212044f, 0.19359307f, -1.3588026f, 0.0f,
1126             18.298532f, -29.624001f, 15.683499f, 1.0f);
1127     D3DXMatrixTransformation(&gotmat, &at, &q, NULL, &eye, &r, &last);
1128     expect_matrix(&expectedmat, &gotmat, 512);
1129 
1130     set_matrix(&expectedmat,
1131             -0.2148f, 1.3116f, 0.4752f, 0.0f,
1132             -2.8512f, 2.6508f, -2.7732f, 0.0f,
1133             7.148399f, 1.3552f, -9.5116f, 0.0f,
1134             122.86409f, -65.116798f, -9.622897f, 1.0f);
1135     D3DXMatrixTransformation(&gotmat, &at, NULL, &axis, &eye, &r, &last);
1136     expect_matrix(&expectedmat, &gotmat, 8);
1137 
1138     set_matrix(&expectedmat,
1139             53094.015625f, 2044.133789f, 21711.687500f, 0.0f,
1140             -7294.705078f, 47440.683594f, 28077.113281, 0.0f,
1141             -12749.161133f, 28365.580078f, 13503.520508f, 0.0f,
1142             18.2985f, -29.624001f, 15.683499f, 1.0f);
1143     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, &eye, &r, &last);
1144     expect_matrix(&expectedmat, &gotmat, 32);
1145 
1146     q.x = 1.0f, q.y = 1.0f, q.z = 1.0f, q.w = 1.0f,
1147     axis.x = 1.0f, axis.y = 1.0f, axis.z = 2.0f,
1148 
1149     set_matrix(&expectedmat,
1150             41.0f, -12.0f, -24.0f, 0.0f,
1151             -12.0f, 25.0f, -12.0f, 0.0f,
1152             -24.0f, -12.0f, 34.0f, 0.0f,
1153             0.0f, 0.0f, 0.0f, 1.0f);
1154     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1155     expect_matrix(&expectedmat, &gotmat, 0);
1156 
1157     q.x = 1.0f, q.y = 1.0f, q.z = 1.0f, q.w = 1.0f,
1158     axis.x = 1.0f, axis.y = 1.0f, axis.z = 3.0f,
1159 
1160     set_matrix(&expectedmat,
1161             57.0f, -12.0f, -36.0f, 0.0f,
1162             -12.0f, 25.0f, -12.0f, 0.0f,
1163             -36.0f, -12.0f, 43.0f, 0.0f,
1164             0.0f, 0.0f, 0.0f, 1.0f);
1165     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1166     expect_matrix(&expectedmat, &gotmat, 0);
1167 
1168     q.x = 1.0f, q.y = 1.0f, q.z = 1.0f, q.w = 0.0f,
1169     axis.x = 1.0f, axis.y = 1.0f, axis.z = 3.0f,
1170 
1171     set_matrix(&expectedmat,
1172             25.0f, 0.0f, -20.0f, 0.0f,
1173             0.0f, 25.0f, -20.0f, 0.0f,
1174             -20.0f, -20.0f, 35.0f, 0.0f,
1175             0.0f, 0.0f, 0.0f, 1.0f);
1176     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1177     expect_matrix(&expectedmat, &gotmat, 0);
1178 
1179     q.x = 1.0f, q.y = 1.0f, q.z = 0.0f, q.w = 0.0f,
1180     axis.x = 1.0f, axis.y = 1.0f, axis.z = 3.0f,
1181 
1182     set_matrix(&expectedmat,
1183             5.0f, -4.0f, 0.0f, 0.0f,
1184             -4.0f, 5.0f, 0.0f, 0.0f,
1185             0.0f, 0.0f, 27.0f, 0.0f,
1186             0.0f, 0.0f, 0.0f, 1.0f);
1187     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1188     expect_matrix(&expectedmat, &gotmat, 0);
1189 
1190     q.x = 1.0f, q.y = 0.0f, q.z = 0.0f, q.w = 0.0f,
1191     axis.x = 5.0f, axis.y = 2.0f, axis.z = 1.0f,
1192 
1193     set_matrix(&expectedmat,
1194             5.0f, 0.0f, 0.0f, 0.0f,
1195             0.0f, 2.0f, 0.0f, 0.0f,
1196             0.0f, 0.0f, 1.0f, 0.0f,
1197             0.0f, 0.0f, 0.0f, 1.0f);
1198     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1199     expect_matrix(&expectedmat, &gotmat, 0);
1200 
1201     q.x = 1.0f, q.y = 0.0f, q.z = 0.0f, q.w = 0.0f,
1202     axis.x = 1.0f, axis.y = 4.0f, axis.z = 1.0f,
1203 
1204     set_matrix(&expectedmat,
1205             1.0f, 0.0f, 0.0f, 0.0f,
1206             0.0f, 4.0f, 0.0f, 0.0f,
1207             0.0f, 0.0f, 1.0f, 0.0f,
1208             0.0f, 0.0f, 0.0f, 1.0f);
1209     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1210     expect_matrix(&expectedmat, &gotmat, 0);
1211 
1212     q.x = 0.0f, q.y = 1.0f, q.z = 0.0f, q.w = 0.0f,
1213     axis.x = 1.0f, axis.y = 4.0f, axis.z = 1.0f,
1214 
1215     set_matrix(&expectedmat,
1216             1.0f, 0.0f, 0.0f, 0.0f,
1217             0.0f, 4.0f, 0.0f, 0.0f,
1218             0.0f, 0.0f, 1.0f, 0.0f,
1219             0.0f, 0.0f, 0.0f, 1.0f);
1220     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1221     expect_matrix(&expectedmat, &gotmat, 0);
1222 
1223     q.x = 1.0f, q.y = 0.0f, q.z = 0.0f, q.w = 1.0f,
1224     axis.x = 1.0f, axis.y = 4.0f, axis.z = 1.0f,
1225 
1226     set_matrix(&expectedmat,
1227             1.0f, 0.0f, 0.0f, 0.0f,
1228             0.0f, 8.0f, -6.0f, 0.0f,
1229             0.0f, -6.0f, 17.0f, 0.0f,
1230             0.0f, 0.0f, 0.0f, 1.0f);
1231     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1232     expect_matrix(&expectedmat, &gotmat, 0);
1233 
1234     q.x = 1.0f, q.y = 0.0f, q.z = 0.0f, q.w = 1.0f,
1235     axis.x = 0.0f, axis.y = 4.0f, axis.z = 0.0f,
1236 
1237     set_matrix(&expectedmat,
1238             0.0f, 0.0f, 0.0f, 0.0f,
1239             0.0f, 4.0f, -8.0f, 0.0f,
1240             0.0f, -8.0f, 16.0f, 0.0f,
1241             0.0f, 0.0f, 0.0f, 1.0f);
1242     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1243     expect_matrix(&expectedmat, &gotmat, 0);
1244 
1245     q.x = 0.0f, q.y = 1.0f, q.z = 0.0f, q.w = 1.0f,
1246     axis.x = 1.0f, axis.y = 4.0f, axis.z = 1.0f,
1247 
1248     set_matrix(&expectedmat,
1249             5.0f, 0.0f, 0.0f, 0.0f,
1250             0.0f, 4.0f, 0.0f, 0.0f,
1251             0.0f, 0.0f, 5.0f, 0.0f,
1252             0.0f, 0.0f, 0.0f, 1.0f);
1253     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1254     expect_matrix(&expectedmat, &gotmat, 0);
1255 
1256     q.x = 1.0f, q.y = 0.0f, q.z = 0.0f, q.w = 0.0f,
1257     axis.x = 1.0f, axis.y = 1.0f, axis.z = 3.0f,
1258 
1259     set_matrix(&expectedmat,
1260             1.0f, 0.0f, 0.0f, 0.0f,
1261             0.0f, 1.0f, 0.0f, 0.0f,
1262             0.0f, 0.0f, 3.0f, 0.0f,
1263             0.0f, 0.0f, 0.0f, 1.0f);
1264     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1265     expect_matrix(&expectedmat, &gotmat, 0);
1266 
1267     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1268     axis.x = 3.0f, axis.y = 3.0f, axis.z = 3.0f,
1269 
1270     set_matrix(&expectedmat,
1271             3796587.0f, -1377948.0f, -1589940.0f, 0.0f,
1272             -1377948.0f, 3334059.0f, -1879020.0f, 0.0f,
1273             -1589940.0f, -1879020.0f, 2794443.0f, 0.0f,
1274             0.0f, 0.0f, 0.0f, 1.0f);
1275     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1276     expect_matrix(&expectedmat, &gotmat, 0);
1277 
1278     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1279     axis.x = 1.0f, axis.y = 1.0f, axis.z = 1.0f,
1280 
1281     set_matrix(&expectedmat,
1282             1265529.0f, -459316.0f, -529980.0f, 0.0f,
1283             -459316.0f, 1111353.0f, -626340.0f, 0.0f,
1284             -529980.0f, -626340.0f, 931481.0f, 0.0f,
1285             0.0f, 0.0f, 0.0f, 1.0f);
1286     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1287     expect_matrix(&expectedmat, &gotmat, 0);
1288 
1289     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1290     axis.x = 1.0f, axis.y = 1.0f, axis.z = 3.0f,
1291 
1292     set_matrix(&expectedmat,
1293             2457497.0f, -434612.0f, -1423956.0f, 0.0f,
1294             -434612.0f, 1111865.0f, -644868.0f, 0.0f,
1295             -1423956.0f, -644868.0f, 1601963.0f, 0.0f,
1296             0.0f, 0.0f, 0.0f, 1.0f);
1297     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1298     expect_matrix(&expectedmat, &gotmat, 0);
1299 
1300     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1301     axis.x = 0.0f, axis.y = 0.0f, axis.z = 3.0f,
1302 
1303     set_matrix(&expectedmat,
1304             1787952.0f, 37056.0f, -1340964.0f, 0.0f,
1305             37056.0f, 768.0f, -27792.0f, 0.0f,
1306             -1340964.0f, -27792.0f, 1005723.0f, 0.0f,
1307             0.0f, 0.0f, 0.0f, 1.0f);
1308     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1309     expect_matrix(&expectedmat, &gotmat, 0);
1310 
1311     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1312     axis.x = 0.0f, axis.y = 0.0f, axis.z = 1.0f,
1313 
1314     set_matrix(&expectedmat,
1315             595984.0f, 12352.0f, -446988.0f, 0.0f,
1316             12352.0f, 256.0f, -9264.0f, 0.0f,
1317             -446988.0f, -9264.0f, 335241.0f, 0.0f,
1318             0.0f, 0.0f, 0.0f, 1.0f);
1319     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1320     expect_matrix(&expectedmat, &gotmat, 0);
1321 
1322     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1323     axis.x = 0.0f, axis.y = 3.0f, axis.z = 0.0f,
1324 
1325     set_matrix(&expectedmat,
1326             150528.0f, 464352.0f, -513408.0f, 0.0f,
1327             464352.0f, 1432443.0f, -1583772.0f, 0.0f,
1328             -513408.0f, -1583772.0f, 1751088.0f, 0.0f,
1329             0.0f, 0.0f, 0.0f, 1.0f);
1330     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1331     expect_matrix(&expectedmat, &gotmat, 0);
1332 
1333     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1334     axis.x = 0.0f, axis.y = 1.0f, axis.z = 0.0f,
1335 
1336     set_matrix(&expectedmat,
1337             50176.0f, 154784.0f, -171136.0f, 0.0f,
1338             154784.0f, 477481.0f, -527924.0f, 0.0f,
1339             -171136.0f, -527924.0f, 583696.0f, 0.0f,
1340             0.0f, 0.0f, 0.0f, 1.0f);
1341     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1342     expect_matrix(&expectedmat, &gotmat, 0);
1343 
1344     q.x = 11.0f, q.y = 13.0f, q.z = 15.0f, q.w = 17.0f,
1345     axis.x = 1.0f, axis.y = 0.0f, axis.z = 0.0f,
1346 
1347     set_matrix(&expectedmat,
1348             619369.0f, -626452.0f, 88144.0f, 0.0f,
1349             -626452.0f, 633616.0f, -89152.0f, 0.0f,
1350             88144.0f, -89152, 12544.0f, 0.0f,
1351             0.0f, 0.0f, 0.0f, 1.0f);
1352     D3DXMatrixTransformation(&gotmat, NULL, &q, &axis, NULL, NULL, NULL);
1353     expect_matrix(&expectedmat, &gotmat, 0);
1354 
1355 /*____________D3DXMatrixTranslation______________*/
1356     set_matrix(&expectedmat,
1357             1.0f, 0.0f, 0.0f, 0.0f,
1358             0.0f, 1.0f, 0.0f, 0.0f,
1359             0.0f, 0.0f, 1.0f, 0.0f,
1360             0.69f, 0.53f, 4.11f, 1.0f);
1361     D3DXMatrixTranslation(&gotmat, 0.69f, 0.53f, 4.11f);
1362     expect_matrix(&expectedmat, &gotmat, 0);
1363 
1364 /*____________D3DXMatrixTranspose______________*/
1365     set_matrix(&expectedmat,
1366             10.0f, 11.0f, 19.0f, 2.0f,
1367             5.0f, 20.0f, -21.0f, 3.0f,
1368             7.0f, 16.0f, 30.f, -4.0f,
1369             8.0f, 33.0f, 43.0f, -40.0f);
1370     D3DXMatrixTranspose(&gotmat, &mat);
1371     expect_matrix(&expectedmat, &gotmat, 0);
1372 }
1373 
1374 static void D3DXPlaneTest(void)
1375 {
1376     D3DXMATRIX mat;
1377     D3DXPLANE expectedplane, gotplane, nulplane, plane;
1378     D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
1379     LPD3DXVECTOR3 funcpointer;
1380     D3DXVECTOR4 vec;
1381     FLOAT expected, got;
1382 
1383     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1384     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1385     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1386     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1387     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
1388     U(mat).m[3][3] = -40.0f;
1389 
1390     plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
1391 
1392     vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
1393 
1394 /*_______________D3DXPlaneDot________________*/
1395     expected = 42.0f;
1396     got = D3DXPlaneDot(&plane,&vec),
1397     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1398     expected = 0.0f;
1399     got = D3DXPlaneDot(NULL,&vec),
1400     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1401     expected = 0.0f;
1402     got = D3DXPlaneDot(NULL,NULL),
1403     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1404 
1405 /*_______________D3DXPlaneDotCoord________________*/
1406     expected = -28.0f;
1407     got = D3DXPlaneDotCoord(&plane,&vec),
1408     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1409     expected = 0.0f;
1410     got = D3DXPlaneDotCoord(NULL,&vec),
1411     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1412     expected = 0.0f;
1413     got = D3DXPlaneDotCoord(NULL,NULL),
1414     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1415 
1416 /*_______________D3DXPlaneDotNormal______________*/
1417     expected = -35.0f;
1418     got = D3DXPlaneDotNormal(&plane,&vec),
1419     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1420     expected = 0.0f;
1421     got = D3DXPlaneDotNormal(NULL,&vec),
1422     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1423     expected = 0.0f;
1424     got = D3DXPlaneDotNormal(NULL,NULL),
1425     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
1426 
1427 /*_______________D3DXPlaneFromPointNormal_______*/
1428     vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
1429     vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
1430     expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
1431     D3DXPlaneFromPointNormal(&gotplane, &vec1, &vec2);
1432     expect_plane(&expectedplane, &gotplane, 0);
1433     gotplane.a = vec2.x; gotplane.b = vec2.y; gotplane.c = vec2.z;
1434     D3DXPlaneFromPointNormal(&gotplane, &vec1, (D3DXVECTOR3 *)&gotplane);
1435     expect_plane(&expectedplane, &gotplane, 0);
1436     gotplane.a = vec1.x; gotplane.b = vec1.y; gotplane.c = vec1.z;
1437     expectedplane.d = -1826.0f;
1438     D3DXPlaneFromPointNormal(&gotplane, (D3DXVECTOR3 *)&gotplane, &vec2);
1439     expect_plane(&expectedplane, &gotplane, 0);
1440 
1441 /*_______________D3DXPlaneFromPoints_______*/
1442     vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
1443     vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
1444     vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
1445     expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
1446     D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
1447     expect_plane(&expectedplane, &gotplane, 64);
1448 
1449 /*_______________D3DXPlaneIntersectLine___________*/
1450     vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
1451     vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
1452     expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
1453     D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
1454     expect_vec3(&expectedvec, &gotvec, 1);
1455     /* Test a parallel line */
1456     vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
1457     vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
1458     expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
1459     funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
1460     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1461 
1462 /*_______________D3DXPlaneNormalize______________*/
1463     expectedplane.a = -3.0f/sqrt(26.0f); expectedplane.b = -1.0f/sqrt(26.0f); expectedplane.c = 4.0f/sqrt(26.0f); expectedplane.d = 7.0/sqrt(26.0f);
1464     D3DXPlaneNormalize(&gotplane, &plane);
1465     expect_plane(&expectedplane, &gotplane, 2);
1466     nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
1467     expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
1468     D3DXPlaneNormalize(&gotplane, &nulplane);
1469     expect_plane(&expectedplane, &gotplane, 0);
1470 
1471 /*_______________D3DXPlaneTransform____________*/
1472     expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
1473     D3DXPlaneTransform(&gotplane,&plane,&mat);
1474     expect_plane(&expectedplane, &gotplane, 0);
1475 }
1476 
1477 static void D3DXQuaternionTest(void)
1478 {
1479     D3DXMATRIX mat;
1480     D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
1481     BOOL expectedbool, gotbool, equal;
1482     float angle, got, scale, scale2;
1483     LPD3DXQUATERNION funcpointer;
1484     D3DXVECTOR3 axis, expectedvec;
1485 
1486     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
1487     q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
1488     r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
1489     t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
1490     u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
1491     smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
1492     smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallr.w = 0.8f;
1493 
1494     scale = 0.3f;
1495     scale2 = 0.78f;
1496 
1497 /*_______________D3DXQuaternionBaryCentric________________________*/
1498     expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
1499     D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
1500     expect_quaternion(&expectedquat, &gotquat, 1);
1501 
1502 /*_______________D3DXQuaternionConjugate________________*/
1503     expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
1504     D3DXQuaternionConjugate(&gotquat,&q);
1505     expect_quaternion(&expectedquat, &gotquat, 0);
1506     /* Test the NULL case */
1507     funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
1508     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1509     funcpointer = D3DXQuaternionConjugate(NULL,NULL);
1510     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1511 
1512 /*_______________D3DXQuaternionDot______________________*/
1513     got = D3DXQuaternionDot(&q,&r);
1514     equal = compare_float(got, 55.0f, 0);
1515     ok(equal, "Got unexpected dot %.8e.\n", got);
1516     /* Tests the case NULL */
1517     got = D3DXQuaternionDot(NULL,&r);
1518     equal = compare_float(got, 0.0f, 0);
1519     ok(equal, "Got unexpected dot %.8e.\n", got);
1520     got = D3DXQuaternionDot(NULL,NULL);
1521     equal = compare_float(got, 0.0f, 0);
1522     ok(equal, "Got unexpected dot %.8e.\n", got);
1523 
1524 /*_______________D3DXQuaternionExp______________________________*/
1525     expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
1526     D3DXQuaternionExp(&gotquat,&q);
1527     expect_quaternion(&expectedquat, &gotquat, 16);
1528     /* Test the null quaternion */
1529     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
1530     D3DXQuaternionExp(&gotquat,&nul);
1531     expect_quaternion(&expectedquat, &gotquat, 0);
1532     /* Test the case where the norm of the quaternion is <1 */
1533     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
1534     expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
1535     D3DXQuaternionExp(&gotquat,&Nq1);
1536     expect_quaternion(&expectedquat, &gotquat, 8);
1537 
1538 /*_______________D3DXQuaternionIdentity________________*/
1539     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
1540     D3DXQuaternionIdentity(&gotquat);
1541     expect_quaternion(&expectedquat, &gotquat, 0);
1542     /* Test the NULL case */
1543     funcpointer = D3DXQuaternionIdentity(NULL);
1544     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1545 
1546 /*_______________D3DXQuaternionInverse________________________*/
1547     expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
1548     D3DXQuaternionInverse(&gotquat,&q);
1549     expect_quaternion(&expectedquat, &gotquat, 0);
1550 
1551     expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 10.0f;
1552     D3DXQuaternionInverse(&gotquat,&gotquat);
1553     expect_quaternion(&expectedquat, &gotquat, 1);
1554 
1555 
1556 /*_______________D3DXQuaternionIsIdentity________________*/
1557     s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
1558     expectedbool = TRUE;
1559     gotbool = D3DXQuaternionIsIdentity(&s);
1560     ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
1561     s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
1562     expectedbool = FALSE;
1563     gotbool = D3DXQuaternionIsIdentity(&q);
1564     ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
1565     /* Test the NULL case */
1566     gotbool = D3DXQuaternionIsIdentity(NULL);
1567     ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
1568 
1569 /*_______________D3DXQuaternionLength__________________________*/
1570     got = D3DXQuaternionLength(&q);
1571     equal = compare_float(got, 11.0f, 0);
1572     ok(equal, "Got unexpected length %.8e.\n", got);
1573     /* Tests the case NULL. */
1574     got = D3DXQuaternionLength(NULL);
1575     equal = compare_float(got, 0.0f, 0);
1576     ok(equal, "Got unexpected length %.8e.\n", got);
1577 
1578 /*_______________D3DXQuaternionLengthSq________________________*/
1579     got = D3DXQuaternionLengthSq(&q);
1580     equal = compare_float(got, 121.0f, 0);
1581     ok(equal, "Got unexpected length %.8e.\n", got);
1582     /* Tests the case NULL */
1583     got = D3DXQuaternionLengthSq(NULL);
1584     equal = compare_float(got, 0.0f, 0);
1585     ok(equal, "Got unexpected length %.8e.\n", got);
1586 
1587 /*_______________D3DXQuaternionLn______________________________*/
1588     expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
1589     D3DXQuaternionLn(&gotquat,&q);
1590     expect_quaternion(&expectedquat, &gotquat, 0);
1591     expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
1592     D3DXQuaternionLn(&gotquat,&r);
1593     expect_quaternion(&expectedquat, &gotquat, 0);
1594     Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
1595     expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
1596     D3DXQuaternionLn(&gotquat,&Nq);
1597     expect_quaternion(&expectedquat, &gotquat, 32);
1598     Nq.x = 0.0f; Nq.y = 0.0f; Nq.z = 0.0f; Nq.w = 1.0f;
1599     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1600     D3DXQuaternionLn(&gotquat,&Nq);
1601     expect_quaternion(&expectedquat, &gotquat, 0);
1602     Nq.x = 5.4f; Nq.y = 1.2f; Nq.z = -0.3f; Nq.w = -0.3f;
1603     expectedquat.x = 10.616652f; expectedquat.y = 2.359256f; expectedquat.z = -0.589814f; expectedquat.w = 0.0f;
1604     D3DXQuaternionLn(&gotquat,&Nq);
1605     expect_quaternion(&expectedquat, &gotquat, 1);
1606     /* Test the case where the norm of the quaternion is <1 */
1607     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = 0.9f;
1608     expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
1609     D3DXQuaternionLn(&gotquat,&Nq1);
1610     expect_quaternion(&expectedquat, &gotquat, 64);
1611     /* Test the case where the real part of the quaternion is -1.0f */
1612     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = -1.0f;
1613     expectedquat.x = 0.2f; expectedquat.y = 0.1f; expectedquat.z = 0.3f; expectedquat.w = 0.0f;
1614     D3DXQuaternionLn(&gotquat,&Nq1);
1615     expect_quaternion(&expectedquat, &gotquat, 0);
1616 
1617 /*_______________D3DXQuaternionMultiply________________________*/
1618     expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
1619     D3DXQuaternionMultiply(&gotquat,&q,&r);
1620     expect_quaternion(&expectedquat, &gotquat, 0);
1621 
1622 /*_______________D3DXQuaternionNormalize________________________*/
1623     expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
1624     D3DXQuaternionNormalize(&gotquat,&q);
1625     expect_quaternion(&expectedquat, &gotquat, 1);
1626 
1627 /*_______________D3DXQuaternionRotationAxis___________________*/
1628     axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
1629     angle = D3DX_PI/3.0f;
1630     expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
1631     D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
1632     expect_quaternion(&expectedquat, &gotquat, 64);
1633  /* Test the nul quaternion */
1634     axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
1635     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
1636     D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
1637     expect_quaternion(&expectedquat, &gotquat, 8);
1638 
1639 /*_______________D3DXQuaternionRotationMatrix___________________*/
1640     /* test when the trace is >0 */
1641     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1642     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1643     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1644     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1645     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
1646     U(mat).m[3][3] = 48.0f;
1647     expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
1648     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1649     expect_quaternion(&expectedquat, &gotquat, 16);
1650     /* test the case when the greater element is (2,2) */
1651     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1652     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1653     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1654     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1655     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
1656     U(mat).m[3][3] = 48.0f;
1657     expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
1658     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1659     expect_quaternion(&expectedquat, &gotquat, 64);
1660     /* test the case when the greater element is (1,1) */
1661     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1662     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1663     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1664     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1665     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
1666     U(mat).m[3][3] = 48.0f;
1667     expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
1668     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1669     expect_quaternion(&expectedquat, &gotquat, 8);
1670     /* test the case when the trace is near 0 in a matrix which is not a rotation */
1671     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1672     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1673     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1674     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1675     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
1676     U(mat).m[3][3] = 48.0f;
1677     expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
1678     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1679     expect_quaternion(&expectedquat, &gotquat, 8);
1680     /* test the case when the trace is 0.49 in a matrix which is not a rotation */
1681     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1682     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1683     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1684     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1685     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
1686     U(mat).m[3][3] = 48.0f;
1687     expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
1688     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1689     expect_quaternion(&expectedquat, &gotquat, 8);
1690     /* test the case when the trace is 0.51 in a matrix which is not a rotation */
1691     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1692     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1693     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1694     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1695     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
1696     U(mat).m[3][3] = 48.0f;
1697     expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
1698     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1699     expect_quaternion(&expectedquat, &gotquat, 8);
1700     /* test the case when the trace is 0.99 in a matrix which is not a rotation */
1701     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1702     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1703     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1704     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1705     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
1706     U(mat).m[3][3] = 48.0f;
1707     expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
1708     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1709     expect_quaternion(&expectedquat, &gotquat, 4);
1710     /* test the case when the trace is 1.0 in a matrix which is not a rotation */
1711     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1712     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1713     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1714     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1715     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
1716     U(mat).m[3][3] = 48.0f;
1717     expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
1718     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1719     expect_quaternion(&expectedquat, &gotquat, 8);
1720     /* test the case when the trace is 1.01 in a matrix which is not a rotation */
1721     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1722     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1723     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1724     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1725     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
1726     U(mat).m[3][3] = 48.0f;
1727     expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
1728     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1729     expect_quaternion(&expectedquat, &gotquat, 4);
1730     /* test the case when the trace is 1.5 in a matrix which is not a rotation */
1731     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1732     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1733     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1734     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1735     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
1736     U(mat).m[3][3] = 48.0f;
1737     expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
1738     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1739     expect_quaternion(&expectedquat, &gotquat, 8);
1740     /* test the case when the trace is 1.7 in a matrix which is not a rotation */
1741     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1742     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1743     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1744     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1745     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
1746     U(mat).m[3][3] = 48.0f;
1747     expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
1748     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1749     expect_quaternion(&expectedquat, &gotquat, 4);
1750     /* test the case when the trace is 1.99 in a matrix which is not a rotation */
1751     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1752     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1753     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1754     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1755     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
1756     U(mat).m[3][3] = 48.0f;
1757     expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
1758     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1759     expect_quaternion(&expectedquat, &gotquat, 4);
1760     /* test the case when the trace is 2.0 in a matrix which is not a rotation */
1761     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1762     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1763     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1764     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1765     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
1766     U(mat).m[3][3] = 48.0f;
1767     expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
1768     D3DXQuaternionRotationMatrix(&gotquat,&mat);
1769     expect_quaternion(&expectedquat, &gotquat, 8);
1770 
1771 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
1772     expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
1773     D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
1774     expect_quaternion(&expectedquat, &gotquat, 16);
1775 
1776 /*_______________D3DXQuaternionSlerp________________________*/
1777     expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
1778     D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
1779     expect_quaternion(&expectedquat, &gotquat, 4);
1780     expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
1781     D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
1782     expect_quaternion(&expectedquat, &gotquat, 2);
1783     expectedquat.x = 0.239485f; expectedquat.y = 0.346580f; expectedquat.z = 0.453676f; expectedquat.w = 0.560772f;
1784     D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
1785     expect_quaternion(&expectedquat, &gotquat, 32);
1786 
1787 /*_______________D3DXQuaternionSquad________________________*/
1788     expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
1789     D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
1790     expect_quaternion(&expectedquat, &gotquat, 2);
1791 
1792 /*_______________D3DXQuaternionSquadSetup___________________*/
1793     r.x = 1.0f, r.y = 2.0f; r.z = 4.0f; r.w = 10.0f;
1794     s.x = -3.0f; s.y = 4.0f; s.z = -5.0f; s.w = 7.0;
1795     t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
1796     u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
1797     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1798     expectedquat.x = 7.121285f; expectedquat.y = 2.159964f; expectedquat.z = -3.855094f; expectedquat.w = 5.362844f;
1799     expect_quaternion(&expectedquat, &gotquat, 2);
1800     expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
1801     expect_quaternion(&expectedquat, &Nq, 4);
1802     expectedquat.x = -1111.0f; expectedquat.y = 111.0f; expectedquat.z = -11.0f; expectedquat.w = 1.0f;
1803     expect_quaternion(&expectedquat, &Nq1, 0);
1804     gotquat = s;
1805     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &gotquat, &t, &u);
1806     expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
1807     expect_quaternion(&expectedquat, &Nq, 4);
1808     Nq1 = u;
1809     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &Nq1);
1810     expect_quaternion(&expectedquat, &Nq, 4);
1811     r.x = 0.2f; r.y = 0.3f; r.z = 1.3f; r.w = -0.6f;
1812     s.x = -3.0f; s.y =-2.0f; s.z = 4.0f; s.w = 0.2f;
1813     t.x = 0.4f; t.y = 8.3f; t.z = -3.1f; t.w = -2.7f;
1814     u.x = 1.1f; u.y = -0.7f; u.z = 9.2f; u.w = 0.0f;
1815     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &u, &t);
1816     expectedquat.x = -4.139569f; expectedquat.y = -2.469115f; expectedquat.z = 2.364477f; expectedquat.w = 0.465494f;
1817     expect_quaternion(&expectedquat, &gotquat, 16);
1818     expectedquat.x = 2.342533f; expectedquat.y = 2.365127f; expectedquat.z = 8.628538f; expectedquat.w = -0.898356f;
1819     expect_quaternion(&expectedquat, &Nq, 16);
1820     expectedquat.x = 1.1f; expectedquat.y = -0.7f; expectedquat.z = 9.2f; expectedquat.w = 0.0f;
1821     expect_quaternion(&expectedquat, &Nq1, 0);
1822     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1823     expectedquat.x = -3.754567f; expectedquat.y = -0.586085f; expectedquat.z = 3.815818f; expectedquat.w = -0.198150f;
1824     expect_quaternion(&expectedquat, &gotquat, 32);
1825     expectedquat.x = 0.140773f; expectedquat.y = -8.737090f; expectedquat.z = -0.516593f; expectedquat.w = 3.053942f;
1826     expect_quaternion(&expectedquat, &Nq, 16);
1827     expectedquat.x = -0.4f; expectedquat.y = -8.3f; expectedquat.z = 3.1f; expectedquat.w = 2.7f;
1828     expect_quaternion(&expectedquat, &Nq1, 0);
1829     r.x = -1.0f; r.y = 0.0f; r.z = 0.0f; r.w = 0.0f;
1830     s.x = 1.0f; s.y =0.0f; s.z = 0.0f; s.w = 0.0f;
1831     t.x = 1.0f; t.y = 0.0f; t.z = 0.0f; t.w = 0.0f;
1832     u.x = -1.0f; u.y = 0.0f; u.z = 0.0f; u.w = 0.0f;
1833     D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1834     expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1835     expect_quaternion(&expectedquat, &gotquat, 0);
1836     expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1837     expect_quaternion(&expectedquat, &Nq, 0);
1838     expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1839     expect_quaternion(&expectedquat, &Nq1, 0);
1840 
1841 /*_______________D3DXQuaternionToAxisAngle__________________*/
1842     Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
1843     expectedvec.x = 1.0f/22.0f; expectedvec.y = 2.0f/22.0f; expectedvec.z = 4.0f/22.0f;
1844     D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
1845     expect_vec3(&expectedvec, &axis, 0);
1846     equal = compare_float(angle, 2.197869f, 1);
1847     ok(equal, "Got unexpected angle %.8e.\n", angle);
1848     /* Test if |w|>1.0f */
1849     expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f;
1850     D3DXQuaternionToAxisAngle(&q,&axis,&angle);
1851     expect_vec3(&expectedvec, &axis, 0);
1852     /* Test the null quaternion */
1853     expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1854     D3DXQuaternionToAxisAngle(&nul, &axis, &angle);
1855     expect_vec3(&expectedvec, &axis, 0);
1856     equal = compare_float(angle, 3.14159274e+00f, 0);
1857     ok(equal, "Got unexpected angle %.8e.\n", angle);
1858 
1859     D3DXQuaternionToAxisAngle(&nul, &axis, NULL);
1860     D3DXQuaternionToAxisAngle(&nul, NULL, &angle);
1861     expect_vec3(&expectedvec, &axis, 0);
1862     equal = compare_float(angle, 3.14159274e+00f, 0);
1863     ok(equal, "Got unexpected angle %.8e.\n", angle);
1864 }
1865 
1866 static void D3DXVector2Test(void)
1867 {
1868     D3DXVECTOR2 expectedvec, gotvec, nul, u, v, w, x;
1869     LPD3DXVECTOR2 funcpointer;
1870     D3DXVECTOR4 expectedtrans, gottrans;
1871     float coeff1, coeff2, got, scale;
1872     D3DXMATRIX mat;
1873     BOOL equal;
1874 
1875     nul.x = 0.0f; nul.y = 0.0f;
1876     u.x = 3.0f; u.y = 4.0f;
1877     v.x = -7.0f; v.y = 9.0f;
1878     w.x = 4.0f; w.y = -3.0f;
1879     x.x = 2.0f; x.y = -11.0f;
1880 
1881     set_matrix(&mat,
1882             1.0f, 2.0f, 3.0f, 4.0f,
1883             5.0f, 6.0f, 7.0f, 8.0f,
1884             9.0f, 10.0f, 11.0f, 12.0f,
1885             13.0f, 14.0f, 15.0f, 16.0f);
1886 
1887     coeff1 = 2.0f; coeff2 = 5.0f;
1888     scale = -6.5f;
1889 
1890 /*_______________D3DXVec2Add__________________________*/
1891     expectedvec.x = -4.0f; expectedvec.y = 13.0f;
1892     D3DXVec2Add(&gotvec,&u,&v);
1893     expect_vec2(&expectedvec, &gotvec, 0);
1894     /* Tests the case NULL */
1895     funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
1896     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1897     funcpointer = D3DXVec2Add(NULL,NULL,NULL);
1898     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1899 
1900 /*_______________D3DXVec2BaryCentric___________________*/
1901     expectedvec.x = -12.0f; expectedvec.y = -21.0f;
1902     D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1903     expect_vec2(&expectedvec, &gotvec, 0);
1904 
1905 /*_______________D3DXVec2CatmullRom____________________*/
1906     expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
1907     D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1908     expect_vec2(&expectedvec, &gotvec, 0);
1909 
1910 /*_______________D3DXVec2CCW__________________________*/
1911     got = D3DXVec2CCW(&u, &v);
1912     equal = compare_float(got, 55.0f, 0);
1913     ok(equal, "Got unexpected ccw %.8e.\n", got);
1914     /* Tests the case NULL. */
1915     got = D3DXVec2CCW(NULL, &v);
1916     equal = compare_float(got, 0.0f, 0);
1917     ok(equal, "Got unexpected ccw %.8e.\n", got);
1918     got = D3DXVec2CCW(NULL, NULL);
1919     equal = compare_float(got, 0.0f, 0);
1920     ok(equal, "Got unexpected ccw %.8e.\n", got);
1921 
1922 /*_______________D3DXVec2Dot__________________________*/
1923     got = D3DXVec2Dot(&u, &v);
1924     equal = compare_float(got, 15.0f, 0);
1925     ok(equal, "Got unexpected dot %.8e.\n", got);
1926     /* Tests the case NULL */
1927     got = D3DXVec2Dot(NULL, &v);
1928     equal = compare_float(got, 0.0f, 0);
1929     ok(equal, "Got unexpected dot %.8e.\n", got);
1930     got = D3DXVec2Dot(NULL, NULL);
1931     equal = compare_float(got, 0.0f, 0);
1932     ok(equal, "Got unexpected dot %.8e.\n", got);
1933 
1934 /*_______________D3DXVec2Hermite__________________________*/
1935     expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
1936     D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
1937     expect_vec2(&expectedvec, &gotvec, 0);
1938 
1939 /*_______________D3DXVec2Length__________________________*/
1940     got = D3DXVec2Length(&u);
1941     equal = compare_float(got, 5.0f, 0);
1942     ok(equal, "Got unexpected length %.8e.\n", got);
1943     /* Tests the case NULL. */
1944     got = D3DXVec2Length(NULL);
1945     equal = compare_float(got, 0.0f, 0);
1946     ok(equal, "Got unexpected length %.8e.\n", got);
1947 
1948 /*_______________D3DXVec2LengthSq________________________*/
1949     got = D3DXVec2LengthSq(&u);
1950     equal = compare_float(got, 25.0f, 0);
1951     ok(equal, "Got unexpected length %.8e.\n", got);
1952     /* Tests the case NULL. */
1953     got = D3DXVec2LengthSq(NULL);
1954     equal = compare_float(got, 0.0f, 0);
1955     ok(equal, "Got unexpected length %.8e.\n", got);
1956 
1957 /*_______________D3DXVec2Lerp__________________________*/
1958     expectedvec.x = 68.0f; expectedvec.y = -28.5f;
1959     D3DXVec2Lerp(&gotvec, &u, &v, scale);
1960     expect_vec2(&expectedvec, &gotvec, 0);
1961     /* Tests the case NULL. */
1962     funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
1963     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1964     funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1965     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1966 
1967 /*_______________D3DXVec2Maximize__________________________*/
1968     expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1969     D3DXVec2Maximize(&gotvec, &u, &v);
1970     expect_vec2(&expectedvec, &gotvec, 0);
1971     /* Tests the case NULL. */
1972     funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1973     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1974     funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1975     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1976 
1977 /*_______________D3DXVec2Minimize__________________________*/
1978     expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1979     D3DXVec2Minimize(&gotvec,&u,&v);
1980     expect_vec2(&expectedvec, &gotvec, 0);
1981     /* Tests the case NULL */
1982     funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1983     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1984     funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1985     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1986 
1987 /*_______________D3DXVec2Normalize_________________________*/
1988     expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1989     D3DXVec2Normalize(&gotvec,&u);
1990     expect_vec2(&expectedvec, &gotvec, 0);
1991     /* Test the nul vector */
1992     expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1993     D3DXVec2Normalize(&gotvec,&nul);
1994     expect_vec2(&expectedvec, &gotvec, 0);
1995 
1996 /*_______________D3DXVec2Scale____________________________*/
1997     expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1998     D3DXVec2Scale(&gotvec,&u,scale);
1999     expect_vec2(&expectedvec, &gotvec, 0);
2000     /* Tests the case NULL */
2001     funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
2002     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2003     funcpointer = D3DXVec2Scale(NULL,NULL,scale);
2004     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2005 
2006 /*_______________D3DXVec2Subtract__________________________*/
2007     expectedvec.x = 10.0f; expectedvec.y = -5.0f;
2008     D3DXVec2Subtract(&gotvec, &u, &v);
2009     expect_vec2(&expectedvec, &gotvec, 0);
2010     /* Tests the case NULL. */
2011     funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
2012     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2013     funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
2014     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2015 
2016 /*_______________D3DXVec2Transform_______________________*/
2017     expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
2018     D3DXVec2Transform(&gottrans, &u, &mat);
2019     expect_vec4(&expectedtrans, &gottrans, 0);
2020     gottrans.x = u.x; gottrans.y = u.y;
2021     D3DXVec2Transform(&gottrans, (D3DXVECTOR2 *)&gottrans, &mat);
2022     expect_vec4(&expectedtrans, &gottrans, 0);
2023 
2024 /*_______________D3DXVec2TransformCoord_______________________*/
2025     expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
2026     D3DXVec2TransformCoord(&gotvec, &u, &mat);
2027     expect_vec2(&expectedvec, &gotvec, 1);
2028     gotvec.x = u.x; gotvec.y = u.y;
2029     D3DXVec2TransformCoord(&gotvec, (D3DXVECTOR2 *)&gotvec, &mat);
2030     expect_vec2(&expectedvec, &gotvec, 1);
2031 
2032  /*_______________D3DXVec2TransformNormal______________________*/
2033     expectedvec.x = 23.0f; expectedvec.y = 30.0f;
2034     D3DXVec2TransformNormal(&gotvec,&u,&mat);
2035     expect_vec2(&expectedvec, &gotvec, 0);
2036 }
2037 
2038 static void D3DXVector3Test(void)
2039 {
2040     D3DVIEWPORT9 viewport;
2041     D3DXVECTOR3 expectedvec, gotvec, nul, u, v, w, x;
2042     LPD3DXVECTOR3 funcpointer;
2043     D3DXVECTOR4 expectedtrans, gottrans;
2044     D3DXMATRIX mat, projection, view, world;
2045     float coeff1, coeff2, got, scale;
2046     BOOL equal;
2047 
2048     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
2049     u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
2050     v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
2051     w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
2052     x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
2053 
2054     viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
2055     viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
2056 
2057     set_matrix(&mat,
2058             1.0f, 2.0f, 3.0f, 4.0f,
2059             5.0f, 6.0f, 7.0f, 8.0f,
2060             9.0f, 10.0f, 11.0f, 12.0f,
2061             13.0f, 14.0f, 15.0f, 16.0f);
2062 
2063     U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
2064     U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
2065     U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
2066     U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
2067     U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
2068     U(view).m[3][3] = -40.0f;
2069 
2070     set_matrix(&world,
2071             21.0f, 2.0f, 3.0f, 4.0f,
2072             5.0f, 23.0f, 7.0f, 8.0f,
2073             -8.0f, -7.0f, 25.0f, -5.0f,
2074             -4.0f, -3.0f, -2.0f, 27.0f);
2075 
2076     coeff1 = 2.0f; coeff2 = 5.0f;
2077     scale = -6.5f;
2078 
2079 /*_______________D3DXVec3Add__________________________*/
2080     expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
2081     D3DXVec3Add(&gotvec,&u,&v);
2082     expect_vec3(&expectedvec, &gotvec, 0);
2083     /* Tests the case NULL */
2084     funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
2085     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2086     funcpointer = D3DXVec3Add(NULL,NULL,NULL);
2087     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2088 
2089 /*_______________D3DXVec3BaryCentric___________________*/
2090     expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
2091     D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
2092     expect_vec3(&expectedvec, &gotvec, 0);
2093 
2094 /*_______________D3DXVec3CatmullRom____________________*/
2095     expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
2096     D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
2097     expect_vec3(&expectedvec, &gotvec, 0);
2098 
2099 /*_______________D3DXVec3Cross________________________*/
2100     expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
2101     D3DXVec3Cross(&gotvec,&u,&v);
2102     expect_vec3(&expectedvec, &gotvec, 0);
2103     expectedvec.x = -277.0f; expectedvec.y = -150.0f; expectedvec.z = -26.0f;
2104     D3DXVec3Cross(&gotvec,&gotvec,&v);
2105     expect_vec3(&expectedvec, &gotvec, 0);
2106     /* Tests the case NULL */
2107     funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
2108     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2109     funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
2110     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2111 
2112 /*_______________D3DXVec3Dot__________________________*/
2113     got = D3DXVec3Dot(&u, &v);
2114     equal = compare_float(got, -8.0f, 0);
2115     ok(equal, "Got unexpected dot %.8e.\n", got);
2116     /* Tests the case NULL */
2117     got = D3DXVec3Dot(NULL, &v);
2118     equal = compare_float(got, 0.0f, 0);
2119     ok(equal, "Got unexpected dot %.8e.\n", got);
2120     got = D3DXVec3Dot(NULL, NULL);
2121     equal = compare_float(got, 0.0f, 0);
2122     ok(equal, "Got unexpected dot %.8e.\n", got);
2123 
2124 /*_______________D3DXVec3Hermite__________________________*/
2125     expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
2126     D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
2127     expect_vec3(&expectedvec, &gotvec, 0);
2128 
2129 /*_______________D3DXVec3Length__________________________*/
2130     got = D3DXVec3Length(&u);
2131     equal = compare_float(got, 11.0f, 0);
2132     ok(equal, "Got unexpected length %.8e.\n", got);
2133     /* Tests the case NULL. */
2134     got = D3DXVec3Length(NULL);
2135     equal = compare_float(got, 0.0f, 0);
2136     ok(equal, "Got unexpected length %.8e.\n", got);
2137 
2138 /*_______________D3DXVec3LengthSq________________________*/
2139     got = D3DXVec3LengthSq(&u);
2140     equal = compare_float(got, 121.0f, 0);
2141     ok(equal, "Got unexpected length %.8e.\n", got);
2142     /* Tests the case NULL. */
2143     got = D3DXVec3LengthSq(NULL);
2144     equal = compare_float(got, 0.0f, 0);
2145     ok(equal, "Got unexpected length %.8e.\n", got);
2146 
2147 /*_______________D3DXVec3Lerp__________________________*/
2148     expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
2149     D3DXVec3Lerp(&gotvec,&u,&v,scale);
2150     expect_vec3(&expectedvec, &gotvec, 0);
2151     /* Tests the case NULL */
2152     funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
2153     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2154     funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
2155     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2156 
2157 /*_______________D3DXVec3Maximize__________________________*/
2158     expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
2159     D3DXVec3Maximize(&gotvec,&u,&v);
2160     expect_vec3(&expectedvec, &gotvec, 0);
2161     /* Tests the case NULL */
2162     funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
2163     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2164     funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
2165     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2166 
2167 /*_______________D3DXVec3Minimize__________________________*/
2168     expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
2169     D3DXVec3Minimize(&gotvec,&u,&v);
2170     expect_vec3(&expectedvec, &gotvec, 0);
2171     /* Tests the case NULL */
2172     funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
2173     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2174     funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
2175     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2176 
2177 /*_______________D3DXVec3Normalize_________________________*/
2178     expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
2179     D3DXVec3Normalize(&gotvec,&u);
2180     expect_vec3(&expectedvec, &gotvec, 1);
2181     /* Test the nul vector */
2182     expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
2183     D3DXVec3Normalize(&gotvec,&nul);
2184     expect_vec3(&expectedvec, &gotvec, 0);
2185 
2186 /*_______________D3DXVec3Scale____________________________*/
2187     expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
2188     D3DXVec3Scale(&gotvec,&u,scale);
2189     expect_vec3(&expectedvec, &gotvec, 0);
2190     /* Tests the case NULL */
2191     funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
2192     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2193     funcpointer = D3DXVec3Scale(NULL,NULL,scale);
2194     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2195 
2196 /*_______________D3DXVec3Subtract_______________________*/
2197     expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
2198     D3DXVec3Subtract(&gotvec,&u,&v);
2199     expect_vec3(&expectedvec, &gotvec, 0);
2200     /* Tests the case NULL */
2201     funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
2202     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2203     funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
2204     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2205 
2206 /*_______________D3DXVec3Transform_______________________*/
2207     expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
2208     D3DXVec3Transform(&gottrans, &u, &mat);
2209     expect_vec4(&expectedtrans, &gottrans, 0);
2210 
2211     gottrans.x = u.x; gottrans.y = u.y; gottrans.z = u.z;
2212     D3DXVec3Transform(&gottrans, (D3DXVECTOR3 *)&gottrans, &mat);
2213     expect_vec4(&expectedtrans, &gottrans, 0);
2214 
2215 /*_______________D3DXVec3TransformCoord_______________________*/
2216     expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
2217     D3DXVec3TransformCoord(&gotvec,&u,&mat);
2218     expect_vec3(&expectedvec, &gotvec, 1);
2219 
2220 /*_______________D3DXVec3TransformNormal______________________*/
2221     expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
2222     D3DXVec3TransformNormal(&gotvec,&u,&mat);
2223     expect_vec3(&expectedvec, &gotvec, 0);
2224 
2225 /*_______________D3DXVec3Project_________________________*/
2226     expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
2227     D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2228     D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
2229     expect_vec3(&expectedvec, &gotvec, 32);
2230     /* World matrix can be omitted */
2231     D3DXMatrixMultiply(&mat,&world,&view);
2232     D3DXVec3Project(&gotvec,&u,&viewport,&projection,&mat,NULL);
2233     expect_vec3(&expectedvec, &gotvec, 32);
2234     /* Projection matrix can be omitted */
2235     D3DXMatrixMultiply(&mat,&view,&projection);
2236     D3DXVec3Project(&gotvec,&u,&viewport,NULL,&mat,&world);
2237     expect_vec3(&expectedvec, &gotvec, 32);
2238     /* View matrix can be omitted */
2239     D3DXMatrixMultiply(&mat,&world,&view);
2240     D3DXVec3Project(&gotvec,&u,&viewport,&projection,NULL,&mat);
2241     expect_vec3(&expectedvec, &gotvec, 32);
2242     /* All matrices can be omitted */
2243     expectedvec.x = 4010.000000f; expectedvec.y = -1695.000000f; expectedvec.z = 1.600000f;
2244     D3DXVec3Project(&gotvec,&u,&viewport,NULL,NULL,NULL);
2245     expect_vec3(&expectedvec, &gotvec, 2);
2246     /* Viewport can be omitted */
2247     expectedvec.x = 1.814305f; expectedvec.y = 0.582097f; expectedvec.z = -0.066555f;
2248     D3DXVec3Project(&gotvec,&u,NULL,&projection,&view,&world);
2249     expect_vec3(&expectedvec, &gotvec, 64);
2250 
2251 /*_______________D3DXVec3Unproject_________________________*/
2252     expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
2253     D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2254     D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
2255     expect_vec3(&expectedvec, &gotvec, 16);
2256     /* World matrix can be omitted */
2257     D3DXMatrixMultiply(&mat,&world,&view);
2258     D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&mat,NULL);
2259     expect_vec3(&expectedvec, &gotvec, 16);
2260     /* Projection matrix can be omitted */
2261     D3DXMatrixMultiply(&mat,&view,&projection);
2262     D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,&mat,&world);
2263     expect_vec3(&expectedvec, &gotvec, 32);
2264     /* View matrix can be omitted */
2265     D3DXMatrixMultiply(&mat,&world,&view);
2266     D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,NULL,&mat);
2267     expect_vec3(&expectedvec, &gotvec, 16);
2268     /* All matrices can be omitted */
2269     expectedvec.x = -1.002500f; expectedvec.y = 0.997059f; expectedvec.z = 2.571429f;
2270     D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,NULL,NULL);
2271     expect_vec3(&expectedvec, &gotvec, 4);
2272     /* Viewport can be omitted */
2273     expectedvec.x = -11.018396f; expectedvec.y = 3.218991f; expectedvec.z = 1.380329f;
2274     D3DXVec3Unproject(&gotvec,&u,NULL,&projection,&view,&world);
2275     expect_vec3(&expectedvec, &gotvec, 8);
2276 }
2277 
2278 static void D3DXVector4Test(void)
2279 {
2280     D3DXVECTOR4 expectedvec, gotvec, u, v, w, x;
2281     LPD3DXVECTOR4 funcpointer;
2282     D3DXVECTOR4 expectedtrans, gottrans;
2283     float coeff1, coeff2, got, scale;
2284     D3DXMATRIX mat;
2285     BOOL equal;
2286 
2287     u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
2288     v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
2289     w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
2290     x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
2291 
2292     set_matrix(&mat,
2293             1.0f, 2.0f, 3.0f, 4.0f,
2294             5.0f, 6.0f, 7.0f, 8.0f,
2295             9.0f, 10.0f, 11.0f, 12.0f,
2296             13.0f, 14.0f, 15.0f, 16.0f);
2297 
2298     coeff1 = 2.0f; coeff2 = 5.0;
2299     scale = -6.5f;
2300 
2301 /*_______________D3DXVec4Add__________________________*/
2302     expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
2303     D3DXVec4Add(&gotvec,&u,&v);
2304     expect_vec4(&expectedvec, &gotvec, 0);
2305     /* Tests the case NULL */
2306     funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
2307     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2308     funcpointer = D3DXVec4Add(NULL,NULL,NULL);
2309     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2310 
2311 /*_______________D3DXVec4BaryCentric____________________*/
2312     expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z =  -44.0f; expectedvec.w = -41.0f;
2313     D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
2314     expect_vec4(&expectedvec, &gotvec, 0);
2315 
2316 /*_______________D3DXVec4CatmullRom____________________*/
2317     expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
2318     D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
2319     expect_vec4(&expectedvec, &gotvec, 0);
2320 
2321 /*_______________D3DXVec4Cross_________________________*/
2322     expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
2323     D3DXVec4Cross(&gotvec,&u,&v,&w);
2324     expect_vec4(&expectedvec, &gotvec, 0);
2325 
2326 /*_______________D3DXVec4Dot__________________________*/
2327     got = D3DXVec4Dot(&u, &v);
2328     equal = compare_float(got, 55.0f, 0);
2329     ok(equal, "Got unexpected dot %.8e.\n", got);
2330     /* Tests the case NULL. */
2331     got = D3DXVec4Dot(NULL, &v);
2332     equal = compare_float(got, 0.0f, 0);
2333     ok(equal, "Got unexpected dot %.8e.\n", got);
2334     got = D3DXVec4Dot(NULL, NULL);
2335     equal = compare_float(got, 0.0f, 0);
2336     ok(equal, "Got unexpected dot %.8e.\n", got);
2337 
2338 /*_______________D3DXVec4Hermite_________________________*/
2339     expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
2340     D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
2341     expect_vec4(&expectedvec, &gotvec, 0);
2342 
2343 /*_______________D3DXVec4Length__________________________*/
2344     got = D3DXVec4Length(&u);
2345     equal = compare_float(got, 11.0f, 0);
2346     ok(equal, "Got unexpected length %.8e.\n", got);
2347     /* Tests the case NULL. */
2348     got = D3DXVec4Length(NULL);
2349     equal = compare_float(got, 0.0f, 0);
2350     ok(equal, "Got unexpected length %.8e.\n", got);
2351 
2352 /*_______________D3DXVec4LengthSq________________________*/
2353     got = D3DXVec4LengthSq(&u);
2354     equal = compare_float(got, 121.0f, 0);
2355     ok(equal, "Got unexpected length %.8e.\n", got);
2356     /* Tests the case NULL. */
2357     got = D3DXVec4LengthSq(NULL);
2358     equal = compare_float(got, 0.0f, 0);
2359     ok(equal, "Got unexpected length %.8e.\n", got);
2360 
2361 /*_______________D3DXVec4Lerp__________________________*/
2362     expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5;  expectedvec.w = 29.5;
2363     D3DXVec4Lerp(&gotvec,&u,&v,scale);
2364     expect_vec4(&expectedvec, &gotvec, 0);
2365     /* Tests the case NULL */
2366     funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
2367     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2368     funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
2369     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2370 
2371 /*_______________D3DXVec4Maximize__________________________*/
2372     expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
2373     D3DXVec4Maximize(&gotvec,&u,&v);
2374     expect_vec4(&expectedvec, &gotvec, 0);
2375     /* Tests the case NULL */
2376     funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
2377     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2378     funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
2379     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2380 
2381 /*_______________D3DXVec4Minimize__________________________*/
2382     expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
2383     D3DXVec4Minimize(&gotvec,&u,&v);
2384     expect_vec4(&expectedvec, &gotvec, 0);
2385     /* Tests the case NULL */
2386     funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
2387     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2388     funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
2389     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2390 
2391 /*_______________D3DXVec4Normalize_________________________*/
2392     expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
2393     D3DXVec4Normalize(&gotvec,&u);
2394     expect_vec4(&expectedvec, &gotvec, 1);
2395 
2396 /*_______________D3DXVec4Scale____________________________*/
2397     expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
2398     D3DXVec4Scale(&gotvec,&u,scale);
2399     expect_vec4(&expectedvec, &gotvec, 0);
2400     /* Tests the case NULL */
2401     funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
2402     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2403     funcpointer = D3DXVec4Scale(NULL,NULL,scale);
2404     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2405 
2406 /*_______________D3DXVec4Subtract__________________________*/
2407     expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
2408     D3DXVec4Subtract(&gotvec,&u,&v);
2409     expect_vec4(&expectedvec, &gotvec, 0);
2410     /* Tests the case NULL */
2411     funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
2412     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2413     funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
2414     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
2415 
2416 /*_______________D3DXVec4Transform_______________________*/
2417     expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
2418     D3DXVec4Transform(&gottrans,&u,&mat);
2419     expect_vec4(&expectedtrans, &gottrans, 0);
2420 }
2421 
2422 static void test_matrix_stack(void)
2423 {
2424     ID3DXMatrixStack *stack;
2425     ULONG refcount;
2426     HRESULT hr;
2427 
2428     const D3DXMATRIX mat1 = {{{
2429          1.0f,  2.0f,  3.0f,  4.0f,
2430          5.0f,  6.0f,  7.0f,  8.0f,
2431          9.0f, 10.0f, 11.0f, 12.0f,
2432         13.0f, 14.0f, 15.0f, 16.0f
2433     }}};
2434 
2435     const D3DXMATRIX mat2 = {{{
2436         17.0f, 18.0f, 19.0f, 20.0f,
2437         21.0f, 22.0f, 23.0f, 24.0f,
2438         25.0f, 26.0f, 27.0f, 28.0f,
2439         29.0f, 30.0f, 31.0f, 32.0f
2440     }}};
2441 
2442     hr = D3DXCreateMatrixStack(0, &stack);
2443     ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
2444     if (FAILED(hr)) return;
2445 
2446     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
2447             "The top of an empty matrix stack should be an identity matrix\n");
2448 
2449     hr = ID3DXMatrixStack_Pop(stack);
2450     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
2451 
2452     hr = ID3DXMatrixStack_Push(stack);
2453     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
2454     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
2455 
2456     hr = ID3DXMatrixStack_Push(stack);
2457     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
2458 
2459     hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
2460     ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
2461     expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
2462 
2463     hr = ID3DXMatrixStack_Push(stack);
2464     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
2465     expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
2466 
2467     hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
2468     ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
2469     expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
2470 
2471     hr = ID3DXMatrixStack_Push(stack);
2472     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
2473     expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
2474 
2475     hr = ID3DXMatrixStack_LoadIdentity(stack);
2476     ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
2477     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
2478 
2479     hr = ID3DXMatrixStack_Pop(stack);
2480     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
2481     expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
2482 
2483     hr = ID3DXMatrixStack_Pop(stack);
2484     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
2485     expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
2486 
2487     hr = ID3DXMatrixStack_Pop(stack);
2488     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
2489     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
2490 
2491     hr = ID3DXMatrixStack_Pop(stack);
2492     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
2493     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
2494 
2495     refcount = ID3DXMatrixStack_Release(stack);
2496     ok(!refcount, "Matrix stack has %u references left.\n", refcount);
2497 }
2498 
2499 static void test_Matrix_AffineTransformation2D(void)
2500 {
2501     D3DXMATRIX exp_mat, got_mat;
2502     D3DXVECTOR2 center, position;
2503     FLOAT angle, scale;
2504 
2505     center.x = 3.0f;
2506     center.y = 4.0f;
2507 
2508     position.x = -6.0f;
2509     position.y = 7.0f;
2510 
2511     angle = D3DX_PI/3.0f;
2512 
2513     scale = 20.0f;
2514 
2515     U(exp_mat).m[0][0] = 10.0f;
2516     U(exp_mat).m[1][0] = -17.320507f;
2517     U(exp_mat).m[2][0] = 0.0f;
2518     U(exp_mat).m[3][0] = -1.035898f;
2519     U(exp_mat).m[0][1] = 17.320507f;
2520     U(exp_mat).m[1][1] = 10.0f;
2521     U(exp_mat).m[2][1] = 0.0f;
2522     U(exp_mat).m[3][1] = 6.401924f;
2523     U(exp_mat).m[0][2] = 0.0f;
2524     U(exp_mat).m[1][2] = 0.0f;
2525     U(exp_mat).m[2][2] = 1.0f;
2526     U(exp_mat).m[3][2] = 0.0f;
2527     U(exp_mat).m[0][3] = 0.0f;
2528     U(exp_mat).m[1][3] = 0.0f;
2529     U(exp_mat).m[2][3] = 0.0f;
2530     U(exp_mat).m[3][3] = 1.0f;
2531 
2532     D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, &position);
2533     expect_matrix(&exp_mat, &got_mat, 2);
2534 
2535 /*______________*/
2536 
2537     center.x = 3.0f;
2538     center.y = 4.0f;
2539 
2540     angle = D3DX_PI/3.0f;
2541 
2542     scale = 20.0f;
2543 
2544     U(exp_mat).m[0][0] = 10.0f;
2545     U(exp_mat).m[1][0] = -17.320507f;
2546     U(exp_mat).m[2][0] = 0.0f;
2547     U(exp_mat).m[3][0] = 4.964102f;
2548     U(exp_mat).m[0][1] = 17.320507f;
2549     U(exp_mat).m[1][1] = 10.0f;
2550     U(exp_mat).m[2][1] = 0.0f;
2551     U(exp_mat).m[3][1] = -0.598076f;
2552     U(exp_mat).m[0][2] = 0.0f;
2553     U(exp_mat).m[1][2] = 0.0f;
2554     U(exp_mat).m[2][2] = 1.0f;
2555     U(exp_mat).m[3][2] = 0.0f;
2556     U(exp_mat).m[0][3] = 0.0f;
2557     U(exp_mat).m[1][3] = 0.0f;
2558     U(exp_mat).m[2][3] = 0.0f;
2559     U(exp_mat).m[3][3] = 1.0f;
2560 
2561     D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, NULL);
2562     expect_matrix(&exp_mat, &got_mat, 8);
2563 
2564 /*______________*/
2565 
2566     position.x = -6.0f;
2567     position.y = 7.0f;
2568 
2569     angle = D3DX_PI/3.0f;
2570 
2571     scale = 20.0f;
2572 
2573     U(exp_mat).m[0][0] = 10.0f;
2574     U(exp_mat).m[1][0] = -17.320507f;
2575     U(exp_mat).m[2][0] = 0.0f;
2576     U(exp_mat).m[3][0] = -6.0f;
2577     U(exp_mat).m[0][1] = 17.320507f;
2578     U(exp_mat).m[1][1] = 10.0f;
2579     U(exp_mat).m[2][1] = 0.0f;
2580     U(exp_mat).m[3][1] = 7.0f;
2581     U(exp_mat).m[0][2] = 0.0f;
2582     U(exp_mat).m[1][2] = 0.0f;
2583     U(exp_mat).m[2][2] = 1.0f;
2584     U(exp_mat).m[3][2] = 0.0f;
2585     U(exp_mat).m[0][3] = 0.0f;
2586     U(exp_mat).m[1][3] = 0.0f;
2587     U(exp_mat).m[2][3] = 0.0f;
2588     U(exp_mat).m[3][3] = 1.0f;
2589 
2590     D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, &position);
2591     expect_matrix(&exp_mat, &got_mat, 1);
2592 
2593 /*______________*/
2594 
2595     angle = 5.0f * D3DX_PI/4.0f;
2596 
2597     scale = -20.0f;
2598 
2599     U(exp_mat).m[0][0] = 14.142133f;
2600     U(exp_mat).m[1][0] = -14.142133f;
2601     U(exp_mat).m[2][0] = 0.0f;
2602     U(exp_mat).m[3][0] = 0.0f;
2603     U(exp_mat).m[0][1] = 14.142133;
2604     U(exp_mat).m[1][1] = 14.142133f;
2605     U(exp_mat).m[2][1] = 0.0f;
2606     U(exp_mat).m[3][1] = 0.0f;
2607     U(exp_mat).m[0][2] = 0.0f;
2608     U(exp_mat).m[1][2] = 0.0f;
2609     U(exp_mat).m[2][2] = 1.0f;
2610     U(exp_mat).m[3][2] = 0.0f;
2611     U(exp_mat).m[0][3] = 0.0f;
2612     U(exp_mat).m[1][3] = 0.0f;
2613     U(exp_mat).m[2][3] = 0.0f;
2614     U(exp_mat).m[3][3] = 1.0f;
2615 
2616     D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, NULL);
2617     expect_matrix(&exp_mat, &got_mat, 8);
2618 }
2619 
2620 static void test_Matrix_Decompose(void)
2621 {
2622     D3DXMATRIX pm;
2623     D3DXQUATERNION exp_rotation, got_rotation;
2624     D3DXVECTOR3 exp_scale, got_scale, exp_translation, got_translation;
2625     HRESULT hr;
2626     BOOL equal;
2627 
2628 /*___________*/
2629 
2630     U(pm).m[0][0] = -9.23879206e-01f;
2631     U(pm).m[1][0] = -2.70598412e-01f;
2632     U(pm).m[2][0] =  2.70598441e-01f;
2633     U(pm).m[3][0] = -5.00000000e+00f;
2634     U(pm).m[0][1] =  2.70598471e-01f;
2635     U(pm).m[1][1] =  3.80604863e-02f;
2636     U(pm).m[2][1] =  9.61939573e-01f;
2637     U(pm).m[3][1] =  0.00000000e+00f;
2638     U(pm).m[0][2] = -2.70598441e-01f;
2639     U(pm).m[1][2] =  9.61939573e-01f;
2640     U(pm).m[2][2] =  3.80603075e-02f;
2641     U(pm).m[3][2] =  1.00000000e+01f;
2642     U(pm).m[0][3] =  0.00000000e+00f;
2643     U(pm).m[1][3] =  0.00000000e+00f;
2644     U(pm).m[2][3] =  0.00000000e+00f;
2645     U(pm).m[3][3] =  1.00000000e+00f;
2646 
2647     exp_scale.x = 9.99999881e-01f;
2648     exp_scale.y = 9.99999881e-01f;
2649     exp_scale.z = 9.99999881e-01f;
2650 
2651     exp_rotation.x = 2.14862776e-08f;
2652     exp_rotation.y = 6.93519890e-01f;
2653     exp_rotation.z = 6.93519890e-01f;
2654     exp_rotation.w = 1.95090637e-01f;
2655 
2656     exp_translation.x = -5.0f;
2657     exp_translation.y = 0.0f;
2658     exp_translation.z = 10.0f;
2659 
2660     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2661     expect_vec3(&exp_scale, &got_scale, 1);
2662     expect_quaternion(&exp_rotation, &got_rotation, 1);
2663     expect_vec3(&exp_translation, &got_translation, 0);
2664 
2665 /*_________*/
2666 
2667     U(pm).m[0][0] = -2.255813f;
2668     U(pm).m[1][0] = 1.302324f;
2669     U(pm).m[2][0] = 1.488373f;
2670     U(pm).m[3][0] = 1.0f;
2671     U(pm).m[0][1] = 1.302327f;
2672     U(pm).m[1][1] = -0.7209296f;
2673     U(pm).m[2][1] = 2.60465f;
2674     U(pm).m[3][1] = 2.0f;
2675     U(pm).m[0][2] = 1.488371f;
2676     U(pm).m[1][2] = 2.604651f;
2677     U(pm).m[2][2] = -0.02325551f;
2678     U(pm).m[3][2] = 3.0f;
2679     U(pm).m[0][3] = 0.0f;
2680     U(pm).m[1][3] = 0.0f;
2681     U(pm).m[2][3] = 0.0f;
2682     U(pm).m[3][3] = 1.0f;
2683 
2684     exp_scale.x = 2.99999928e+00f;
2685     exp_scale.y = 2.99999905e+00f;
2686     exp_scale.z = 2.99999952e+00f;
2687 
2688     exp_rotation.x = 3.52180451e-01f;
2689     exp_rotation.y = 6.16315663e-01f;
2690     exp_rotation.z = 7.04360664e-01f;
2691     exp_rotation.w = 3.38489343e-07f;
2692 
2693     exp_translation.x = 1.0f;
2694     exp_translation.y = 2.0f;
2695     exp_translation.z = 3.0f;
2696 
2697     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2698     expect_vec3(&exp_scale, &got_scale, 0);
2699     expect_quaternion(&exp_rotation, &got_rotation, 2);
2700     expect_vec3(&exp_translation, &got_translation, 0);
2701 
2702 /*_____________*/
2703 
2704     U(pm).m[0][0] = 2.427051f;
2705     U(pm).m[1][0] = 0.0f;
2706     U(pm).m[2][0] = 1.763355f;
2707     U(pm).m[3][0] = 5.0f;
2708     U(pm).m[0][1] = 0.0f;
2709     U(pm).m[1][1] = 3.0f;
2710     U(pm).m[2][1] = 0.0f;
2711     U(pm).m[3][1] = 5.0f;
2712     U(pm).m[0][2] = -1.763355f;
2713     U(pm).m[1][2] = 0.0f;
2714     U(pm).m[2][2] = 2.427051f;
2715     U(pm).m[3][2] = 5.0f;
2716     U(pm).m[0][3] = 0.0f;
2717     U(pm).m[1][3] = 0.0f;
2718     U(pm).m[2][3] = 0.0f;
2719     U(pm).m[3][3] = 1.0f;
2720 
2721     exp_scale.x = 2.99999976e+00f;
2722     exp_scale.y = 3.00000000e+00f;
2723     exp_scale.z = 2.99999976e+00f;
2724 
2725     exp_rotation.x = 0.00000000e+00f;
2726     exp_rotation.y = 3.09016883e-01f;
2727     exp_rotation.z = 0.00000000e+00f;
2728     exp_rotation.w = 9.51056540e-01f;
2729 
2730     exp_translation.x = 5.0f;
2731     exp_translation.y = 5.0f;
2732     exp_translation.z = 5.0f;
2733 
2734     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2735     expect_vec3(&exp_scale, &got_scale, 1);
2736     expect_quaternion(&exp_rotation, &got_rotation, 1);
2737     expect_vec3(&exp_translation, &got_translation, 0);
2738 
2739 /*_____________*/
2740 
2741     U(pm).m[0][0] = -9.23879206e-01f;
2742     U(pm).m[1][0] = -2.70598412e-01f;
2743     U(pm).m[2][0] =  2.70598441e-01f;
2744     U(pm).m[3][0] = -5.00000000e+00f;
2745     U(pm).m[0][1] =  2.70598471e-01f;
2746     U(pm).m[1][1] =  3.80604863e-02f;
2747     U(pm).m[2][1] =  9.61939573e-01f;
2748     U(pm).m[3][1] =  0.00000000e+00f;
2749     U(pm).m[0][2] = -2.70598441e-01f;
2750     U(pm).m[1][2] =  9.61939573e-01f;
2751     U(pm).m[2][2] =  3.80603075e-02f;
2752     U(pm).m[3][2] =  1.00000000e+01f;
2753     U(pm).m[0][3] =  0.00000000e+00f;
2754     U(pm).m[1][3] =  0.00000000e+00f;
2755     U(pm).m[2][3] =  0.00000000e+00f;
2756     U(pm).m[3][3] =  1.00000000e+00f;
2757 
2758     exp_scale.x = 9.99999881e-01f;
2759     exp_scale.y = 9.99999881e-01f;
2760     exp_scale.z = 9.99999881e-01f;
2761 
2762     exp_rotation.x = 2.14862776e-08f;
2763     exp_rotation.y = 6.93519890e-01f;
2764     exp_rotation.z = 6.93519890e-01f;
2765     exp_rotation.w = 1.95090637e-01f;
2766 
2767     exp_translation.x = -5.0f;
2768     exp_translation.y = 0.0f;
2769     exp_translation.z = 10.0f;
2770 
2771     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2772     expect_vec3(&exp_scale, &got_scale, 1);
2773     expect_quaternion(&exp_rotation, &got_rotation, 1);
2774     expect_vec3(&exp_translation, &got_translation, 0);
2775 
2776 /*__________*/
2777 
2778     U(pm).m[0][0] = -9.23878908e-01f;
2779     U(pm).m[1][0] = -5.41196704e-01f;
2780     U(pm).m[2][0] =  8.11795175e-01f;
2781     U(pm).m[3][0] = -5.00000000e+00f;
2782     U(pm).m[0][1] =  2.70598322e-01f;
2783     U(pm).m[1][1] =  7.61209577e-02f;
2784     U(pm).m[2][1] =  2.88581824e+00f;
2785     U(pm).m[3][1] =  0.00000000e+00f;
2786     U(pm).m[0][2] = -2.70598352e-01f;
2787     U(pm).m[1][2] =  1.92387879e+00f;
2788     U(pm).m[2][2] =  1.14180908e-01f;
2789     U(pm).m[3][2] =  1.00000000e+01f;
2790     U(pm).m[0][3] =  0.00000000e+00f;
2791     U(pm).m[1][3] =  0.00000000e+00f;
2792     U(pm).m[2][3] =  0.00000000e+00f;
2793     U(pm).m[3][3] =  1.00000000e+00f;
2794 
2795     exp_scale.x = 9.99999583e-01f;
2796     exp_scale.y = 1.99999940e+00f;
2797     exp_scale.z = 2.99999928e+00f;
2798 
2799     exp_rotation.x = 1.07431388e-08f;
2800     exp_rotation.y = 6.93519890e-01f;
2801     exp_rotation.z = 6.93519831e-01f;
2802     exp_rotation.w = 1.95090622e-01f;
2803 
2804     exp_translation.x = -5.0f;
2805     exp_translation.y = 0.0f;
2806     exp_translation.z = 10.0f;
2807 
2808     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2809     expect_vec3(&exp_scale, &got_scale, 1);
2810     equal = compare_quaternion(&exp_rotation, &got_rotation, 1);
2811     exp_rotation.x = 0.0f;
2812     equal |= compare_quaternion(&exp_rotation, &got_rotation, 2);
2813     ok(equal, "Got unexpected quaternion {%.8e, %.8e, %.8e, %.8e}.\n",
2814             got_rotation.x, got_rotation.y, got_rotation.z, got_rotation.w);
2815     expect_vec3(&exp_translation, &got_translation, 0);
2816 
2817 /*__________*/
2818 
2819     U(pm).m[0][0] = 0.7156004f;
2820     U(pm).m[1][0] = -0.5098283f;
2821     U(pm).m[2][0] = -0.4774843f;
2822     U(pm).m[3][0] = -5.0f;
2823     U(pm).m[0][1] = -0.6612288f;
2824     U(pm).m[1][1] = -0.7147621f;
2825     U(pm).m[2][1] = -0.2277977f;
2826     U(pm).m[3][1] = 0.0f;
2827     U(pm).m[0][2] = -0.2251499f;
2828     U(pm).m[1][2] = 0.4787385f;
2829     U(pm).m[2][2] = -0.8485972f;
2830     U(pm).m[3][2] = 10.0f;
2831     U(pm).m[0][3] = 0.0f;
2832     U(pm).m[1][3] = 0.0f;
2833     U(pm).m[2][3] = 0.0f;
2834     U(pm).m[3][3] = 1.0f;
2835 
2836     exp_scale.x = 9.99999940e-01f;
2837     exp_scale.y = 1.00000012e+00f;
2838     exp_scale.z = 1.00000012e+00f;
2839 
2840     exp_rotation.x = 9.05394852e-01f;
2841     exp_rotation.y = -3.23355347e-01f;
2842     exp_rotation.z = -1.94013178e-01f;
2843     exp_rotation.w = 1.95090592e-01f;
2844 
2845     exp_translation.x = -5.0f;
2846     exp_translation.y = 0.0f;
2847     exp_translation.z = 10.0f;
2848 
2849     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2850     expect_vec3(&exp_scale, &got_scale, 0);
2851     expect_quaternion(&exp_rotation, &got_rotation, 1);
2852     expect_vec3(&exp_translation, &got_translation, 0);
2853 
2854 /*_____________*/
2855 
2856     U(pm).m[0][0] = 0.06554436f;
2857     U(pm).m[1][0] = -0.6873012f;
2858     U(pm).m[2][0] = 0.7234092f;
2859     U(pm).m[3][0] = -5.0f;
2860     U(pm).m[0][1] = -0.9617381f;
2861     U(pm).m[1][1] = -0.2367795f;
2862     U(pm).m[2][1] = -0.1378230f;
2863     U(pm).m[3][1] = 0.0f;
2864     U(pm).m[0][2] = 0.2660144f;
2865     U(pm).m[1][2] = -0.6866967f;
2866     U(pm).m[2][2] = -0.6765233f;
2867     U(pm).m[3][2] = 10.0f;
2868     U(pm).m[0][3] = 0.0f;
2869     U(pm).m[1][3] = 0.0f;
2870     U(pm).m[2][3] = 0.0f;
2871     U(pm).m[3][3] = 1.0f;
2872 
2873     exp_scale.x = 9.99999940e-01f;
2874     exp_scale.y = 9.99999940e-01f;
2875     exp_scale.z = 9.99999881e-01f;
2876 
2877     exp_rotation.x = 7.03357518e-01f;
2878     exp_rotation.y = -5.86131275e-01f;
2879     exp_rotation.z = 3.51678789e-01f;
2880     exp_rotation.w = -1.95090577e-01f;
2881 
2882     exp_translation.x = -5.0f;
2883     exp_translation.y = 0.0f;
2884     exp_translation.z = 10.0f;
2885 
2886     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2887     expect_vec3(&exp_scale, &got_scale, 1);
2888     expect_quaternion(&exp_rotation, &got_rotation, 2);
2889     expect_vec3(&exp_translation, &got_translation, 0);
2890 
2891 /*_________*/
2892 
2893     U(pm).m[0][0] =  7.12104797e+00f;
2894     U(pm).m[1][0] = -5.88348627e+00f;
2895     U(pm).m[2][0] =  1.18184204e+01f;
2896     U(pm).m[3][0] = -5.00000000e+00f;
2897     U(pm).m[0][1] =  5.88348627e+00f;
2898     U(pm).m[1][1] = -1.06065865e+01f;
2899     U(pm).m[2][1] = -8.82523251e+00f;
2900     U(pm).m[3][1] =  0.00000000e+00f;
2901     U(pm).m[0][2] =  1.18184204e+01f;
2902     U(pm).m[1][2] =  8.82523155e+00f;
2903     U(pm).m[2][2] = -2.72764111e+00f;
2904     U(pm).m[3][2] =  2.00000000e+00f;
2905     U(pm).m[0][3] =  0.00000000e+00f;
2906     U(pm).m[1][3] =  0.00000000e+00f;
2907     U(pm).m[2][3] =  0.00000000e+00f;
2908     U(pm).m[3][3] =  1.00000000e+00f;
2909 
2910     exp_scale.x = 1.49999933e+01f;
2911     exp_scale.y = 1.49999933e+01f;
2912     exp_scale.z = 1.49999943e+01f;
2913 
2914     exp_rotation.x = 7.68714130e-01f;
2915     exp_rotation.y = 0.00000000e+00f;
2916     exp_rotation.z = 5.12475967e-01f;
2917     exp_rotation.w = 3.82683903e-01f;
2918 
2919     exp_translation.x = -5.0f;
2920     exp_translation.y = 0.0f;
2921     exp_translation.z = 2.0f;
2922 
2923     D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2924     expect_vec3(&exp_scale, &got_scale, 0);
2925     expect_quaternion(&exp_rotation, &got_rotation, 1);
2926     expect_vec3(&exp_translation, &got_translation, 0);
2927 
2928 /*__________*/
2929 
2930     U(pm).m[0][0] = 0.0f;
2931     U(pm).m[1][0] = 4.0f;
2932     U(pm).m[2][0] = 5.0f;
2933     U(pm).m[3][0] = -5.0f;
2934     U(pm).m[0][1] = 0.0f;
2935     U(pm).m[1][1] = -10.60660f;
2936     U(pm).m[2][1] = -8.825232f;
2937     U(pm).m[3][1] = 6.0f;
2938     U(pm).m[0][2] = 0.0f;
2939     U(pm).m[1][2] = 8.8252320f;
2940     U(pm).m[2][2] = 2.727645;
2941     U(pm).m[3][2] = 3.0f;
2942     U(pm).m[0][3] = 0.0f;
2943     U(pm).m[1][3] = 0.0f;
2944     U(pm).m[2][3] = 0.0f;
2945     U(pm).m[3][3] = 1.0f;
2946 
2947     hr = D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2948     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
2949 }
2950 
2951 static void test_Matrix_Transformation2D(void)
2952 {
2953     D3DXMATRIX exp_mat, got_mat;
2954     D3DXVECTOR2 rot_center, sca, sca_center, trans;
2955     FLOAT rot, sca_rot;
2956 
2957     rot_center.x = 3.0f;
2958     rot_center.y = 4.0f;
2959 
2960     sca.x = 12.0f;
2961     sca.y = -3.0f;
2962 
2963     sca_center.x = 9.0f;
2964     sca_center.y = -5.0f;
2965 
2966     trans.x = -6.0f;
2967     trans.y = 7.0f;
2968 
2969     rot = D3DX_PI/3.0f;
2970 
2971     sca_rot = 5.0f*D3DX_PI/4.0f;
2972 
2973     U(exp_mat).m[0][0] = -4.245192f;
2974     U(exp_mat).m[1][0] = -0.147116f;
2975     U(exp_mat).m[2][0] = 0.0f;
2976     U(exp_mat).m[3][0] = 45.265373f;
2977     U(exp_mat).m[0][1] = 7.647113f;
2978     U(exp_mat).m[1][1] = 8.745192f;
2979     U(exp_mat).m[2][1] = 0.0f;
2980     U(exp_mat).m[3][1] = -13.401899f;
2981     U(exp_mat).m[0][2] = 0.0f;
2982     U(exp_mat).m[1][2] = 0.0f;
2983     U(exp_mat).m[2][2] = 1.0f;
2984     U(exp_mat).m[3][2] = 0.0f;
2985     U(exp_mat).m[0][3] = 0.0f;
2986     U(exp_mat).m[1][3] = 0.0f;
2987     U(exp_mat).m[2][3] = 0.0f;
2988     U(exp_mat).m[3][3] = 1.0f;
2989 
2990     D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
2991     expect_matrix(&exp_mat, &got_mat, 64);
2992 
2993 /*_________*/
2994 
2995     sca_center.x = 9.0f;
2996     sca_center.y = -5.0f;
2997 
2998     trans.x = -6.0f;
2999     trans.y = 7.0f;
3000 
3001     rot = D3DX_PI/3.0f;
3002 
3003     sca_rot = 5.0f*D3DX_PI/4.0f;
3004 
3005     U(exp_mat).m[0][0] = 0.50f;
3006     U(exp_mat).m[1][0] = -0.866025f;
3007     U(exp_mat).m[2][0] = 0.0f;
3008     U(exp_mat).m[3][0] = -6.0f;
3009     U(exp_mat).m[0][1] = 0.866025f;
3010     U(exp_mat).m[1][1] = 0.50f;
3011     U(exp_mat).m[2][1] = 0.0f;
3012     U(exp_mat).m[3][1] = 7.0f;
3013     U(exp_mat).m[0][2] = 0.0f;
3014     U(exp_mat).m[1][2] = 0.0f;
3015     U(exp_mat).m[2][2] = 1.0f;
3016     U(exp_mat).m[3][2] = 0.0f;
3017     U(exp_mat).m[0][3] = 0.0f;
3018     U(exp_mat).m[1][3] = 0.0f;
3019     U(exp_mat).m[2][3] = 0.0f;
3020     U(exp_mat).m[3][3] = 1.0f;
3021 
3022     D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
3023     expect_matrix(&exp_mat, &got_mat, 8);
3024 
3025 /*_________*/
3026 
3027     U(exp_mat).m[0][0] = 0.50f;
3028     U(exp_mat).m[1][0] = -0.866025f;
3029     U(exp_mat).m[2][0] = 0.0f;
3030     U(exp_mat).m[3][0] = 0.0f;
3031     U(exp_mat).m[0][1] = 0.866025f;
3032     U(exp_mat).m[1][1] = 0.50f;
3033     U(exp_mat).m[2][1] = 0.0f;
3034     U(exp_mat).m[3][1] = 0.0f;
3035     U(exp_mat).m[0][2] = 0.0f;
3036     U(exp_mat).m[1][2] = 0.0f;
3037     U(exp_mat).m[2][2] = 1.0f;
3038     U(exp_mat).m[3][2] = 0.0f;
3039     U(exp_mat).m[0][3] = 0.0f;
3040     U(exp_mat).m[1][3] = 0.0f;
3041     U(exp_mat).m[2][3] = 0.0f;
3042     U(exp_mat).m[3][3] = 1.0f;
3043 
3044     D3DXMatrixTransformation2D(&got_mat, NULL, sca_rot, NULL, NULL, rot, NULL);
3045     expect_matrix(&exp_mat, &got_mat, 8);
3046 }
3047 
3048 static void test_D3DXVec_Array(void)
3049 {
3050     D3DXPLANE inp_plane[5], out_plane[7], exp_plane[7];
3051     D3DXVECTOR4 inp_vec[5], out_vec[7], exp_vec[7];
3052     D3DXMATRIX mat, projection, view, world;
3053     D3DVIEWPORT9 viewport;
3054     unsigned int i;
3055 
3056     viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
3057     viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
3058 
3059     memset(out_vec, 0, sizeof(out_vec));
3060     memset(exp_vec, 0, sizeof(exp_vec));
3061     memset(out_plane, 0, sizeof(out_plane));
3062     memset(exp_plane, 0, sizeof(exp_plane));
3063 
3064     for (i = 0; i < ARRAY_SIZE(inp_vec); ++i)
3065     {
3066         inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
3067         inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE(inp_vec) - i;
3068     }
3069 
3070     set_matrix(&mat,
3071             1.0f, 2.0f, 3.0f, 4.0f,
3072             5.0f, 6.0f, 7.0f, 8.0f,
3073             9.0f, 10.0f, 11.0f, 12.0f,
3074             13.0f, 14.0f, 15.0f, 16.0f);
3075 
3076     D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI / 4.0f, 20.0f / 17.0f, 1.0f, 1000.0f);
3077 
3078     U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
3079     U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
3080     U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
3081     U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
3082     U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
3083     U(view).m[3][3] = -40.0f;
3084 
3085     set_matrix(&world,
3086             21.0f, 2.0f, 3.0f, 4.0f,
3087             5.0f, 23.0f, 7.0f, 8.0f,
3088             -8.0f, -7.0f, 25.0f, -5.0f,
3089             -4.0f, -3.0f, -2.0f, 27.0f);
3090 
3091     /* D3DXVec2TransformCoordArray */
3092     exp_vec[1].x = 6.78571403e-01f; exp_vec[1].y = 7.85714269e-01f;
3093     exp_vec[2].x = 6.53846204e-01f; exp_vec[2].y = 7.69230783e-01f;
3094     exp_vec[3].x = 6.25000000e-01f; exp_vec[3].y = 7.50000000e-01f;
3095     exp_vec[4].x = 5.90909123e-01f; exp_vec[4].y = 7.27272749e-01f;
3096     exp_vec[5].x = 5.49999952e-01f; exp_vec[5].y = 6.99999928e-01f;
3097     D3DXVec2TransformCoordArray((D3DXVECTOR2 *)&out_vec[1], sizeof(*out_vec),
3098             (D3DXVECTOR2 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3099     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 1);
3100 
3101     /* D3DXVec2TransformNormalArray */
3102     exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
3103     exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
3104     exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
3105     exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
3106     exp_vec[5].x =  9.0f; exp_vec[5].y = 14.0f;
3107     D3DXVec2TransformNormalArray((D3DXVECTOR2 *)&out_vec[1], sizeof(*out_vec),
3108             (D3DXVECTOR2 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3109     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
3110 
3111     /* D3DXVec3TransformCoordArray */
3112     exp_vec[1].x = 6.78571403e-01f; exp_vec[1].y = 7.85714269e-01f; exp_vec[1].z = 8.92857075e-01f;
3113     exp_vec[2].x = 6.71874940e-01f; exp_vec[2].y = 7.81249940e-01f; exp_vec[2].z = 8.90624940e-01f;
3114     exp_vec[3].x = 6.66666627e-01f; exp_vec[3].y = 7.77777731e-01f; exp_vec[3].z = 8.88888836e-01f;
3115     exp_vec[4].x = 6.62499964e-01f; exp_vec[4].y = 7.74999976e-01f; exp_vec[4].z = 8.87499928e-01f;
3116     exp_vec[5].x = 6.59090877e-01f; exp_vec[5].y = 7.72727251e-01f; exp_vec[5].z = 8.86363566e-01f;
3117     D3DXVec3TransformCoordArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec),
3118             (D3DXVECTOR3 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3119     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 1);
3120 
3121     /* D3DXVec3TransformNormalArray */
3122     exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
3123     exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
3124     exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
3125     exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
3126     exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
3127     D3DXVec3TransformNormalArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec),
3128             (D3DXVECTOR3 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3129     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
3130 
3131     /* D3DXVec3ProjectArray */
3132     exp_vec[1].x = 1.08955420e+03f; exp_vec[1].y = -2.26590622e+02f; exp_vec[1].z = 2.15272754e-01f;
3133     exp_vec[2].x = 1.06890344e+03f; exp_vec[2].y =  1.03085144e+02f; exp_vec[2].z = 1.83049560e-01f;
3134     exp_vec[3].x = 1.05177905e+03f; exp_vec[3].y =  3.76462280e+02f; exp_vec[3].z = 1.56329080e-01f;
3135     exp_vec[4].x = 1.03734888e+03f; exp_vec[4].y =  6.06827393e+02f; exp_vec[4].z = 1.33812696e-01f;
3136     exp_vec[5].x = 1.02502356e+03f; exp_vec[5].y =  8.03591248e+02f; exp_vec[5].z = 1.14580572e-01f;
3137     D3DXVec3ProjectArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
3138             sizeof(*inp_vec), &viewport, &projection, &view, &world, ARRAY_SIZE(inp_vec));
3139     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 8);
3140 
3141     /* D3DXVec3UnprojectArray */
3142     exp_vec[1].x = -6.12403107e+00f; exp_vec[1].y = 3.22536016e+00f; exp_vec[1].z = 6.20571136e-01f;
3143     exp_vec[2].x = -3.80710936e+00f; exp_vec[2].y = 2.04657936e+00f; exp_vec[2].z = 4.46894377e-01f;
3144     exp_vec[3].x = -2.92283988e+00f; exp_vec[3].y = 1.59668946e+00f; exp_vec[3].z = 3.80609393e-01f;
3145     exp_vec[4].x = -2.45622563e+00f; exp_vec[4].y = 1.35928988e+00f; exp_vec[4].z = 3.45631927e-01f;
3146     exp_vec[5].x = -2.16789746e+00f; exp_vec[5].y = 1.21259713e+00f; exp_vec[5].z = 3.24018806e-01f;
3147     D3DXVec3UnprojectArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
3148             sizeof(*inp_vec), &viewport, &projection, &view, &world, ARRAY_SIZE(inp_vec));
3149     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 4);
3150 
3151     /* D3DXVec2TransformArray */
3152     exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
3153     exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
3154     exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
3155     exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
3156     exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
3157     D3DXVec2TransformArray(&out_vec[1], sizeof(*out_vec), (D3DXVECTOR2 *)inp_vec,
3158             sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3159     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
3160 
3161     /* D3DXVec3TransformArray */
3162     exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
3163     exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
3164     exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
3165     exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
3166     exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
3167     D3DXVec3TransformArray(&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
3168             sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3169     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
3170 
3171     /* D3DXVec4TransformArray */
3172     exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
3173     exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f;  exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
3174     exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f;  exp_vec[3].z = 94.0f;  exp_vec[3].w = 104.0f;
3175     exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f;  exp_vec[4].z = 86.0f;  exp_vec[4].w = 96.0f;
3176     exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f;  exp_vec[5].z = 78.0f;  exp_vec[5].w = 88.0f;
3177     D3DXVec4TransformArray(&out_vec[1], sizeof(*out_vec), inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
3178     expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
3179 
3180     /* D3DXPlaneTransformArray */
3181     exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
3182     exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f;  exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
3183     exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f;  exp_plane[3].c = 94.0f;  exp_plane[3].d = 104.0f;
3184     exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f;  exp_plane[4].c = 86.0f;  exp_plane[4].d = 96.0f;
3185     exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f;  exp_plane[5].c = 78.0f;  exp_plane[5].d = 88.0f;
3186     D3DXPlaneTransformArray(&out_plane[1], sizeof(*out_plane), inp_plane,
3187             sizeof(*inp_plane), &mat, ARRAY_SIZE(inp_plane));
3188     for (i = 0; i < ARRAY_SIZE(exp_plane); ++i)
3189     {
3190         BOOL equal = compare_plane(&exp_plane[i], &out_plane[i], 0);
3191         ok(equal, "Got unexpected plane {%.8e, %.8e, %.8e, %.8e} at index %u, expected {%.8e, %.8e, %.8e, %.8e}.\n",
3192                 out_plane[i].a, out_plane[i].b, out_plane[i].c, out_plane[i].d, i,
3193                 exp_plane[i].a, exp_plane[i].b, exp_plane[i].c, exp_plane[i].d);
3194         if (!equal)
3195             break;
3196     }
3197 }
3198 
3199 static void test_D3DXFloat_Array(void)
3200 {
3201     unsigned int i;
3202     void *out = NULL;
3203     D3DXFLOAT16 half;
3204     BOOL equal;
3205 
3206     /* Input floats through bit patterns because compilers do not generate reliable INF and NaN values. */
3207     union convert
3208     {
3209         DWORD d;
3210         float f;
3211     } single;
3212 
3213     struct
3214     {
3215         union convert single_in;
3216 
3217         /* half_ver2 occurs on WXPPROSP3 (32 bit math), WVISTAADM (32/64 bit math), W7PRO (32 bit math) */
3218         WORD half_ver1, half_ver2;
3219 
3220         /* single_out_ver2 confirms that half -> single conversion is consistent across platforms */
3221         union convert single_out_ver1, single_out_ver2;
3222     }
3223     testdata[] =
3224     {
3225         { { 0x479c4000 }, 0x7c00, 0x7ce2, { 0x47800000 }, { 0x479c4000 } }, /* 80000.0f */
3226         { { 0x477fdf00 }, 0x7bff, 0x7bff, { 0x477fe000 }, { 0x477fe000 } }, /* 65503.0f */
3227         { { 0x477fe000 }, 0x7bff, 0x7bff, { 0x477fe000 }, { 0x477fe000 } }, /* 65504.0f */
3228         { { 0x477ff000 }, 0x7bff, 0x7c00, { 0x477fe000 }, { 0x47800000 } }, /* 65520.0f */
3229         { { 0x477ff100 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65521.0f */
3230 
3231         { { 0x477ffe00 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65534.0f */
3232         { { 0x477fff00 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65535.0f */
3233         { { 0x47800000 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65536.0f */
3234         { { 0xc79c4000 }, 0xfc00, 0xfce2, { 0xc7800000 }, { 0xc79c4000 } }, /* -80000.0f */
3235         { { 0xc77fdf00 }, 0xfbff, 0xfbff, { 0xc77fe000 }, { 0xc77fe000 } }, /* -65503.0f */
3236 
3237         { { 0xc77fe000 }, 0xfbff, 0xfbff, { 0xc77fe000 }, { 0xc77fe000 } }, /* -65504.0f */
3238         { { 0xc77ff000 }, 0xfbff, 0xfc00, { 0xc77fe000 }, { 0xc7800000 } }, /* -65520.0f */
3239         { { 0xc77ff100 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65521.0f */
3240         { { 0xc77ffe00 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65534.0f */
3241         { { 0xc77fff00 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65535.0f */
3242 
3243         { { 0xc7800000 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65536.0f */
3244         { { 0x7f800000 }, 0x7c00, 0x7fff, { 0x47800000 }, { 0x47ffe000 } }, /* INF */
3245         { { 0xff800000 }, 0xffff, 0xffff, { 0xc7ffe000 }, { 0xc7ffe000 } }, /* -INF */
3246         { { 0x7fc00000 }, 0x7fff, 0xffff, { 0x47ffe000 }, { 0xc7ffe000 } }, /* NaN */
3247         { { 0xffc00000 }, 0xffff, 0xffff, { 0xc7ffe000 }, { 0xc7ffe000 } }, /* -NaN */
3248 
3249         { { 0x00000000 }, 0x0000, 0x0000, { 0x00000000 }, { 0x00000000 } }, /* 0.0f */
3250         { { 0x80000000 }, 0x8000, 0x8000, { 0x80000000 }, { 0x80000000 } }, /* -0.0f */
3251         { { 0x330007ff }, 0x0000, 0x0000, { 0x00000000 }, { 0x00000000 } }, /* 2.9809595e-08f */
3252         { { 0xb30007ff }, 0x8000, 0x8000, { 0x80000000 }, { 0x80000000 } }, /* -2.9809595e-08f */
3253         { { 0x33000800 }, 0x0001, 0x0000, { 0x33800000 }, { 0x00000000 } }, /* 2.9809598e-08f */
3254 
3255         { { 0xb3000800 }, 0x8001, 0x8000, { 0xb3800000 }, { 0x80000000 } }, /* -2.9809598e-08f */
3256         { { 0x33c00000 }, 0x0002, 0x0001, { 0x34000000 }, { 0x33800000 } }, /* 8.9406967e-08f */
3257     };
3258 
3259     /* exception on NULL out or in parameter */
3260     out = D3DXFloat32To16Array(&half, &single.f, 0);
3261     ok(out == &half, "Got %p, expected %p.\n", out, &half);
3262 
3263     out = D3DXFloat16To32Array(&single.f, &half, 0);
3264     ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
3265 
3266     for (i = 0; i < ARRAY_SIZE(testdata); ++i)
3267     {
3268         out = D3DXFloat32To16Array(&half, &testdata[i].single_in.f, 1);
3269         ok(out == &half, "Got %p, expected %p.\n", out, &half);
3270         ok(half.value == testdata[i].half_ver1 || half.value == testdata[i].half_ver2,
3271            "Got %x, expected %x or %x for index %d.\n", half.value, testdata[i].half_ver1,
3272            testdata[i].half_ver2, i);
3273 
3274         out = D3DXFloat16To32Array(&single.f, (D3DXFLOAT16 *)&testdata[i].half_ver1, 1);
3275         ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
3276         equal = compare_float(single.f, testdata[i].single_out_ver1.f, 0);
3277         ok(equal, "Got %#x, expected %#x at index %u.\n", single.d, testdata[i].single_out_ver1.d, i);
3278 
3279         out = D3DXFloat16To32Array(&single.f, (D3DXFLOAT16 *)&testdata[i].half_ver2, 1);
3280         ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
3281         equal = compare_float(single.f, testdata[i].single_out_ver2.f, 0);
3282         ok(equal, "Got %#x, expected %#x at index %u.\n", single.d, testdata[i].single_out_ver2.d, i);
3283     }
3284 }
3285 
3286 static void test_D3DXSHAdd(void)
3287 {
3288     float out[50] = {0.0f};
3289     unsigned int i, k;
3290     float *ret;
3291     BOOL equal;
3292 
3293     static const float in1[50] =
3294     {
3295         1.11f, 1.12f, 1.13f, 1.14f, 1.15f, 1.16f, 1.17f, 1.18f,
3296         1.19f, 1.20f, 1.21f, 1.22f, 1.23f, 1.24f, 1.25f, 1.26f,
3297         1.27f, 1.28f, 1.29f, 1.30f, 1.31f, 1.32f, 1.33f, 1.34f,
3298         1.35f, 1.36f, 1.37f, 1.38f, 1.39f, 1.40f, 1.41f, 1.42f,
3299         1.43f, 1.44f, 1.45f, 1.46f, 1.47f, 1.48f, 1.49f, 1.50f,
3300         1.51f, 1.52f, 1.53f, 1.54f, 1.55f, 1.56f, 1.57f, 1.58f,
3301         1.59f, 1.60f,
3302     };
3303     static const float in2[50] =
3304     {
3305         2.11f, 2.12f, 2.13f, 2.14f, 2.15f, 2.16f, 2.17f, 2.18f,
3306         2.19f, 2.20f, 2.21f, 2.22f, 2.23f, 2.24f, 2.25f, 2.26f,
3307         2.27f, 2.28f, 2.29f, 2.30f, 2.31f, 2.32f, 2.33f, 2.34f,
3308         2.35f, 2.36f, 2.37f, 2.38f, 2.39f, 2.40f, 2.41f, 2.42f,
3309         2.43f, 2.44f, 2.45f, 2.46f, 2.47f, 2.48f, 2.49f, 2.50f,
3310         2.51f, 2.52f, 2.53f, 2.54f, 2.55f, 2.56f, 2.57f, 2.58f,
3311         2.59f, 2.60f,
3312     };
3313 
3314     /*
3315      * Order is not limited by D3DXSH_MINORDER and D3DXSH_MAXORDER!
3316      * All values will work, test from 0-7 [D3DXSH_MINORDER = 2, D3DXSH_MAXORDER = 6]
3317      * Exceptions will show up when out, in1 or in2 is NULL
3318      */
3319     for (k = 0; k <= D3DXSH_MAXORDER + 1; k++)
3320     {
3321         UINT count = k * k;
3322 
3323         ret = D3DXSHAdd(&out[0], k, &in1[0], &in2[0]);
3324         ok(ret == out, "%u: D3DXSHAdd() failed, got %p, expected %p\n", k, out, ret);
3325 
3326         for (i = 0; i < count; ++i)
3327         {
3328             equal = compare_float(in1[i] + in2[i], out[i], 0);
3329             ok(equal, "%u-%u: Got %.8e, expected %.8e.\n", k, i, out[i], in1[i] + in2[i]);
3330         }
3331         equal = compare_float(out[count], 0.0f, 0);
3332         ok(equal, "%u-%u: Got %.8e, expected 0.0.\n", k, k * k, out[count]);
3333     }
3334 }
3335 
3336 static void test_D3DXSHDot(void)
3337 {
3338     float a[49], b[49], got;
3339     unsigned int i;
3340     BOOL equal;
3341 
3342     static const float expected[] = {0.5f, 0.5f, 25.0f, 262.5f, 1428.0f, 5362.5f, 15873.0f, 39812.5f};
3343 
3344     for (i = 0; i < ARRAY_SIZE(a); ++i)
3345     {
3346         a[i] = i + 1.0f;
3347         b[i] = i + 0.5f;
3348     }
3349 
3350     /* D3DXSHDot computes by using order * order elements */
3351     for (i = 0; i <= D3DXSH_MAXORDER + 1; i++)
3352     {
3353         got = D3DXSHDot(i, a, b);
3354         equal = compare_float(got, expected[i], 0);
3355         ok(equal, "order %u: Got %.8e, expected %.8e.\n", i, got, expected[i]);
3356     }
3357 }
3358 
3359 static void test_D3DXSHEvalConeLight(void)
3360 {
3361     float bout[49], expected, gout[49], rout[49];
3362     unsigned int j, l, order;
3363     D3DXVECTOR3 dir;
3364     HRESULT hr;
3365     BOOL equal;
3366 
3367     static const float table[] =
3368     {
3369     /* Red colour */
3370         1.604815f, -3.131381f, 7.202175f, -2.870432f, 6.759296f, -16.959688f,
3371         32.303082f, -15.546381f, -0.588878f, -5.902123f, 40.084042f, -77.423569f,
3372         137.556320f, -70.971603f, -3.492171f, 7.683092f, -2.129311f, -35.971344f,
3373         183.086548f, -312.414948f, 535.091064f, -286.380371f, -15.950727f, 46.825714f,
3374         -12.127637f, 11.289261f, -12.417809f, -155.039566f, 681.182556f, -1079.733643f,
3375         1807.650513f, -989.755798f, -59.345467f, 201.822815f, -70.726486f, 7.206529f,
3376 
3377         3.101155f, -3.128710f, 7.196033f, -2.867984f, -0.224708f, 0.563814f,
3378         -1.073895f, 0.516829f, 0.019577f, 2.059788f, -13.988971f, 27.020128f,
3379         -48.005917f, 24.768450f, 1.218736f, -2.681329f, -0.088639f, -1.497410f,
3380         7.621501f, -13.005165f, 22.274696f, -11.921401f, -0.663995f, 1.949254f,
3381         -0.504848f, 4.168484f, -4.585193f, -57.247314f, 251.522095f, -398.684387f,
3382         667.462891f, -365.460693f, -21.912912f, 74.521721f, -26.115280f, 2.660963f,
3383     /* Green colour */
3384         2.454422f, -4.789170f, 11.015091f, -4.390072f, 10.337747f, -25.938347f,
3385         49.404713f, -23.776817f, -0.900637f, -9.026776f, 61.305000f, -118.412514f,
3386         210.380249f, -108.544792f, -5.340967f, 11.750610f, -3.256593f, -55.014996f,
3387         280.014709f, -477.811066f, 818.374512f, -437.993469f, -24.395227f, 71.615799f,
3388         -18.548151f, 17.265928f, -18.991943f, -237.119324f, 1041.808594f, -1651.357300f,
3389         2764.642090f, -1513.744141f, -90.763657f, 308.670197f, -108.169922f, 11.021750f,
3390 
3391         4.742942f, -4.785086f, 11.005697f, -4.386329f, -0.343672f, 0.862303f,
3392         -1.642427f, 0.790444f, 0.029941f, 3.150264f, -21.394896f, 41.324898f,
3393         -73.420807f, 37.881153f, 1.863950f, -4.100857f, -0.135565f, -2.290156f,
3394         11.656413f, -19.890251f, 34.067181f, -18.232729f, -1.015521f, 2.981212f,
3395         -0.772120f, 6.375328f, -7.012648f, -87.554710f, 384.680817f, -609.752563f,
3396         1020.825500f, -558.939819f, -33.513863f, 113.974388f, -39.941013f, 4.069707f,
3397     /* Blue colour */
3398         3.304030f, -6.446959f, 14.828006f, -5.909713f, 13.916198f, -34.917004f,
3399         66.506340f, -32.007256f, -1.212396f, -12.151429f, 82.525963f, -159.401459f,
3400         283.204193f, -146.117996f, -7.189764f, 15.818130f, -4.383876f, -74.058655f,
3401         376.942871f, -643.207214f, 1101.658081f, -589.606628f, -32.839729f, 96.405884f,
3402         -24.968664f, 23.242596f, -25.566080f, -319.199097f, 1402.434692f, -2222.980957f,
3403         3721.633545f, -2037.732544f, -122.181847f, 415.517578f, -145.613358f, 14.836972f,
3404 
3405         6.384730f, -6.441462f, 14.815362f, -5.904673f, -0.462635f, 1.160793f,
3406         -2.210959f, 1.064060f, 0.040305f, 4.240739f, -28.800821f, 55.629673f,
3407         -98.835709f, 50.993862f, 2.509163f, -5.520384f, -0.182491f, -3.082903f,
3408         15.691326f, -26.775339f, 45.859665f, -24.544060f, -1.367048f, 4.013170f,
3409         -1.039392f, 8.582172f, -9.440103f, -117.862114f, 517.839600f, -820.820740f,
3410         1374.188232f, -752.419067f, -45.114819f, 153.427063f, -53.766754f, 5.478452f, };
3411     const struct
3412     {
3413         float *red_received, *green_received, *blue_received;
3414         const float *red_expected, *green_expected, *blue_expected;
3415         float radius, roffset, goffset, boffset;
3416     }
3417     test[] =
3418     {
3419         { rout, gout, bout, table, &table[72], &table[144], 0.5f, 1.01f, 1.02f, 1.03f, },
3420         { rout, gout, bout, &table[36], &table[108], &table[180], 1.6f, 1.01f, 1.02f, 1.03f, },
3421         { rout, rout, rout, &table[144], &table[144], &table[144], 0.5f, 1.03f, 1.03f, 1.03f, },
3422         { rout, rout, bout, &table[72], &table[72], &table[144], 0.5, 1.02f, 1.02f, 1.03f, },
3423         { rout, gout, gout, table, &table[144], &table[144], 0.5f, 1.01f, 1.03f, 1.03f, },
3424         { rout, gout, rout, &table[144], &table[72], &table[144], 0.5f, 1.03f, 1.02f, 1.03f, },
3425     /* D3DXSHEvalConeLight accepts NULL green or blue colour. */
3426         { rout, NULL, bout, table, NULL, &table[144], 0.5f, 1.01f, 0.0f, 1.03f, },
3427         { rout, gout, NULL, table, &table[72], NULL, 0.5f, 1.01f, 1.02f, 0.0f, },
3428         { rout, NULL, NULL, table, NULL, NULL, 0.5f, 1.01f, 0.0f, 0.0f, },
3429     };
3430 
3431     dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
3432 
3433     for (l = 0; l < ARRAY_SIZE(test); ++l)
3434     {
3435         for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3436         {
3437             for (j = 0; j < 49; j++)
3438             {
3439                 test[l].red_received[j] = 1.01f + j;
3440                 if (test[l].green_received)
3441                     test[l].green_received[j] = 1.02f + j;
3442                 if (test[l].blue_received)
3443                     test[l].blue_received[j] = 1.03f + j;
3444             }
3445 
3446             hr = D3DXSHEvalConeLight(order, &dir, test[l].radius, 1.7f, 2.6f, 3.5f, test[l].red_received, test[l].green_received, test[l].blue_received);
3447             ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3448 
3449             for (j = 0; j < 49; j++)
3450             {
3451                 if (j >= order * order)
3452                     expected = j + test[l].roffset;
3453                 else
3454                     expected = test[l].red_expected[j];
3455                 equal = compare_float(test[l].red_received[j], expected, 128);
3456                 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3457                         l, order, j, expected, test[l].red_received[j]);
3458 
3459                 if (test[l].green_received)
3460                 {
3461                     if (j >= order * order)
3462                         expected = j + test[l].goffset;
3463                     else
3464                         expected = test[l].green_expected[j];
3465                     equal = compare_float(test[l].green_received[j], expected, 64);
3466                     ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3467                             l, order, j, expected, test[l].green_received[j]);
3468                 }
3469 
3470                 if (test[l].blue_received)
3471                 {
3472                     if (j >= order * order)
3473                         expected = j + test[l].boffset;
3474                     else
3475                         expected = test[l].blue_expected[j];
3476                     equal = compare_float(test[l].blue_received[j], expected, 128);
3477                     ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3478                             l, order, j, expected, test[l].blue_received[j]);
3479                 }
3480             }
3481         }
3482     }
3483 
3484     /* Cone light with radius <= 0.0f behaves as a directional light */
3485     for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3486     {
3487         FLOAT blue[49], green[49], red[49];
3488 
3489         for (j = 0; j < 49; j++)
3490         {
3491             rout[j] = 1.01f + j;
3492             gout[j] = 1.02f + j;
3493             bout[j] = 1.03f + j;
3494             red[j] = 1.01f + j;
3495             green[j] = 1.02f + j;
3496             blue[j] = 1.03f + j;
3497         }
3498 
3499         hr = D3DXSHEvalConeLight(order, &dir, -0.1f, 1.7f, 2.6f, 3.5f, rout, gout, bout);
3500         ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3501         D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red, green, blue);
3502 
3503         for (j = 0; j < 49; j++)
3504         {
3505             equal = compare_float(red[j], rout[j], 0);
3506             ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3507                     l, order, j, red[j], rout[j]);
3508 
3509             equal = compare_float(green[j], gout[j], 0);
3510             ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3511                     l, order, j, green[j], gout[j]);
3512 
3513             equal = compare_float(blue[j], bout[j], 0);
3514             ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3515                     l, order, j, blue[j], bout[j]);
3516         }
3517     }
3518 
3519     /* D3DXSHEvalConeLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
3520     hr = D3DXSHEvalConeLight(7, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3521     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3522     hr = D3DXSHEvalConeLight(0, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3523     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3524     hr = D3DXSHEvalConeLight(1, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3525     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3526 }
3527 
3528 static void test_D3DXSHEvalDirection(void)
3529 {
3530     float a[49], expected, *received_ptr;
3531     unsigned int i, order;
3532     D3DXVECTOR3 d;
3533     BOOL equal;
3534 
3535     static const float table[36] =
3536     {
3537          2.82094806e-01f, -9.77205038e-01f,  1.46580756e+00f, -4.88602519e-01f,  2.18509698e+00f, -6.55529118e+00f,
3538          8.20018101e+00f, -3.27764559e-00f, -1.63882279e+00f,  1.18008721e+00f,  1.73436680e+01f, -4.02200317e+01f,
3539          4.70202179e+01f, -2.01100159e+01f, -1.30077515e+01f,  6.49047947e+00f, -1.50200577e+01f,  1.06207848e+01f,
3540          1.17325661e+02f, -2.40856750e+02f,  2.71657288e+02f, -1.20428375e+02f, -8.79942474e+01f,  5.84143143e+01f,
3541         -4.38084984e+00f,  2.49425201e+01f, -1.49447693e+02f,  7.82781296e+01f,  7.47791748e+02f, -1.42768787e+03f,
3542          1.57461914e+03f, -7.13843933e+02f, -5.60843811e+02f,  4.30529724e+02f, -4.35889091e+01f, -2.69116650e+01f,
3543     };
3544 
3545     d.x = 1.0; d.y = 2.0f; d.z = 3.0f;
3546 
3547     for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
3548     {
3549         for (i = 0; i < ARRAY_SIZE(a); ++i)
3550             a[i] = 1.5f + i;
3551 
3552         received_ptr = D3DXSHEvalDirection(a, order, &d);
3553         ok(received_ptr == a, "Expected %p, received %p\n", a, received_ptr);
3554 
3555         for (i = 0; i < ARRAY_SIZE(a); ++i)
3556         {
3557             /* if the order is < D3DXSH_MINORDER or order > D3DXSH_MAXORDER or
3558              * the index of the element is greater than order * order - 1,
3559              * D3DXSHEvalDirection() does not modify the output. */
3560             if ((order < D3DXSH_MINORDER) || (order > D3DXSH_MAXORDER) || (i >= order * order))
3561                 expected = 1.5f + i;
3562             else
3563                 expected = table[i];
3564 
3565             equal = compare_float(a[i], expected, 2);
3566             ok(equal, "order %u, index %u: Got unexpected result %.8e, expected %.8e.\n",
3567                     order, i, a[i], expected);
3568         }
3569     }
3570 }
3571 
3572 static void test_D3DXSHEvalDirectionalLight(void)
3573 {
3574     float *blue_out, bout[49], expected, gout[49], *green_out, *red_out, rout[49];
3575     unsigned int j, l, order, startindex;
3576     D3DXVECTOR3 dir;
3577     HRESULT hr;
3578     BOOL equal;
3579 
3580     static const float table[] =
3581     {
3582     /* Red colour */
3583       2.008781f, -4.175174f, 9.602900f, -3.827243f, 1.417963f, -2.947181f,
3584       6.778517f, -2.701583f, 7.249108f, -18.188671f, 34.643921f, -16.672949f,
3585       -0.631551f, 1.417963f, -2.947181f, 6.778517f, -2.701583f, 7.249108f,
3586       -18.188671f, 34.643921f, -16.672949f, -0.631551f, -7.794341f, 52.934967f,
3587       -102.245529f, 181.656815f, -93.725060f, -4.611760f, 10.146287f, 1.555186f,
3588       -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f, 37.996559f,
3589       -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f, 199.236496f,
3590       -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f, 360.268829f,
3591       -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f, -23.864176f,
3592       1.555186f, -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f,
3593       37.996559f, -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f,
3594       199.236496f, -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f,
3595       360.268829f, -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f,
3596       -23.864176f, 34.868664f, -38.354366f, -478.864166f, 2103.939941f, -3334.927734f,
3597       5583.213867f, -3057.017090f, -183.297836f, 623.361633f, -218.449921f, 22.258503f,
3598     /* Green colour */
3599       3.072254f, -6.385560f, 14.686787f, -5.853429f, 2.168650f, -4.507453f,
3600       10.367143f, -4.131832f, 11.086870f, -27.817965f, 52.984818f, -25.499800f,
3601       -0.965902f, 2.168650f, -4.507453f, 10.367143f, -4.131832f, 11.086870f,
3602       -27.817965f, 52.984818f, -25.499800f, -0.965902f, -11.920755f, 80.959351f,
3603       -156.375488f, 277.828033f, -143.344193f, -7.053278f, 15.517849f, 2.378519f,
3604       -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f, 58.112385f,
3605       -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f, 304.714630f,
3606       -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f, 550.999390f,
3607       -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f, -36.498150f,
3608       2.378519f, -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f,
3609       58.112385f, -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f,
3610       304.714630f, -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f,
3611       550.999390f, -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f,
3612       -36.498150f, 53.328545f, -58.659618f, -732.380493f, 3217.790283f, -5100.477539f,
3613       8539.033203f, -4675.437500f, -280.337860f, 953.376587f, -334.099884f, 34.042416f,
3614     /* Blue colour */
3615       4.135726f, -8.595945f, 19.770674f, -7.879617f, 2.919336f, -6.067726f,
3616       13.955770f, -5.562082f, 14.924634f, -37.447262f, 71.325722f, -34.326656f,
3617       -1.300252f, 2.919336f, -6.067726f, 13.955770f, -5.562082f, 14.924634f,
3618       -37.447262f, 71.325722f, -34.326656f, -1.300252f, -16.047173f, 108.983749f,
3619       -210.505493f, 373.999298f, -192.963348f, -9.494799f, 20.889414f, 3.201853f,
3620       -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f, 78.228210f,
3621       -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f, 410.192780f,
3622       -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f, 741.729919f,
3623       -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f, -49.132126f,
3624       3.201853f, -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f,
3625       78.228210f, -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f,
3626       410.192780f, -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f,
3627       741.729919f, -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f,
3628       -49.132126f, 71.788422f, -78.964867f, -985.896790f, 4331.640625f, -6866.027344f,
3629       11494.852539f, -6293.858398f, -377.377899f, 1283.391479f, -449.749817f, 45.826328f, };
3630     const struct
3631     {
3632         float *red_in, *green_in, *blue_in;
3633         const float *red_out, *green_out, *blue_out;
3634         float roffset, goffset, boffset;
3635     }
3636     test[] =
3637     {
3638       { rout, gout, bout, table, &table[90], &table[180], 1.01f, 1.02f, 1.03f, },
3639       { rout, rout, rout, &table[180], &table[180], &table[180], 1.03f, 1.03f, 1.03f, },
3640       { rout, rout, bout, &table[90], &table[90], &table[180], 1.02f, 1.02f, 1.03f, },
3641       { rout, gout, gout, table, &table[180], &table[180], 1.01f, 1.03f, 1.03f, },
3642       { rout, gout, rout, &table[180], &table[90], &table[180], 1.03f, 1.02f, 1.03f, },
3643     /* D3DXSHEvalDirectionaLight accepts NULL green or blue colour. */
3644       { rout, NULL, bout, table, NULL, &table[180], 1.01f, 0.0f, 1.03f, },
3645       { rout, gout, NULL, table, &table[90], NULL, 1.01f, 1.02f, 0.0f, },
3646       { rout, NULL, NULL, table, NULL, NULL, 1.01f, 0.0f, 0.0f, },
3647     };
3648 
3649     dir.x = 1.1f; dir.y= 1.2f; dir.z = 2.76f;
3650 
3651     for (l = 0; l < ARRAY_SIZE(test); ++l)
3652     {
3653         startindex = 0;
3654 
3655         for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3656         {
3657             red_out = test[l].red_in;
3658             green_out = test[l].green_in;
3659             blue_out = test[l].blue_in;
3660 
3661             for (j = 0; j < ARRAY_SIZE(rout); ++j)
3662             {
3663                 red_out[j] = 1.01f + j;
3664                 if ( green_out )
3665                     green_out[j] = 1.02f + j;
3666                 if ( blue_out )
3667                     blue_out[j] = 1.03f + j;
3668             }
3669 
3670             hr = D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red_out, green_out, blue_out);
3671             ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3672 
3673             for (j = 0; j < ARRAY_SIZE(rout); ++j)
3674             {
3675                 if ( j >= order * order )
3676                     expected = j + test[l].roffset;
3677                 else
3678                     expected = test[l].red_out[startindex + j];
3679                 equal = compare_float(expected, red_out[j], 8);
3680                 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3681                         l, order, j, expected, red_out[j]);
3682 
3683                 if ( green_out )
3684                 {
3685                     if ( j >= order * order )
3686                         expected = j + test[l].goffset;
3687                     else
3688                         expected = test[l].green_out[startindex + j];
3689                     equal = compare_float(expected, green_out[j], 8);
3690                     ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3691                             l, order, j, expected, green_out[j]);
3692                 }
3693 
3694                 if ( blue_out )
3695                 {
3696                     if ( j >= order * order )
3697                         expected = j + test[l].boffset;
3698                     else
3699                         expected = test[l].blue_out[startindex + j];
3700                     equal = compare_float(expected, blue_out[j], 4);
3701                     ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3702                             l, order, j, expected, blue_out[j]);
3703                 }
3704             }
3705 
3706             startindex += order * order;
3707         }
3708     }
3709 
3710     /* D3DXSHEvalDirectionalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set*/
3711     hr = D3DXSHEvalDirectionalLight(7, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3712     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3713     hr = D3DXSHEvalDirectionalLight(0, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3714     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3715     hr = D3DXSHEvalDirectionalLight(1, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3716     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3717 }
3718 
3719 static void test_D3DXSHEvalHemisphereLight(void)
3720 {
3721     float bout[49], expected, gout[49], rout[49];
3722     unsigned int j, l, order;
3723     D3DXCOLOR bottom, top;
3724     D3DXVECTOR3 dir;
3725     HRESULT hr;
3726     BOOL equal;
3727 
3728     static const float table[] =
3729     {
3730         /* Red colour. */
3731         23.422981f, 15.859521f, -36.476898f, 14.537894f,
3732         /* Green colour. */
3733         19.966694f,  6.096982f, -14.023058f,  5.588900f,
3734         /* Blue colour. */
3735         24.566214f,  8.546826f, -19.657701f,  7.834591f,
3736     };
3737     const struct
3738     {
3739         float *red_received, *green_received, *blue_received;
3740         const float *red_expected, *green_expected, *blue_expected;
3741         const float roffset, goffset, boffset;
3742     }
3743     test[] =
3744     {
3745         { rout, gout, bout, table, &table[4], &table[8], 1.01f, 1.02f, 1.03f, },
3746         { rout, rout, rout, &table[8], &table[8], &table[8], 1.03f, 1.03f, 1.03f, },
3747         { rout, rout, bout, &table[4], &table[4], &table[8], 1.02f, 1.02f, 1.03f, },
3748         { rout, gout, gout, table, &table[8], &table[8], 1.01f, 1.03f, 1.03f, },
3749         { rout, gout, rout, &table[8], &table[4], &table[8], 1.03f, 1.02f, 1.03f, },
3750     /* D3DXSHEvalHemisphereLight accepts NULL green or blue colour. */
3751         { rout, NULL, bout, table, NULL, &table[8], 1.01f, 1.02f, 1.03f, },
3752         { rout, gout, NULL, table, &table[4], NULL, 1.01f, 1.02f, 1.03f, },
3753         { rout, NULL, NULL, table, NULL, NULL, 1.01f, 1.02f, 1.03f, },
3754     };
3755 
3756     dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
3757     top.r = 0.1f; top.g = 2.1f; top.b = 2.3f; top.a = 4.3f;
3758     bottom.r = 8.71f; bottom.g = 5.41f; bottom.b = 6.94f; bottom.a = 8.43f;
3759 
3760     for (l = 0; l < ARRAY_SIZE(test); ++l)
3761         for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER + 1; order++)
3762         {
3763             for (j = 0; j < 49; j++)
3764             {
3765                 test[l].red_received[j] = 1.01f + j;
3766                 if (test[l].green_received)
3767                     test[l].green_received[j] = 1.02f + j;
3768                 if (test[l].blue_received)
3769                     test[l].blue_received[j] = 1.03f + j;
3770             }
3771 
3772             hr = D3DXSHEvalHemisphereLight(order, &dir, top, bottom, test[l].red_received, test[l].green_received, test[l].blue_received);
3773             ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3774 
3775             for (j = 0; j < 49; j++)
3776             {
3777                 if (j < 4)
3778                     expected = test[l].red_expected[j];
3779                 else if (j < order * order)
3780                      expected = 0.0f;
3781                 else
3782                     expected = test[l].roffset + j;
3783                 equal = compare_float(test[l].red_received[j], expected, 4);
3784                 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3785                         l, order, j, expected, test[l].red_received[j]);
3786 
3787                 if (test[l].green_received)
3788                 {
3789                     if (j < 4)
3790                         expected = test[l].green_expected[j];
3791                     else if (j < order * order)
3792                          expected = 0.0f;
3793                     else
3794                          expected = test[l].goffset + j;
3795                     equal = compare_float(expected, test[l].green_received[j], 4);
3796                     ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3797                             l, order, j, expected, test[l].green_received[j]);
3798                 }
3799 
3800                 if (test[l].blue_received)
3801                 {
3802                     if (j < 4)
3803                         expected = test[l].blue_expected[j];
3804                     else if (j < order * order)
3805                         expected = 0.0f;
3806                     else
3807                         expected = test[l].boffset + j;
3808                     equal = compare_float(expected, test[l].blue_received[j], 4);
3809                     ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3810                             l, order, j, expected, test[l].blue_received[j]);
3811                 }
3812             }
3813         }
3814 }
3815 
3816 static void test_D3DXSHEvalSphericalLight(void)
3817 {
3818     float bout[49], expected, gout[49], rout[49];
3819     unsigned int j, l, order;
3820     D3DXVECTOR3 dir;
3821     HRESULT hr;
3822     BOOL equal;
3823 
3824     static const float table[] =
3825     {
3826         /* Red colour. */
3827          3.01317163e+00f, -9.77240128e-01f,  2.24765220e+00f, -8.95803434e-01f,  3.25255224e-35f, -8.16094904e-35f,
3828          8.95199460e-35f, -7.48086982e-35f, -2.83366352e-36f,  6.29281376e-02f, -4.27374053e-01f,  6.19212543e-01f,
3829         -3.04508915e-01f,  5.67611487e-01f,  3.72333533e-02f, -8.19167317e-02f,  1.25205729e-36f,  2.11515287e-35f,
3830         -8.85884025e-35f,  8.22100105e-35f, -1.41290744e-37f,  7.53591749e-35f,  7.71793061e-36f, -2.75340121e-35f,
3831          7.13117824e-36f,  1.24992691e-02f, -1.37487792e-02f, -1.48109290e-01f,  4.34345843e-01f, -2.45986100e-01f,
3832         -1.51757946e-01f, -2.25487254e-01f, -3.78407442e-02f,  1.92801335e-01f, -7.83071154e-02f,  7.97894137e-03f,
3833 
3834          4.02519645e-01f, -2.43653315e-01f,  5.60402600e-01f, -2.23348868e-01f,  1.62046875e-01f, -4.06590330e-01f,
3835          4.46001368e-01f, -3.72707796e-01f, -1.41177231e-02f, -4.31995198e-02f,  2.93387896e-01f, -4.25083048e-01f,
3836          2.09042241e-01f, -3.89659453e-01f, -2.55603144e-02f,  5.62349945e-02f, -4.68822967e-03f, -7.92002290e-02f,
3837          3.31712278e-01f, -3.07828893e-01f,  5.29052032e-04f, -2.82176480e-01f, -2.88991817e-02f,  1.03098934e-01f,
3838         -2.67021338e-02f,  7.24339502e-03f, -7.96749298e-03f, -8.58301461e-02f,  2.51705799e-01f, -1.42550295e-01f,
3839         -8.79445626e-02f, -1.30671101e-01f, -2.19289189e-02f,  1.11729432e-01f, -4.53794030e-02f,  4.62384030e-03f,
3840 
3841          1.95445306e+00f, -8.56593659e-01f,  1.97016533e+00f, -7.85210840e-01f,  2.31033385e-01f, -5.79683751e-01f,
3842          6.35872835e-01f, -5.31376762e-01f, -2.01279127e-02f,  2.11104646e-02f, -1.43370917e-01f,  2.07726860e-01f,
3843         -1.02153423e-01f,  1.90416285e-01f,  1.24906507e-02f, -2.74805568e-02f,  6.33162467e-03f,  1.06962790e-01f,
3844         -4.47989495e-01f,  4.15734115e-01f, -7.14504011e-04f,  3.81089599e-01f,  3.90293960e-02f, -1.39238860e-01f,
3845          3.60622028e-02f, -4.47359268e-03f,  4.92080277e-03f,  5.30095505e-02f, -1.55456001e-01f,  8.80404774e-02f,
3846          5.43154350e-02f,  8.07037695e-02f,  1.35435180e-02f, -6.90052063e-02f,  2.80267699e-02f, -2.85572968e-03f,
3847         /* Green colour. */
3848          4.60837984e+00f, -1.49460245e+00f,  3.43758549e+00f, -1.37005222e+00f,  4.97449134e-35f, -1.24814507e-34f,
3849          1.36912850e-34f, -1.14413296e-34f, -4.33383805e-36f,  9.62430278e-02f, -6.53630863e-01f,  9.47030887e-01f,
3850         -4.65719486e-01f,  8.68111630e-01f,  5.69451249e-02f, -1.25284405e-01f,  1.91491103e-36f,  3.23493947e-35f,
3851         -1.35488136e-34f,  1.25732949e-34f, -2.16091711e-37f,  1.15255201e-34f,  1.18038931e-35f, -4.21108392e-35f,
3852          1.09065072e-35f,  1.91165280e-02f, -2.10275433e-02f, -2.26520076e-01f,  6.64293599e-01f, -3.76214011e-01f,
3853         -2.32100374e-01f, -3.44862837e-01f, -5.78740756e-02f,  2.94872611e-01f, -1.19763816e-01f,  1.22030860e-02f,
3854 
3855          6.15618240e-01f, -3.72646222e-01f,  8.57086273e-01f, -3.41592364e-01f,  2.47836381e-01f, -6.21843994e-01f,
3856          6.82119695e-01f, -5.70023651e-01f, -2.15918104e-02f, -6.60698496e-02f,  4.48710870e-01f, -6.50126972e-01f,
3857          3.19711642e-01f, -5.95949713e-01f, -3.90922430e-02f,  8.60064566e-02f, -7.17023314e-03f, -1.21129754e-01f,
3858          5.07324627e-01f, -4.70797100e-01f,  8.09138350e-04f, -4.31564000e-01f, -4.41987457e-02f,  1.57680712e-01f,
3859         -4.08385549e-02f,  1.10781328e-02f, -1.21855767e-02f, -1.31269627e-01f,  3.84961785e-01f, -2.18018084e-01f,
3860         -1.34503440e-01f, -1.99849906e-01f, -3.35383443e-02f,  1.70880296e-01f, -6.94037884e-02f,  7.07175529e-03f,
3861 
3862          2.98916331e+00f, -1.31008433e+00f,  3.01319384e+00f, -1.20091062e+00f,  3.53345154e-01f, -8.86575090e-01f,
3863          9.72511332e-01f, -8.12693818e-01f, -3.07838645e-02f,  3.22865908e-02f, -2.19273153e-01f,  3.17699883e-01f,
3864         -1.56234637e-01f,  2.91224888e-01f,  1.91033469e-02f, -4.20290842e-02f,  9.68366064e-03f,  1.63590138e-01f,
3865         -6.85160360e-01f,  6.35828606e-01f, -1.09277077e-03f,  5.82842878e-01f,  5.96920135e-02f, -2.12953537e-01f,
3866          5.51539537e-02f, -6.84196484e-03f,  7.52593316e-03f,  8.10734249e-02f, -2.37756221e-01f,  1.34650133e-01f,
3867          8.30706600e-02f,  1.23429287e-01f,  2.07136145e-02f, -1.05537368e-01f,  4.28644688e-02f, -4.36758628e-03f,
3868         /* Blue colour. */
3869          6.20358848e+00f, -2.01196491e+00f,  4.62751910e+00f, -1.84430114e+00f,  6.69643089e-35f, -1.68019534e-34f,
3870          1.84305766e-34f, -1.54017904e-34f, -5.83401297e-36f,  1.29557927e-01f, -8.79887732e-01f,  1.27484932e+00f,
3871         -6.26930101e-01f,  1.16861185e+00f,  7.66569017e-02f, -1.68652090e-01f,  2.57776494e-36f,  4.35472637e-35f,
3872         -1.82387882e-34f,  1.69255899e-34f, -2.90892699e-37f,  1.55151238e-34f,  1.58898567e-35f, -5.66876703e-35f,
3873          1.46818371e-35f,  2.57337886e-02f, -2.83063093e-02f, -3.04930882e-01f,  8.94241416e-01f, -5.06441957e-01f,
3874         -3.12442822e-01f, -4.64238452e-01f, -7.79074123e-02f,  3.96943914e-01f, -1.61220527e-01f,  1.64272318e-02f,
3875 
3876          8.28716892e-01f, -5.01639163e-01f,  1.15377003e+00f, -4.59835891e-01f,  3.33625909e-01f, -8.37097715e-01f,
3877          9.18238085e-01f, -7.67339558e-01f, -2.90658997e-02f, -8.89401854e-02f,  6.04033886e-01f, -8.75170956e-01f,
3878          4.30381072e-01f, -8.02240028e-01f, -5.26241753e-02f,  1.15777927e-01f, -9.65223728e-03f, -1.63059290e-01f,
3879          6.82937023e-01f, -6.33765350e-01f,  1.08922474e-03f, -5.80951560e-01f, -5.94983136e-02f,  2.12262505e-01f,
3880         -5.49749798e-02f,  1.49128717e-02f, -1.64036616e-02f, -1.76709119e-01f,  5.18217807e-01f, -2.93485893e-01f,
3881         -1.81062330e-01f, -2.69028730e-01f, -4.51477729e-02f,  2.30031176e-01f, -9.34281801e-02f,  9.51967094e-03f,
3882 
3883          4.02387383e+00f, -1.76357513e+00f,  4.05622263e+00f, -1.61661051e+00f,  4.75656955e-01f, -1.19346651e+00f,
3884          1.30914992e+00f, -1.09401095e+00f, -4.14398191e-02f,  4.34627200e-02f, -2.95175409e-01f,  4.27672935e-01f,
3885         -2.10315865e-01f,  3.92033517e-01f,  2.57160448e-02f, -5.65776154e-02f,  1.30356975e-02f,  2.20217502e-01f,
3886         -9.22331288e-01f,  8.55923154e-01f, -1.47103763e-03f,  7.84596211e-01f,  8.03546365e-02f, -2.86668233e-01f,
3887          7.42457096e-02f, -9.21033762e-03f,  1.01310642e-02f,  1.09137307e-01f, -3.20056463e-01f,  1.81259801e-01f,
3888          1.11825893e-01f,  1.66154815e-01f,  2.78837128e-02f, -1.42069538e-01f,  5.77021717e-02f, -5.87944329e-03f,
3889     };
3890     const struct
3891     {
3892         float *red_received, *green_received, *blue_received;
3893         const float *red_expected, *green_expected, *blue_expected;
3894         float radius, roffset, goffset, boffset;
3895     }
3896     test[] =
3897     {
3898         { rout, gout, bout, table, &table[108], &table[216], 17.4f, 1.01f, 1.02f, 1.03f, },
3899         { rout, gout, bout, &table[36], &table[144], &table[252], 1.6f, 1.01f, 1.02f, 1.03f, },
3900         { rout, gout, bout, &table[72], &table[180], &table[288], -3.0f, 1.01f, 1.02f, 1.03f, },
3901         { rout, rout, rout, &table[216], &table[216], &table[216], 17.4f, 1.03f, 1.03f, 1.03f, },
3902         { rout, rout, bout, &table[108], &table[108], &table[216], 17.4, 1.02f, 1.02f, 1.03f, },
3903         { rout, gout, gout, table, &table[216], &table[216], 17.4f, 1.01f, 1.03f, 1.03f, },
3904         { rout, gout, rout, &table[216], &table[108], &table[216], 17.4f, 1.03f, 1.02f, 1.03f, },
3905     /* D3DXSHEvalSphericalLight accepts NULL green or blue colour. */
3906         { rout, NULL, bout, table, NULL, &table[216], 17.4f, 1.01f, 0.0f, 1.03f, },
3907         { rout, gout, NULL, table, &table[108], NULL, 17.4f, 1.01f, 1.02f, 0.0f, },
3908         { rout, NULL, NULL, table, NULL, NULL, 17.4f, 1.01f, 0.0f, 0.0f, },
3909     };
3910 
3911     dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
3912 
3913     for (l = 0; l < ARRAY_SIZE(test); ++l)
3914     {
3915         for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3916         {
3917             for (j = 0; j < 49; j++)
3918             {
3919                 test[l].red_received[j] = 1.01f + j;
3920                 if (test[l].green_received)
3921                     test[l].green_received[j] = 1.02f + j;
3922                 if (test[l].blue_received)
3923                     test[l].blue_received[j] = 1.03f + j;
3924             }
3925 
3926             hr = D3DXSHEvalSphericalLight(order, &dir, test[l].radius, 1.7f, 2.6f, 3.5f, test[l].red_received, test[l].green_received, test[l].blue_received);
3927             ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3928 
3929             for (j = 0; j < 49; j++)
3930             {
3931                 if (j >= order * order)
3932                     expected = j + test[l].roffset;
3933                 else
3934                     expected = test[l].red_expected[j];
3935                 equal = compare_float(expected, test[l].red_received[j], 4096);
3936                 ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].red_received[j]) < 1.0e-6f),
3937                         "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3938                         l, order, j, expected, test[l].red_received[j]);
3939 
3940                 if (test[l].green_received)
3941                 {
3942                     if (j >= order * order)
3943                         expected = j + test[l].goffset;
3944                     else
3945                         expected = test[l].green_expected[j];
3946                     equal = compare_float(expected, test[l].green_received[j], 4096);
3947                     ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].green_received[j]) < 1.0e-6f),
3948                             "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3949                             l, order, j, expected, test[l].green_received[j]);
3950                 }
3951 
3952                 if (test[l].blue_received)
3953                 {
3954                     if (j >= order * order)
3955                         expected = j + test[l].boffset;
3956                     else
3957                         expected = test[l].blue_expected[j];
3958                     equal = compare_float(expected, test[l].blue_received[j], 4096);
3959                     ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].blue_received[j]) < 1.0e-6f),
3960                             "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3961                             l, order, j, expected, test[l].blue_received[j]);
3962                 }
3963             }
3964         }
3965     }
3966 
3967     /* D3DXSHEvalSphericalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
3968     hr = D3DXSHEvalSphericalLight(7, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3969     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3970     hr = D3DXSHEvalSphericalLight(0, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3971     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3972     hr = D3DXSHEvalSphericalLight(1, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3973     ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3974 }
3975 
3976 static void test_D3DXSHMultiply2(void)
3977 {
3978     float a[20], b[20], c[20];
3979     unsigned int i;
3980     BOOL equal;
3981 
3982     /* D3DXSHMultiply2() only modifies the first 4 elements of the array. */
3983     static const float expected[20] =
3984     {
3985          3.41859412f,  1.69821072f,  1.70385253f,  1.70949447f,  4.0f,  5.0f,  6.0f,
3986                 7.0f,         8.0f,         9.0f,        10.0f, 11.0f, 12.0f, 13.0f,
3987                14.0f,        15.0f,        16.0f,        17.0f, 18.0f, 19.0f,
3988     };
3989 
3990     for (i = 0; i < ARRAY_SIZE(a); ++i)
3991     {
3992         a[i] = 1.0f + i / 100.0f;
3993         b[i] = 3.0f - i / 100.0f;
3994         c[i] = i;
3995     }
3996 
3997     D3DXSHMultiply2(c, a, b);
3998     for (i = 0; i < ARRAY_SIZE(expected); ++i)
3999     {
4000         equal = compare_float(c[i], expected[i], 2);
4001         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
4002     }
4003 }
4004 
4005 static void test_D3DXSHMultiply3(void)
4006 {
4007     float a[20], b[20], c[20];
4008     unsigned int i;
4009     BOOL equal;
4010 
4011     /* D3DXSHMultiply3() only modifies the first 9 elements of the array. */
4012     static const float expected[20] =
4013     {
4014         7.81391382e+00f, 2.25605774e+00f, 5.94839954e+00f, 4.97089481e+00f, 2.89985824e+00f, 3.59894633e+00f,
4015         1.72657156e+00f, 5.57353783e+00f, 6.22063160e-01f, 9.00000000e+00f, 1.00000000e+01f, 1.10000000e+01f,
4016         1.20000000e+01f, 1.30000000e+01f, 1.40000000e+01f, 1.50000000e+01f, 1.60000000e+01f, 1.70000000e+01f,
4017         1.80000000e+01f, 1.90000000e+01f,
4018     };
4019     static const float expected_aliased[20] =
4020     {
4021         4.54092499e+02f, 2.12640405e+00f, 5.57040071e+00f, 1.53303785e+01f, 2.27960873e+01f, 4.36041260e+01f,
4022         4.27384138e+00f, 1.75772034e+02f, 2.37672729e+02f, 1.09000003e+00f, 1.10000002e+00f, 1.11000001e+00f,
4023         1.12000000e+00f, 1.13000000e+00f, 1.13999999e+00f, 1.14999998e+00f, 1.15999997e+00f, 1.16999996e+00f,
4024         1.17999995e+00f, 1.19000006e+00f,
4025     };
4026 
4027     for (i = 0; i < ARRAY_SIZE(a); ++i)
4028     {
4029         a[i] = 1.0f + i / 100.0f;
4030         b[i] = 3.0f - i / 100.0f;
4031         c[i] = i;
4032     }
4033 
4034     D3DXSHMultiply3(c, a, b);
4035     for (i = 0; i < ARRAY_SIZE(expected); ++i)
4036     {
4037         equal = compare_float(c[i], expected[i], 4);
4038         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
4039     }
4040 
4041     memcpy(c, a, sizeof(c));
4042     D3DXSHMultiply3(c, c, b);
4043     for (i = 0; i < ARRAY_SIZE(expected_aliased); ++i)
4044     {
4045         equal = compare_float(c[i], expected_aliased[i], 32);
4046         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected_aliased[i], c[i]);
4047     }
4048 }
4049 
4050 static void test_D3DXSHMultiply4(void)
4051 {
4052     float a[20], b[20], c[20];
4053     unsigned int i;
4054     BOOL equal;
4055 
4056     /* D3DXSHMultiply4() only modifies the first 16 elements of the array. */
4057     static const float expected[] =
4058     {
4059         /* c, a, b */
4060          1.41825991e+01f,  2.61570334e+00f,  1.28286009e+01f,  9.82059574e+00f,  3.03969646e+00f,  4.53044176e+00f,
4061          5.82058382e+00f,  1.22498465e+01f,  2.19434643e+00f,  3.90015244e+00f,  5.41660881e+00f,  5.60181284e+00f,
4062          9.59981740e-01f,  7.03754997e+00f,  3.62523031e+00f,  4.63601470e-01f,  1.60000000e+01f,  1.70000000e+01f,
4063          1.80000000e+01f,  1.90000000e+01f,
4064         /* c, c, b */
4065         -2.11441266e+05f, -2.52915771e+03f, -1.00233936e+04f, -4.41277191e+02f, -1.63994385e+02f, -5.26305115e+02f,
4066          2.96361875e+04f, -3.93183081e+03f, -1.35771113e+04f, -3.97897388e+03f, -1.03303418e+04f, -1.37797871e+04f,
4067         -1.66851094e+04f, -4.49813750e+04f, -7.32697422e+04f, -9.52373359e+04f,  1.60000000e+01f,  1.70000000e+01f,
4068          1.80000000e+01f,  1.90000000e+01f,
4069         /* c, c, c */
4070          2.36682415e-01f, -7.17648506e-01f, -1.80499524e-01f, -7.71235973e-02f,  1.44830629e-01f,  5.73285699e-01f,
4071         -3.37959230e-01f,  5.56938872e-02f, -4.42100227e-01f,  1.47701755e-01f, -5.51566519e-02f,  8.43374059e-02f,
4072          1.79876596e-01f,  9.09878965e-03f,  2.32199892e-01f,  7.41420984e-02f,  1.60000002e+00f,  1.70000005e+00f,
4073          1.80000007e+00f,  1.89999998e+00f,
4074     };
4075 
4076     for (i = 0; i < ARRAY_SIZE(a); ++i)
4077     {
4078         a[i] = 1.0f + i / 100.0f;
4079         b[i] = 3.0f - i / 100.0f;
4080         c[i] = i;
4081     }
4082 
4083     D3DXSHMultiply4(c, a, b);
4084     for (i = 0; i < ARRAY_SIZE(c); ++i)
4085     {
4086         equal = compare_float(c[i], expected[i], 16);
4087         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
4088     }
4089 
4090     for (i = 0; i < ARRAY_SIZE(b); ++i)
4091     {
4092         b[i] = 3.0f - i / 100.0f;
4093         c[i] = i;
4094     }
4095 
4096     D3DXSHMultiply4(c, c, b);
4097     for (i = 0; i < ARRAY_SIZE(c); ++i)
4098     {
4099         equal = compare_float(c[i], expected[20 + i], 32);
4100         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[20 + i], c[i]);
4101     }
4102 
4103     for (i = 0; i < ARRAY_SIZE(c); ++i)
4104         c[i] = 0.1f * i;
4105 
4106     D3DXSHMultiply4(c, c, c);
4107     for (i = 0; i < ARRAY_SIZE(c); ++i)
4108     {
4109         equal = compare_float(c[i], expected[40 + i], 8);
4110         ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[40 + i], c[i]);
4111     }
4112 }
4113 
4114 static void test_D3DXSHRotate(void)
4115 {
4116     float expected, in[49], out[49], *out_temp, *received_ptr;
4117     unsigned int i, j, l, order;
4118     D3DXMATRIX m[4];
4119     BOOL equal;
4120 
4121     static const float table[]=
4122     {
4123         /* Rotation around the x-axis, Ï€/2. */
4124          1.00999999e+00f, -3.00999999e+00f,  2.00999975e+00f,  4.01000023e+00f, -8.01000023e+00f, -6.00999928e+00f,
4125         -1.13078899e+01f,  5.00999975e+00f, -1.56583869e+00f,  1.09359801e+00f, -1.10099983e+01f,  1.98334141e+01f,
4126         -1.52681913e+01f, -1.90041180e+01f, -3.36488891e+00f, -9.56262684e+00f,  1.20996542e+01f, -2.72131383e-01f,
4127          3.02410126e+01f,  2.69199905e+01f,  3.92368774e+01f, -2.26324463e+01f,  6.70738792e+00f, -1.17682819e+01f,
4128          3.44367194e+00f, -6.07445812e+00f,  1.16183939e+01f,  1.52756083e+00f,  3.78963356e+01f, -5.69012184e+01f,
4129          4.74228935e+01f,  5.03915329e+01f,  1.06181908e+01f,  2.55010109e+01f,  4.92456071e-02f,  1.69833069e+01f,
4130 
4131          1.00999999e+00f, -3.00999999e+00f, -3.01000023e+00f,  4.01000023e+00f, -8.01000023e+00f, -6.00999928e+00f,
4132         -1.13078890e+01f, -8.01000023e+00f,  1.42979193e+01f,
4133         /* Rotation around the x-axis, -Ï€/2. */
4134          1.00999999e+00f,  3.00999999e+00f, -2.01000023e+00f,  4.01000023e+00f,  8.01000023e+00f, -6.01000118e+00f,
4135         -1.13078880e+01f, -5.01000071e+00f, -1.56583774e+00f, -1.09359753e+00f, -1.10100021e+01f, -1.98334103e+01f,
4136          1.52681961e+01f, -1.90041142e+01f,  3.36489248e+00f, -9.56262398e+00f, -1.20996523e+01f, -2.72129118e-01f,
4137         -3.02410049e+01f,  2.69200020e+01f,  3.92368736e+01f,  2.26324520e+01f,  6.70738268e+00f,  1.17682877e+01f,
4138          3.44367099e+00f,  6.07445717e+00f,  1.16183996e+01f, -1.52756333e+00f,  3.78963509e+01f,  5.69011993e+01f,
4139         -4.74229126e+01f,  5.03915253e+01f, -1.06182041e+01f,  2.55009995e+01f, -4.92481887e-02f,  1.69833050e+01f,
4140 
4141          1.00999999e+00f,  3.00999999e+00f, -3.01000023e+00f,  4.01000023e+00f,  8.01000023e+00f, -6.01000118e+00f,
4142         -1.13078899e+01f, -8.01000023e+00f,  1.42979193e+01f,
4143         /* Yaw Ï€/3, pitch Ï€/4, roll Ï€/5. */
4144          1.00999999e+00f,  4.94489908e+00f,  1.44230127e+00f,  1.62728095e+00f,  2.19220325e-01f,  1.05408239e+01f,
4145         -9.13690281e+00f,  2.76374960e+00f, -7.30904531e+00f, -5.87572050e+00f,  5.30312395e+00f, -8.68215370e+00f,
4146         -2.56833839e+01f,  1.68027866e+00f, -1.88083878e+01f,  7.65365601e+00f,  1.69391327e+01f, -1.73280182e+01f,
4147          1.46297951e+01f, -5.44671021e+01f, -1.22310352e+01f, -4.08985710e+00f, -9.44422245e+00f,  3.05603528e+00f,
4148          1.79257303e-01f, -1.00418749e+01f,  2.30900917e+01f, -2.31887093e+01f,  1.17270985e+01f, -6.51830902e+01f,
4149          4.86715775e+01f, -1.50732088e+01f,  3.87931709e+01f, -2.60395355e+01f,  6.19276857e+00f, -1.76722469e+01f,
4150 
4151          1.00999999e+00f,  4.94489908e+00f, -8.91142070e-01f,  4.60769463e+00f,  2.19218358e-01f,  1.07733250e+01f,
4152         -8.20476913e+00f,  1.35638294e+01f, -1.20077667e+01f,
4153         /* Rotation around the z-axis, Ï€/6. */
4154          1.00999999e+00f,  3.74571109e+00f,  3.00999999e+00f,  2.46776199e+00f,  1.03078890e+01f,  9.20981312e+00f,
4155          7.01000023e+00f,  3.93186355e+00f,  1.66212186e-01f,  1.60099983e+01f,  1.85040417e+01f,  1.74059658e+01f,
4156          1.30100002e+01f,  6.12801647e+00f, -2.02994061e+00f, -1.00100012e+01f,  1.31542921e+01f,  2.40099964e+01f,
4157          2.94322453e+01f,  2.83341675e+01f,  2.10100021e+01f,  9.05622101e+00f, -4.95814323e+00f, -1.80100002e+01f,
4158         -2.72360935e+01f, -4.52033186e+00f,  1.68145428e+01f,  3.40099945e+01f,  4.30924950e+01f,  4.19944229e+01f,
4159          3.10100002e+01f,  1.27164707e+01f, -8.61839962e+00f, -2.80100021e+01f, -4.08963470e+01f, -4.41905708e+01f,
4160 
4161          1.00999999e+00f,  3.74571109e+00f,  3.00999999e+00f,  1.59990644e+00f,  1.03078890e+01f,  9.20981312e+00f,
4162          7.01000023e+00f,  2.33195710e+00f, -4.42189360e+00f,
4163     };
4164 
4165     D3DXMatrixRotationX(&m[0], -D3DX_PI / 2.0f);
4166     D3DXMatrixRotationX(&m[1], D3DX_PI / 2.0f);
4167     D3DXMatrixRotationYawPitchRoll(&m[2], D3DX_PI / 3.0f, D3DX_PI / 4.0f, D3DX_PI / 5.0f);
4168     D3DXMatrixRotationZ(&m[3], D3DX_PI / 6.0f);
4169 
4170     for (l = 0; l < 2; l++)
4171     {
4172         if (l == 0)
4173             out_temp = out;
4174         else
4175             out_temp = in;
4176 
4177         for (j = 0; j < ARRAY_SIZE(m); ++j)
4178         {
4179             for (order = 0; order <= D3DXSH_MAXORDER; order++)
4180             {
4181                 for (i = 0; i < ARRAY_SIZE(out); ++i)
4182                 {
4183                     out[i] = ( i + 1.0f ) * ( i + 1.0f );
4184                     in[i] = i + 1.01f;
4185                 }
4186 
4187                 received_ptr = D3DXSHRotate(out_temp, order, &m[j], in);
4188                 ok(received_ptr == out_temp, "Order %u, expected %p, received %p.\n",
4189                         order, out, received_ptr);
4190 
4191                 for (i = 0; i < ARRAY_SIZE(out); ++i)
4192                 {
4193                     if ((i > 0) && ((i >= order * order) || (order > D3DXSH_MAXORDER)))
4194                     {
4195                         if (l == 0)
4196                             expected = ( i + 1.0f ) * ( i + 1.0f );
4197                         else
4198                             expected = i + 1.01f;
4199                     }
4200                     else if ((l == 0) || (order > 3))
4201                         expected = table[45 * j + i];
4202                     else
4203                         expected = table[45 * j + 36 +i];
4204                     equal = compare_float(out_temp[i], expected, 4096);
4205                     ok(equal, "Order %u index %u, expected %.8e, received %.8e.\n",
4206                             order, i, expected, out_temp[i]);
4207                 }
4208             }
4209         }
4210     }
4211 }
4212 
4213 static void test_D3DXSHRotateZ(void)
4214 {
4215     float expected, in[49], out[49], *out_temp, *received_ptr;
4216     unsigned int end, i, j, l, order, square;
4217     BOOL equal;
4218 
4219     static const float angle[] = {D3DX_PI / 3.0f, -D3DX_PI / 3.0f, 4.0f * D3DX_PI / 3.0f};
4220     static const float table[] =
4221     {
4222         /* Angle Ï€/3. */
4223          1.00999999e+00f,  4.47776222e+00f,  3.00999999e+00f,  2.64288902e-01f,  5.29788828e+00f,  9.94186401e+00f,
4224          7.01000023e+00f, -1.19981313e+00f, -8.84378910e+00f, -1.00100021e+01f,  7.49403954e+00f,  1.81380157e+01f,
4225          1.30100002e+01f, -3.39596605e+00f, -1.70399418e+01f, -1.60099983e+01f, -3.01642971e+01f, -1.80100040e+01f,
4226          1.04222422e+01f,  2.90662193e+01f,  2.10100002e+01f, -6.32417059e+00f, -2.79681454e+01f, -2.40099983e+01f,
4227          2.22609901e+00f, -1.81805649e+01f, -4.38245506e+01f, -2.80100040e+01f,  1.40824928e+01f,  4.27264709e+01f,
4228          3.10100002e+01f, -9.98442554e+00f, -4.16283989e+01f, -3.40099945e+01f,  5.88635778e+00f,  4.05303307e+01f,
4229 
4230          1.00999999e+00f,  4.47776222e+00f,  0.00000000e+00f, -5.81678391e+00f,  5.29788828e+00f,  6.93686390e+00f,
4231          0.00000000e+00f, -9.01125050e+00f, -2.29405236e+00f, -1.00100021e+01f,  1.29990416e+01f,  1.21330166e+01f,
4232          0.00000000e+00f, -1.57612505e+01f, -5.62874842e+00f,  0.00000000e+00f, -3.01642971e+01f, -3.29017075e-06f,
4233          1.99272442e+01f,  1.90612202e+01f,  0.00000000e+00f, -2.47612514e+01f, -8.62874794e+00f,  0.00000000e+00f,
4234         -1.30615301e+01f, -1.81805649e+01f, -3.03195534e+01f, -4.66050415e-06f,  2.85874958e+01f,  2.77214737e+01f,
4235          0.00000000e+00f, -3.60112534e+01f, -1.23787460e+01f,  0.00000000e+00f, -1.31287584e+01f, -2.36172504e+01f,
4236 
4237          1.00999999e+00f,  3.97776222e+00f,  3.97776222e+00f,  1.11419535e+00f,  7.24579096e+00f,  1.05597591e+01f,
4238          1.05597591e+01f, -9.95159924e-01f, -4.67341393e-01f,  4.67339337e-01f,  1.27653713e+01f,  1.85157013e+01f,
4239          1.85157013e+01f, -1.79728663e+00f,  4.93915796e-01f, -4.93915856e-01f, -2.14123421e+01f,  2.14123383e+01f,
4240          9.22107220e+00f,  2.36717567e+01f,  2.36717567e+01f,  3.85019469e+00f, -2.04687271e+01f,  2.04687233e+01f,
4241         -1.06621027e+01f, -3.65166283e+01f, -1.20612450e+01f,  1.20612402e+01f,  2.25568752e+01f,  3.89999084e+01f,
4242          3.89999084e+01f, -3.48751247e-02f, -1.04279022e+01f,  1.04279003e+01f, -3.68382835e+01f, -2.76528034e+01f,
4243         /* Angle -Ï€/3. */
4244          1.00999999e+00f, -2.46776247e+00f,  3.00999999e+00f,  3.74571109e+00f, -1.03078899e+01f, -3.93186426e+00f,
4245          7.01000023e+00f,  9.20981312e+00f, -1.66213632e-01f, -1.00099983e+01f, -1.85040436e+01f, -6.12801695e+00f,
4246          1.30100002e+01f,  1.74059658e+01f,  2.02993774e+00f, -1.60100021e+01f,  1.31543026e+01f, -1.80099964e+01f,
4247         -2.94322472e+01f, -9.05622101e+00f,  2.10100002e+01f,  2.83341694e+01f,  4.95813942e+00f, -2.40100021e+01f,
4248         -2.72360916e+01f,  4.41905823e+01f,  1.68145580e+01f, -2.80099964e+01f, -4.30924988e+01f, -1.27164736e+01f,
4249          3.10100002e+01f,  4.19944229e+01f,  8.61839294e+00f, -3.40100021e+01f, -4.08963470e+01f, -4.52030993e+00f,
4250 
4251          1.00999999e+00f, -2.46776247e+00f,  0.00000000e+00f, -3.20571756e+00f, -1.03078899e+01f, -6.93686390e+00f,
4252          0.00000000e+00f, -9.01125050e+00f, -4.46344614e+00f, -1.00099983e+01f, -1.29990416e+01f, -1.21330166e+01f,
4253          0.00000000e+00f, -1.57612505e+01f, -5.62874842e+00f,  0.00000000e+00f,  1.31543026e+01f,  3.29017075e-06f,
4254         -1.99272442e+01f, -1.90612202e+01f,  0.00000000e+00f, -2.47612514e+01f, -8.62874794e+00f,  0.00000000e+00f,
4255         -5.69598293e+00f,  4.41905823e+01f,  3.03195534e+01f,  4.66050415e-06f, -2.85874958e+01f, -2.77214737e+01f,
4256          0.00000000e+00f, -3.60112534e+01f, -1.23787460e+01f,  0.00000000e+00f, -1.31287584e+01f, -5.74052582e+01f,
4257 
4258          1.00999999e+00f, -2.96776223e+00f, -2.96776223e+00f, -6.09195352e-01f, -7.49829102e+00f, -1.06860094e+01f,
4259         -1.06860094e+01f, -1.18367157e+01f,  5.39078045e+00f, -5.39077854e+00f, -1.03036509e+01f, -1.72848415e+01f,
4260         -1.72848415e+01f, -1.75656433e+01f,  4.11427259e+00f, -4.11427307e+00f,  2.37164364e+01f, -2.37164326e+01f,
4261         -8.06902504e+00f, -2.30957317e+01f, -2.30957317e+01f, -1.85358467e+01f, -1.12711067e+01f,  1.12711039e+01f,
4262         -2.07248449e+00f,  3.01493301e+01f,  1.52448931e+01f, -1.52448883e+01f, -2.09650497e+01f, -3.82039986e+01f,
4263         -3.82039986e+01f, -3.72582664e+01f,  5.42667723e+00f, -5.42667913e+00f, -2.33967514e+01f, -9.90355873e+00f,
4264         /* Angle 4Ï€/3. */
4265          1.00999999e+00f, -4.47776222e+00f,  3.00999999e+00f, -2.64288664e-01f,  5.29788685e+00f, -9.94186401e+00f,
4266          7.01000023e+00f,  1.19981360e+00f, -8.84378815e+00f,  1.00100040e+01f,  7.49403811e+00f, -1.81380157e+01f,
4267          1.30100002e+01f,  3.39596677e+00f, -1.70399399e+01f,  1.60099964e+01f, -3.01642933e+01f,  1.80100060e+01f,
4268          1.04222393e+01f, -2.90662193e+01f,  2.10100002e+01f,  6.32417202e+00f, -2.79681435e+01f,  2.40099926e+01f,
4269          2.22610497e+00f,  1.81805515e+01f, -4.38245430e+01f,  2.80100079e+01f,  1.40824890e+01f, -4.27264709e+01f,
4270          3.10100002e+01f,  9.98442745e+00f, -4.16283989e+01f,  3.40099869e+01f,  5.88636589e+00f, -4.05303268e+01f,
4271 
4272          1.00999999e+00f, -4.47776222e+00f,  0.00000000e+00f, -1.93892837e+00f,  5.29788685e+00f, -6.93686390e+00f,
4273          0.00000000e+00f, -3.00375080e+00f, -2.29405141e+00f,  1.00100040e+01f,  1.29990396e+01f, -1.21330166e+01f,
4274          0.00000000e+00f, -5.25375128e+00f, -5.62874699e+00f, -5.68378528e-06f, -3.01642933e+01f,  7.00829787e-06f,
4275          1.99272423e+01f, -1.90612202e+01f,  0.00000000e+00f, -8.25375271e+00f, -8.62874603e+00f, -4.09131496e-12f,
4276         -1.30615349e+01f,  1.81805515e+01f, -3.03195534e+01f,  9.92720470e-06f,  2.85874920e+01f, -2.77214737e+01f,
4277          0.00000000e+00f, -1.20037527e+01f, -1.23787422e+01f, -5.79531909e-12f, -1.31287651e+01f, -7.87240028e+00f,
4278 
4279          1.00999999e+00f, -3.97776222e+00f, -3.97776222e+00f,  2.86356640e+00f,  6.37110424e+00f, -1.01224155e+01f,
4280         -1.01224155e+01f,  1.05787458e+01f, -7.76929522e+00f, -7.76928997e+00f,  1.68836861e+01f, -2.05748577e+01f,
4281         -2.05748577e+01f,  2.49091301e+01f, -5.72616625e+00f, -5.72616386e+00f, -1.87962208e+01f, -1.87962112e+01f,
4282          2.93253498e+01f, -3.37238922e+01f, -3.37238922e+01f,  4.22584419e+01f, -4.85123205e+00f, -4.85122633e+00f,
4283         -2.53339314e+00f,  3.24522591e+01f, -4.65456696e+01f, -4.65456543e+01f,  5.18603249e+01f, -5.36516304e+01f,
4284         -5.36516304e+01f,  7.17381744e+01f,  4.44061565e+00f,  4.44062901e+00f,  2.58841743e+01f, -1.07481155e+01f,
4285     };
4286 
4287     for (l = 0; l < 3; l++)
4288     {
4289         if (l == 0)
4290             out_temp = out;
4291         else
4292             out_temp = &in[l - 1];
4293 
4294         if (l < 2)
4295             end = 49;
4296         else
4297             end = 48;
4298 
4299         for (j = 0; j < ARRAY_SIZE(angle); ++j)
4300         {
4301             for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
4302             {
4303                 for (i = 0; i < ARRAY_SIZE(out); ++i)
4304                 {
4305                     out[i] = ( i + 1.0f ) * ( i + 1.0f );
4306                     in[i] = i + 1.01f;
4307                 }
4308 
4309                 received_ptr = D3DXSHRotateZ(out_temp, order, angle[j], in);
4310                 ok(received_ptr == out_temp, "angle %f, order %u, expected %p, received %p\n", angle[j], order, out_temp, received_ptr);
4311 
4312                 for (i = 0; i < end; i++)
4313                 {
4314                     /* order = 0 or order = 1 behaves like order = D3DXSH_MINORDER */
4315                     square = (order <= D3DXSH_MINORDER) ? D3DXSH_MINORDER * D3DXSH_MINORDER : order * order;
4316                     if (i >= square || ((order >= D3DXSH_MAXORDER) && (i >= D3DXSH_MAXORDER * D3DXSH_MAXORDER)))
4317                         if (l > 0)
4318                             expected = i + l + 0.01f;
4319                         else
4320                             expected = ( i + 1.0f ) * ( i + 1.0f );
4321                     else
4322                         expected = table[36 * (l + 3 * j) + i];
4323                     equal = compare_float(expected, out_temp[i], 256);
4324                     ok(equal || (fabs(expected) < 2.0e-5f && fabs(out_temp[i]) < 2.0e-5f),
4325                             "angle %.8e, order %u index %u, expected %.8e, received %.8e.\n",
4326                             angle[j], order, i, expected, out_temp[i]);
4327                 }
4328             }
4329         }
4330     }
4331 }
4332 
4333 static void test_D3DXSHScale(void)
4334 {
4335     float a[49], b[49], expected, *received_array;
4336     unsigned int i, order;
4337     BOOL equal;
4338 
4339     for (i = 0; i < ARRAY_SIZE(a); ++i)
4340     {
4341         a[i] = i;
4342         b[i] = i;
4343     }
4344 
4345     for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
4346     {
4347         received_array = D3DXSHScale(b, order, a, 5.0f);
4348         ok(received_array == b, "Expected %p, received %p\n", b, received_array);
4349 
4350         for (i = 0; i < ARRAY_SIZE(b); ++i)
4351         {
4352             if (i < order * order)
4353                 expected = 5.0f * a[i];
4354             /* D3DXSHScale does not modify the elements of the array after the order * order-th element */
4355             else
4356                 expected = a[i];
4357             equal = compare_float(b[i], expected, 0);
4358             ok(equal, "order %u, element %u, expected %.8e, received %.8e.\n", order, i, expected, b[i]);
4359         }
4360     }
4361 }
4362 
4363 START_TEST(math)
4364 {
4365     D3DXColorTest();
4366     D3DXFresnelTest();
4367     D3DXMatrixTest();
4368     D3DXPlaneTest();
4369     D3DXQuaternionTest();
4370     D3DXVector2Test();
4371     D3DXVector3Test();
4372     D3DXVector4Test();
4373     test_matrix_stack();
4374     test_Matrix_AffineTransformation2D();
4375     test_Matrix_Decompose();
4376     test_Matrix_Transformation2D();
4377     test_D3DXVec_Array();
4378     test_D3DXFloat_Array();
4379     test_D3DXSHAdd();
4380     test_D3DXSHDot();
4381     test_D3DXSHEvalConeLight();
4382     test_D3DXSHEvalDirection();
4383     test_D3DXSHEvalDirectionalLight();
4384     test_D3DXSHEvalHemisphereLight();
4385     test_D3DXSHEvalSphericalLight();
4386     test_D3DXSHMultiply2();
4387     test_D3DXSHMultiply3();
4388     test_D3DXSHMultiply4();
4389     test_D3DXSHRotate();
4390     test_D3DXSHRotateZ();
4391     test_D3DXSHScale();
4392 }
4393