kernel32/nls: Added LOCALE_SNAN entries.
[wine.git] / dlls / d3dx9_36 / tests / math.c
blobff3b098991622417d466d2ab584276d4e06df140
1 /*
2 * Copyright 2008 David Adam
3 * Copyright 2008 Luis Busquets
4 * Copyright 2008 Philip Nilsson
5 * Copyright 2008 Henri Verbeet
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.
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.
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
22 #include "wine/test.h"
23 #include "d3dx9.h"
24 #include <math.h>
26 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
28 static BOOL compare_float(float f, float g, unsigned int ulps)
30 int x = *(int *)&f;
31 int y = *(int *)&g;
33 if (x < 0)
34 x = INT_MIN - x;
35 if (y < 0)
36 y = INT_MIN - y;
38 if (abs(x - y) > ulps)
39 return FALSE;
41 return TRUE;
44 static BOOL compare_vec2(const D3DXVECTOR2 *v1, const D3DXVECTOR2 *v2, unsigned int ulps)
46 return compare_float(v1->x, v2->x, ulps) && compare_float(v1->y, v2->y, ulps);
49 static BOOL compare_vec3(const D3DXVECTOR3 *v1, const D3DXVECTOR3 *v2, unsigned int ulps)
51 return compare_float(v1->x, v2->x, ulps)
52 && compare_float(v1->y, v2->y, ulps)
53 && compare_float(v1->z, v2->z, ulps);
56 static BOOL compare_vec4(const D3DXVECTOR4 *v1, const D3DXVECTOR4 *v2, unsigned int ulps)
58 return compare_float(v1->x, v2->x, ulps)
59 && compare_float(v1->y, v2->y, ulps)
60 && compare_float(v1->z, v2->z, ulps)
61 && compare_float(v1->w, v2->w, ulps);
64 static BOOL compare_color(const D3DXCOLOR *c1, const D3DXCOLOR *c2, unsigned int ulps)
66 return compare_float(c1->r, c2->r, ulps)
67 && compare_float(c1->g, c2->g, ulps)
68 && compare_float(c1->b, c2->b, ulps)
69 && compare_float(c1->a, c2->a, ulps);
72 static BOOL compare_plane(const D3DXPLANE *p1, const D3DXPLANE *p2, unsigned int ulps)
74 return compare_float(p1->a, p2->a, ulps)
75 && compare_float(p1->b, p2->b, ulps)
76 && compare_float(p1->c, p2->c, ulps)
77 && compare_float(p1->d, p2->d, ulps);
80 static BOOL compare_quaternion(const D3DXQUATERNION *q1, const D3DXQUATERNION *q2, unsigned int ulps)
82 return compare_float(q1->x, q2->x, ulps)
83 && compare_float(q1->y, q2->y, ulps)
84 && compare_float(q1->z, q2->z, ulps)
85 && compare_float(q1->w, q2->w, ulps);
88 static BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2, unsigned int ulps)
90 unsigned int i, j;
92 for (i = 0; i < 4; ++i)
94 for (j = 0; j < 4; ++j)
96 if (!compare_float(U(*m1).m[i][j], U(*m2).m[i][j], ulps))
97 return FALSE;
101 return TRUE;
104 #define expect_vec2(expected, vector, ulps) expect_vec2_(__LINE__, expected, vector, ulps)
105 static void expect_vec2_(unsigned int line, const D3DXVECTOR2 *expected, const D3DXVECTOR2 *vector, unsigned int ulps)
107 BOOL equal = compare_vec2(expected, vector, ulps);
108 ok_(__FILE__, line)(equal,
109 "Got unexpected vector {%.8e, %.8e}, expected {%.8e, %.8e}.\n",
110 vector->x, vector->y, expected->x, expected->y);
113 #define expect_vec3(expected, vector, ulps) expect_vec3_(__LINE__, expected, vector, ulps)
114 static void expect_vec3_(unsigned int line, const D3DXVECTOR3 *expected, const D3DXVECTOR3 *vector, unsigned int ulps)
116 BOOL equal = compare_vec3(expected, vector, ulps);
117 ok_(__FILE__, line)(equal,
118 "Got unexpected vector {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
119 vector->x, vector->y, vector->z, expected->x, expected->y, expected->z);
122 #define expect_vec4(expected, vector, ulps) expect_vec4_(__LINE__, expected, vector, ulps)
123 static void expect_vec4_(unsigned int line, const D3DXVECTOR4 *expected, const D3DXVECTOR4 *vector, unsigned int ulps)
125 BOOL equal = compare_vec4(expected, vector, ulps);
126 ok_(__FILE__, line)(equal,
127 "Got unexpected vector {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
128 vector->x, vector->y, vector->z, vector->w, expected->x, expected->y, expected->z, expected->w);
131 #define expect_color(expected, color, ulps) expect_color_(__LINE__, expected, color, ulps)
132 static void expect_color_(unsigned int line, const D3DXCOLOR *expected, const D3DXCOLOR *color, unsigned int ulps)
134 BOOL equal = compare_color(expected, color, ulps);
135 ok_(__FILE__, line)(equal,
136 "Got unexpected color {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
137 color->r, color->g, color->b, color->a, expected->r, expected->g, expected->b, expected->a);
140 #define expect_plane(expected, plane, ulps) expect_plane_(__LINE__, expected, plane, ulps)
141 static void expect_plane_(unsigned int line, const D3DXPLANE *expected, const D3DXPLANE *plane, unsigned int ulps)
143 BOOL equal = compare_plane(expected, plane, ulps);
144 ok_(__FILE__, line)(equal,
145 "Got unexpected plane {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
146 plane->a, plane->b, plane->c, plane->d, expected->a, expected->b, expected->c, expected->d);
149 #define expect_quaternion(expected, quaternion, ulps) expect_quaternion_(__LINE__, expected, quaternion, ulps)
150 static void expect_quaternion_(unsigned int line, const D3DXQUATERNION *expected,
151 const D3DXQUATERNION *quaternion, unsigned int ulps)
153 BOOL equal = compare_quaternion(expected, quaternion, ulps);
154 ok_(__FILE__, line)(equal,
155 "Got unexpected quaternion {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
156 quaternion->x, quaternion->y, quaternion->z, quaternion->w,
157 expected->x, expected->y, expected->z, expected->w);
160 #define expect_matrix(expected, matrix, ulps) expect_matrix_(__LINE__, expected, matrix, ulps)
161 static void expect_matrix_(unsigned int line, const D3DXMATRIX *expected, const D3DXMATRIX *matrix, unsigned int ulps)
163 BOOL equal = compare_matrix(expected, matrix, ulps);
164 ok_(__FILE__, line)(equal,
165 "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, "
166 "%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e}, "
167 "expected {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, "
168 "%.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
169 U(*matrix).m[0][0], U(*matrix).m[0][1], U(*matrix).m[0][2], U(*matrix).m[0][3],
170 U(*matrix).m[1][0], U(*matrix).m[1][1], U(*matrix).m[1][2], U(*matrix).m[1][3],
171 U(*matrix).m[2][0], U(*matrix).m[2][1], U(*matrix).m[2][2], U(*matrix).m[2][3],
172 U(*matrix).m[3][0], U(*matrix).m[3][1], U(*matrix).m[3][2], U(*matrix).m[3][3],
173 U(*expected).m[0][0], U(*expected).m[0][1], U(*expected).m[0][2], U(*expected).m[0][3],
174 U(*expected).m[1][0], U(*expected).m[1][1], U(*expected).m[1][2], U(*expected).m[1][3],
175 U(*expected).m[2][0], U(*expected).m[2][1], U(*expected).m[2][2], U(*expected).m[2][3],
176 U(*expected).m[3][0], U(*expected).m[3][1], U(*expected).m[3][2], U(*expected).m[3][3]);
179 #define expect_vec4_array(count, expected, vector, ulps) expect_vec4_array_(__LINE__, count, expected, vector, ulps)
180 static void expect_vec4_array_(unsigned int line, unsigned int count, const D3DXVECTOR4 *expected,
181 const D3DXVECTOR4 *vector, unsigned int ulps)
183 BOOL equal;
184 unsigned int i;
186 for (i = 0; i < count; ++i)
188 equal = compare_vec4(&expected[i], &vector[i], ulps);
189 ok_(__FILE__, line)(equal,
190 "Got unexpected vector {%.8e, %.8e, %.8e, %.8e} at index %u, expected {%.8e, %.8e, %.8e, %.8e}.\n",
191 vector[i].x, vector[i].y, vector[i].z, vector[i].w, i,
192 expected[i].x, expected[i].y, expected[i].z, expected[i].w);
193 if (!equal)
194 break;
198 static void D3DXColorTest(void)
200 D3DXCOLOR color, color1, color2, expected, got;
201 LPD3DXCOLOR funcpointer;
202 FLOAT scale;
204 color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
205 color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
206 color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
208 scale = 0.3f;
210 /*_______________D3DXColorAdd________________*/
211 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
212 D3DXColorAdd(&got,&color1,&color2);
213 expect_color(&expected, &got, 1);
214 /* Test the NULL case */
215 funcpointer = D3DXColorAdd(&got,NULL,&color2);
216 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
217 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
218 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
219 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
220 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
222 /*_______________D3DXColorAdjustContrast______*/
223 expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
224 D3DXColorAdjustContrast(&got,&color,scale);
225 expect_color(&expected, &got, 0);
227 /*_______________D3DXColorAdjustSaturation______*/
228 expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
229 D3DXColorAdjustSaturation(&got,&color,scale);
230 expect_color(&expected, &got, 16);
232 /*_______________D3DXColorLerp________________*/
233 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
234 D3DXColorLerp(&got,&color,&color1,scale);
235 expect_color(&expected, &got, 0);
236 /* Test the NULL case */
237 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
238 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
239 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
240 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
241 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
242 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
244 /*_______________D3DXColorModulate________________*/
245 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
246 D3DXColorModulate(&got,&color1,&color2);
247 expect_color(&expected, &got, 0);
248 /* Test the NULL case */
249 funcpointer = D3DXColorModulate(&got,NULL,&color2);
250 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
251 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
252 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
253 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
254 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
256 /*_______________D3DXColorNegative________________*/
257 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
258 D3DXColorNegative(&got,&color);
259 expect_color(&expected, &got, 1);
260 /* Test the greater than 1 case */
261 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
262 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
263 D3DXColorNegative(&got,&color1);
264 expect_color(&expected, &got, 1);
265 /* Test the negative case */
266 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
267 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
268 D3DXColorNegative(&got,&color1);
269 expect_color(&expected, &got, 1);
270 /* Test the NULL case */
271 funcpointer = D3DXColorNegative(&got,NULL);
272 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
273 funcpointer = D3DXColorNegative(NULL,NULL);
274 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
276 /*_______________D3DXColorScale________________*/
277 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
278 D3DXColorScale(&got,&color,scale);
279 expect_color(&expected, &got, 1);
280 /* Test the NULL case */
281 funcpointer = D3DXColorScale(&got,NULL,scale);
282 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
283 funcpointer = D3DXColorScale(NULL,NULL,scale);
284 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
286 /*_______________D3DXColorSubtract_______________*/
287 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
288 D3DXColorSubtract(&got,&color,&color2);
289 expect_color(&expected, &got, 1);
290 /* Test the NULL case */
291 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
292 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
293 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
294 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
295 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
296 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
299 static void D3DXFresnelTest(void)
301 float fresnel;
302 BOOL equal;
304 fresnel = D3DXFresnelTerm(0.5f, 1.5f);
305 equal = compare_float(fresnel, 8.91867056e-02f, 1);
306 ok(equal, "Got unexpected Fresnel term %.8e.\n", fresnel);
309 static void D3DXMatrixTest(void)
311 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
312 BOOL expected, got, equal;
313 float angle, determinant;
314 D3DXMATRIX *funcpointer;
315 D3DXPLANE plane;
316 D3DXQUATERNION q, r;
317 D3DXVECTOR3 at, axis, eye, last;
318 D3DXVECTOR4 light;
320 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
321 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
322 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
323 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
324 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
325 U(mat).m[3][3] = -40.0f;
327 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
328 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
329 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
330 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
331 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
332 U(mat2).m[3][3] = -1.0f;
334 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
336 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
337 r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
339 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
340 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
341 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
342 last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
344 light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
346 angle = D3DX_PI/3.0f;
348 /*____________D3DXMatrixAffineTransformation______*/
349 U(expectedmat).m[0][0] = -459.239990f; U(expectedmat).m[0][1] = -576.719971f; U(expectedmat).m[0][2] = -263.440002f; U(expectedmat).m[0][3] = 0.0f;
350 U(expectedmat).m[1][0] = 519.760010f; U(expectedmat).m[1][1] = -352.440002f; U(expectedmat).m[1][2] = -277.679993f; U(expectedmat).m[1][3] = 0.0f;
351 U(expectedmat).m[2][0] = 363.119995f; U(expectedmat).m[2][1] = -121.040001f; U(expectedmat).m[2][2] = -117.479996f; U(expectedmat).m[2][3] = 0.0f;
352 U(expectedmat).m[3][0] = -1239.0f; U(expectedmat).m[3][1] = 667.0f; U(expectedmat).m[3][2] = 567.0f; U(expectedmat).m[3][3] = 1.0f;
353 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, &axis);
354 expect_matrix(&expectedmat, &gotmat, 0);
356 /* Test the NULL case */
357 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;
358 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, &axis);
359 expect_matrix(&expectedmat, &gotmat, 0);
361 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;
362 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, NULL);
363 expect_matrix(&expectedmat, &gotmat, 0);
365 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;
366 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, NULL);
367 expect_matrix(&expectedmat, &gotmat, 0);
369 U(expectedmat).m[0][0] = 3.56f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
370 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 3.56f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
371 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 3.56f; U(expectedmat).m[2][3] = 0.0f;
372 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;
373 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, &axis);
374 expect_matrix(&expectedmat, &gotmat, 0);
376 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, &axis);
377 expect_matrix(&expectedmat, &gotmat, 0);
379 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;
380 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, NULL);
381 expect_matrix(&expectedmat, &gotmat, 0);
383 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, NULL);
384 expect_matrix(&expectedmat, &gotmat, 0);
386 /*____________D3DXMatrixfDeterminant_____________*/
387 determinant = D3DXMatrixDeterminant(&mat);
388 equal = compare_float(determinant, -147888.0f, 0);
389 ok(equal, "Got unexpected determinant %.8e.\n", determinant);
391 /*____________D3DXMatrixInverse______________*/
392 U(expectedmat).m[0][0] = 16067.0f/73944.0f; U(expectedmat).m[0][1] = -10165.0f/147888.0f; U(expectedmat).m[0][2] = -2729.0f/147888.0f; U(expectedmat).m[0][3] = -1631.0f/49296.0f;
393 U(expectedmat).m[1][0] = -565.0f/36972.0f; U(expectedmat).m[1][1] = 2723.0f/73944.0f; U(expectedmat).m[1][2] = -1073.0f/73944.0f; U(expectedmat).m[1][3] = 289.0f/24648.0f;
394 U(expectedmat).m[2][0] = -389.0f/2054.0f; U(expectedmat).m[2][1] = 337.0f/4108.0f; U(expectedmat).m[2][2] = 181.0f/4108.0f; U(expectedmat).m[2][3] = 317.0f/4108.0f;
395 U(expectedmat).m[3][0] = 163.0f/5688.0f; U(expectedmat).m[3][1] = -101.0f/11376.0f; U(expectedmat).m[3][2] = -73.0f/11376.0f; U(expectedmat).m[3][3] = -127.0f/3792.0f;
396 D3DXMatrixInverse(&gotmat,&determinant,&mat);
397 expect_matrix(&expectedmat, &gotmat, 1);
398 equal = compare_float(determinant, -147888.0f, 0);
399 ok(equal, "Got unexpected determinant %.8e.\n", determinant);
400 funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
401 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
403 /*____________D3DXMatrixIsIdentity______________*/
404 expected = FALSE;
405 memset(&mat3, 0, sizeof(mat3));
406 got = D3DXMatrixIsIdentity(&mat3);
407 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
408 D3DXMatrixIdentity(&mat3);
409 expected = TRUE;
410 got = D3DXMatrixIsIdentity(&mat3);
411 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
412 U(mat3).m[0][0] = 0.000009f;
413 expected = FALSE;
414 got = D3DXMatrixIsIdentity(&mat3);
415 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
416 /* Test the NULL case */
417 expected = FALSE;
418 got = D3DXMatrixIsIdentity(NULL);
419 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
421 /*____________D3DXMatrixLookatLH_______________*/
422 U(expectedmat).m[0][0] = -0.822465f; U(expectedmat).m[0][1] = -0.409489f; U(expectedmat).m[0][2] = -0.394803f; U(expectedmat).m[0][3] = 0.0f;
423 U(expectedmat).m[1][0] = -0.555856f; U(expectedmat).m[1][1] = 0.431286f; U(expectedmat).m[1][2] = 0.710645f; U(expectedmat).m[1][3] = 0.0f;
424 U(expectedmat).m[2][0] = -0.120729f; U(expectedmat).m[2][1] = 0.803935f; U(expectedmat).m[2][2] = -0.582335f; U(expectedmat).m[2][3] = 0.0f;
425 U(expectedmat).m[3][0] = 4.494634f; U(expectedmat).m[3][1] = 0.809719f; U(expectedmat).m[3][2] = 10.060076f; U(expectedmat).m[3][3] = 1.0f;
426 D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
427 expect_matrix(&expectedmat, &gotmat, 32);
429 /*____________D3DXMatrixLookatRH_______________*/
430 U(expectedmat).m[0][0] = 0.822465f; U(expectedmat).m[0][1] = -0.409489f; U(expectedmat).m[0][2] = 0.394803f; U(expectedmat).m[0][3] = 0.0f;
431 U(expectedmat).m[1][0] = 0.555856f; U(expectedmat).m[1][1] = 0.431286f; U(expectedmat).m[1][2] = -0.710645f; U(expectedmat).m[1][3] = 0.0f;
432 U(expectedmat).m[2][0] = 0.120729f; U(expectedmat).m[2][1] = 0.803935f; U(expectedmat).m[2][2] = 0.582335f; U(expectedmat).m[2][3] = 0.0f;
433 U(expectedmat).m[3][0] = -4.494634f; U(expectedmat).m[3][1] = 0.809719f; U(expectedmat).m[3][2] = -10.060076f; U(expectedmat).m[3][3] = 1.0f;
434 D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
435 expect_matrix(&expectedmat, &gotmat, 32);
437 /*____________D3DXMatrixMultiply______________*/
438 U(expectedmat).m[0][0] = 73.0f; U(expectedmat).m[0][1] = 193.0f; U(expectedmat).m[0][2] = -197.0f; U(expectedmat).m[0][3] = -77.0f;
439 U(expectedmat).m[1][0] = 231.0f; U(expectedmat).m[1][1] = 551.0f; U(expectedmat).m[1][2] = -489.0f; U(expectedmat).m[1][3] = -169.0;
440 U(expectedmat).m[2][0] = 239.0f; U(expectedmat).m[2][1] = 523.0f; U(expectedmat).m[2][2] = -400.0f; U(expectedmat).m[2][3] = -116.0f;
441 U(expectedmat).m[3][0] = -164.0f; U(expectedmat).m[3][1] = -320.0f; U(expectedmat).m[3][2] = 187.0f; U(expectedmat).m[3][3] = 31.0f;
442 D3DXMatrixMultiply(&gotmat,&mat,&mat2);
443 expect_matrix(&expectedmat, &gotmat, 0);
445 /*____________D3DXMatrixMultiplyTranspose____*/
446 U(expectedmat).m[0][0] = 73.0f; U(expectedmat).m[0][1] = 231.0f; U(expectedmat).m[0][2] = 239.0f; U(expectedmat).m[0][3] = -164.0f;
447 U(expectedmat).m[1][0] = 193.0f; U(expectedmat).m[1][1] = 551.0f; U(expectedmat).m[1][2] = 523.0f; U(expectedmat).m[1][3] = -320.0;
448 U(expectedmat).m[2][0] = -197.0f; U(expectedmat).m[2][1] = -489.0f; U(expectedmat).m[2][2] = -400.0f; U(expectedmat).m[2][3] = 187.0f;
449 U(expectedmat).m[3][0] = -77.0f; U(expectedmat).m[3][1] = -169.0f; U(expectedmat).m[3][2] = -116.0f; U(expectedmat).m[3][3] = 31.0f;
450 D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
451 expect_matrix(&expectedmat, &gotmat, 0);
453 /*____________D3DXMatrixOrthoLH_______________*/
454 U(expectedmat).m[0][0] = 0.8f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
455 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.270270f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
456 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = -0.151515f; U(expectedmat).m[2][3] = 0.0f;
457 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = -0.484848f; U(expectedmat).m[3][3] = 1.0f;
458 D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
459 expect_matrix(&expectedmat, &gotmat, 16);
461 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
462 U(expectedmat).m[0][0] = 3.636364f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
463 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.180180f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
464 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = -0.045662f; U(expectedmat).m[2][3] = 0.0f;
465 U(expectedmat).m[3][0] = -1.727272f; U(expectedmat).m[3][1] = -0.567568f; U(expectedmat).m[3][2] = 0.424658f; U(expectedmat).m[3][3] = 1.0f;
466 D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
467 expect_matrix(&expectedmat, &gotmat, 32);
469 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
470 U(expectedmat).m[0][0] = 3.636364f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
471 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.180180f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
472 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 0.045662f; U(expectedmat).m[2][3] = 0.0f;
473 U(expectedmat).m[3][0] = -1.727272f; U(expectedmat).m[3][1] = -0.567568f; U(expectedmat).m[3][2] = 0.424658f; U(expectedmat).m[3][3] = 1.0f;
474 D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
475 expect_matrix(&expectedmat, &gotmat, 32);
477 /*____________D3DXMatrixOrthoRH_______________*/
478 U(expectedmat).m[0][0] = 0.8f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
479 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.270270f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
480 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 0.151515f; U(expectedmat).m[2][3] = 0.0f;
481 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = -0.484848f; U(expectedmat).m[3][3] = 1.0f;
482 D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
483 expect_matrix(&expectedmat, &gotmat, 16);
485 /*____________D3DXMatrixPerspectiveFovLH_______________*/
486 U(expectedmat).m[0][0] = 13.288858f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
487 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 9.966644f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
488 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 0.783784f; U(expectedmat).m[2][3] = 1.0f;
489 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 1.881081f; U(expectedmat).m[3][3] = 0.0f;
490 D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
491 expect_matrix(&expectedmat, &gotmat, 4);
493 /*____________D3DXMatrixPerspectiveFovRH_______________*/
494 U(expectedmat).m[0][0] = 13.288858f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
495 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 9.966644f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
496 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = -0.783784f; U(expectedmat).m[2][3] = -1.0f;
497 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 1.881081f; U(expectedmat).m[3][3] = 0.0f;
498 D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
499 expect_matrix(&expectedmat, &gotmat, 4);
501 /*____________D3DXMatrixPerspectiveLH_______________*/
502 U(expectedmat).m[0][0] = -24.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
503 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = -6.4f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
504 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 0.783784f; U(expectedmat).m[2][3] = 1.0f;
505 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 1.881081f; U(expectedmat).m[3][3] = 0.0f;
506 D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
507 expect_matrix(&expectedmat, &gotmat, 4);
509 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
510 U(expectedmat).m[0][0] = 11.636364f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
511 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.576577f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
512 U(expectedmat).m[2][0] = -1.727273f; U(expectedmat).m[2][1] = -0.567568f; U(expectedmat).m[2][2] = 0.840796f; U(expectedmat).m[2][3] = 1.0f;
513 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = -2.690547f; U(expectedmat).m[3][3] = 0.0f;
514 D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
515 expect_matrix(&expectedmat, &gotmat, 8);
517 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
518 U(expectedmat).m[0][0] = 11.636364f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
519 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = 0.576577f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
520 U(expectedmat).m[2][0] = 1.727273f; U(expectedmat).m[2][1] = 0.567568f; U(expectedmat).m[2][2] = -0.840796f; U(expectedmat).m[2][3] = -1.0f;
521 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = -2.690547f; U(expectedmat).m[3][3] = 0.0f;
522 D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
523 expect_matrix(&expectedmat, &gotmat, 8);
525 /*____________D3DXMatrixPerspectiveRH_______________*/
526 U(expectedmat).m[0][0] = -24.0f; U(expectedmat).m[0][1] = -0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
527 U(expectedmat).m[1][0] = 0.0f; U(expectedmat).m[1][1] = -6.4f; U(expectedmat).m[1][2] = 0.0; U(expectedmat).m[1][3] = 0.0f;
528 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = -0.783784f; U(expectedmat).m[2][3] = -1.0f;
529 U(expectedmat).m[3][0] = 0.0f; U(expectedmat).m[3][1] = 0.0f; U(expectedmat).m[3][2] = 1.881081f; U(expectedmat).m[3][3] = 0.0f;
530 D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
531 expect_matrix(&expectedmat, &gotmat, 4);
533 /*____________D3DXMatrixReflect______________*/
534 U(expectedmat).m[0][0] = 0.307692f; U(expectedmat).m[0][1] = -0.230769f; U(expectedmat).m[0][2] = 0.923077f; U(expectedmat).m[0][3] = 0.0f;
535 U(expectedmat).m[1][0] = -0.230769; U(expectedmat).m[1][1] = 0.923077f; U(expectedmat).m[1][2] = 0.307693f; U(expectedmat).m[1][3] = 0.0f;
536 U(expectedmat).m[2][0] = 0.923077f; U(expectedmat).m[2][1] = 0.307693f; U(expectedmat).m[2][2] = -0.230769f; U(expectedmat).m[2][3] = 0.0f;
537 U(expectedmat).m[3][0] = 1.615385f; U(expectedmat).m[3][1] = 0.538462f; U(expectedmat).m[3][2] = -2.153846f; U(expectedmat).m[3][3] = 1.0f;
538 D3DXMatrixReflect(&gotmat,&plane);
539 expect_matrix(&expectedmat, &gotmat, 32);
541 /*____________D3DXMatrixRotationAxis_____*/
542 U(expectedmat).m[0][0] = 0.508475f; U(expectedmat).m[0][1] = 0.763805f; U(expectedmat).m[0][2] = 0.397563f; U(expectedmat).m[0][3] = 0.0f;
543 U(expectedmat).m[1][0] = -0.814652f; U(expectedmat).m[1][1] = 0.576271f; U(expectedmat).m[1][2] = -0.065219f; U(expectedmat).m[1][3] = 0.0f;
544 U(expectedmat).m[2][0] = -0.278919f; U(expectedmat).m[2][1] = -0.290713f; U(expectedmat).m[2][2] = 0.915254f; U(expectedmat).m[2][3] = 0.0f;
545 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;
546 D3DXMatrixRotationAxis(&gotmat,&axis,angle);
547 expect_matrix(&expectedmat, &gotmat, 32);
549 /*____________D3DXMatrixRotationQuaternion______________*/
550 U(expectedmat).m[0][0] = -129.0f; U(expectedmat).m[0][1] = -162.0f; U(expectedmat).m[0][2] = -74.0f; U(expectedmat).m[0][3] = 0.0f;
551 U(expectedmat).m[1][0] = 146.0f; U(expectedmat).m[1][1] = -99.0f; U(expectedmat).m[1][2] = -78.0f; U(expectedmat).m[1][3] = 0.0f;
552 U(expectedmat).m[2][0] = 102.0f; U(expectedmat).m[2][1] = -34.0f; U(expectedmat).m[2][2] = -33.0f; U(expectedmat).m[2][3] = 0.0f;
553 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;
554 D3DXMatrixRotationQuaternion(&gotmat,&q);
555 expect_matrix(&expectedmat, &gotmat, 0);
557 /*____________D3DXMatrixRotationX______________*/
558 U(expectedmat).m[0][0] = 1.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
559 U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 0.5f; U(expectedmat).m[1][2] = sqrt(3.0f)/2.0f; U(expectedmat).m[1][3] = 0.0f;
560 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = -sqrt(3.0f)/2.0f; U(expectedmat).m[2][2] = 0.5f; U(expectedmat).m[2][3] = 0.0f;
561 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;
562 D3DXMatrixRotationX(&gotmat,angle);
563 expect_matrix(&expectedmat, &gotmat, 1);
565 /*____________D3DXMatrixRotationY______________*/
566 U(expectedmat).m[0][0] = 0.5f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = -sqrt(3.0f)/2.0f; U(expectedmat).m[0][3] = 0.0f;
567 U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 1.0f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
568 U(expectedmat).m[2][0] = sqrt(3.0f)/2.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 0.5f; U(expectedmat).m[2][3] = 0.0f;
569 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;
570 D3DXMatrixRotationY(&gotmat,angle);
571 expect_matrix(&expectedmat, &gotmat, 1);
573 /*____________D3DXMatrixRotationYawPitchRoll____*/
574 U(expectedmat).m[0][0] = 0.888777f; U(expectedmat).m[0][1] = 0.091875f; U(expectedmat).m[0][2] = -0.449037f; U(expectedmat).m[0][3] = 0.0f;
575 U(expectedmat).m[1][0] = 0.351713f; U(expectedmat).m[1][1] = 0.491487f; U(expectedmat).m[1][2] = 0.796705f; U(expectedmat).m[1][3] = 0.0f;
576 U(expectedmat).m[2][0] = 0.293893f; U(expectedmat).m[2][1] = -0.866025f; U(expectedmat).m[2][2] = 0.404509f; U(expectedmat).m[2][3] = 0.0f;
577 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;
578 D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
579 expect_matrix(&expectedmat, &gotmat, 64);
581 /*____________D3DXMatrixRotationZ______________*/
582 U(expectedmat).m[0][0] = 0.5f; U(expectedmat).m[0][1] = sqrt(3.0f)/2.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
583 U(expectedmat).m[1][0] = -sqrt(3.0f)/2.0f; U(expectedmat).m[1][1] = 0.5f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
584 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 1.0f; U(expectedmat).m[2][3] = 0.0f;
585 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;
586 D3DXMatrixRotationZ(&gotmat,angle);
587 expect_matrix(&expectedmat, &gotmat, 1);
589 /*____________D3DXMatrixScaling______________*/
590 U(expectedmat).m[0][0] = 0.69f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
591 U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 0.53f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
592 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 4.11f; U(expectedmat).m[2][3] = 0.0f;
593 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;
594 D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
595 expect_matrix(&expectedmat, &gotmat, 0);
597 /*____________D3DXMatrixShadow______________*/
598 U(expectedmat).m[0][0] = 12.786773f; U(expectedmat).m[0][1] = 5.000961f; U(expectedmat).m[0][2] = 4.353778f; U(expectedmat).m[0][3] = 3.706595f;
599 U(expectedmat).m[1][0] = 1.882715; U(expectedmat).m[1][1] = 8.805615f; U(expectedmat).m[1][2] = 1.451259f; U(expectedmat).m[1][3] = 1.235532f;
600 U(expectedmat).m[2][0] = -7.530860f; U(expectedmat).m[2][1] = -6.667949f; U(expectedmat).m[2][2] = 1.333590f; U(expectedmat).m[2][3] = -4.942127f;
601 U(expectedmat).m[3][0] = -13.179006f; U(expectedmat).m[3][1] = -11.668910f; U(expectedmat).m[3][2] = -10.158816f; U(expectedmat).m[3][3] = -1.510094f;
602 D3DXMatrixShadow(&gotmat,&light,&plane);
603 expect_matrix(&expectedmat, &gotmat, 8);
605 /*____________D3DXMatrixTransformation______________*/
606 U(expectedmat).m[0][0] = -0.2148f; U(expectedmat).m[0][1] = 1.3116f; U(expectedmat).m[0][2] = 0.4752f; U(expectedmat).m[0][3] = 0.0f;
607 U(expectedmat).m[1][0] = 0.9504f; U(expectedmat).m[1][1] = -0.8836f; U(expectedmat).m[1][2] = 0.9244f; U(expectedmat).m[1][3] = 0.0f;
608 U(expectedmat).m[2][0] = 1.0212f; U(expectedmat).m[2][1] = 0.1936f; U(expectedmat).m[2][2] = -1.3588f; U(expectedmat).m[2][3] = 0.0f;
609 U(expectedmat).m[3][0] = 18.2985f; U(expectedmat).m[3][1] = -29.624001f; U(expectedmat).m[3][2] = 15.683499f; U(expectedmat).m[3][3] = 1.0f;
610 D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
611 expect_matrix(&expectedmat, &gotmat, 512);
613 /*____________D3DXMatrixTranslation______________*/
614 U(expectedmat).m[0][0] = 1.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
615 U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 1.0f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;
616 U(expectedmat).m[2][0] = 0.0f; U(expectedmat).m[2][1] = 0.0f; U(expectedmat).m[2][2] = 1.0f; U(expectedmat).m[2][3] = 0.0f;
617 U(expectedmat).m[3][0] = 0.69f; U(expectedmat).m[3][1] = 0.53f; U(expectedmat).m[3][2] = 4.11f; U(expectedmat).m[3][3] = 1.0f;
618 D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
619 expect_matrix(&expectedmat, &gotmat, 0);
621 /*____________D3DXMatrixTranspose______________*/
622 U(expectedmat).m[0][0] = 10.0f; U(expectedmat).m[0][1] = 11.0f; U(expectedmat).m[0][2] = 19.0f; U(expectedmat).m[0][3] = 2.0f;
623 U(expectedmat).m[1][0] = 5.0; U(expectedmat).m[1][1] = 20.0f; U(expectedmat).m[1][2] = -21.0f; U(expectedmat).m[1][3] = 3.0f;
624 U(expectedmat).m[2][0] = 7.0f; U(expectedmat).m[2][1] = 16.0f; U(expectedmat).m[2][2] = 30.f; U(expectedmat).m[2][3] = -4.0f;
625 U(expectedmat).m[3][0] = 8.0f; U(expectedmat).m[3][1] = 33.0f; U(expectedmat).m[3][2] = 43.0f; U(expectedmat).m[3][3] = -40.0f;
626 D3DXMatrixTranspose(&gotmat,&mat);
627 expect_matrix(&expectedmat, &gotmat, 0);
630 static void D3DXPlaneTest(void)
632 D3DXMATRIX mat;
633 D3DXPLANE expectedplane, gotplane, nulplane, plane;
634 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
635 LPD3DXVECTOR3 funcpointer;
636 D3DXVECTOR4 vec;
637 FLOAT expected, got;
639 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
640 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
641 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
642 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
643 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
644 U(mat).m[3][3] = -40.0f;
646 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
648 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
650 /*_______________D3DXPlaneDot________________*/
651 expected = 42.0f;
652 got = D3DXPlaneDot(&plane,&vec),
653 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
654 expected = 0.0f;
655 got = D3DXPlaneDot(NULL,&vec),
656 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
657 expected = 0.0f;
658 got = D3DXPlaneDot(NULL,NULL),
659 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
661 /*_______________D3DXPlaneDotCoord________________*/
662 expected = -28.0f;
663 got = D3DXPlaneDotCoord(&plane,&vec),
664 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
665 expected = 0.0f;
666 got = D3DXPlaneDotCoord(NULL,&vec),
667 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
668 expected = 0.0f;
669 got = D3DXPlaneDotCoord(NULL,NULL),
670 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
672 /*_______________D3DXPlaneDotNormal______________*/
673 expected = -35.0f;
674 got = D3DXPlaneDotNormal(&plane,&vec),
675 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
676 expected = 0.0f;
677 got = D3DXPlaneDotNormal(NULL,&vec),
678 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
679 expected = 0.0f;
680 got = D3DXPlaneDotNormal(NULL,NULL),
681 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
683 /*_______________D3DXPlaneFromPointNormal_______*/
684 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
685 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
686 expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
687 D3DXPlaneFromPointNormal(&gotplane, &vec1, &vec2);
688 expect_plane(&expectedplane, &gotplane, 0);
689 gotplane.a = vec2.x; gotplane.b = vec2.y; gotplane.c = vec2.z;
690 D3DXPlaneFromPointNormal(&gotplane, &vec1, (D3DXVECTOR3 *)&gotplane);
691 expect_plane(&expectedplane, &gotplane, 0);
692 gotplane.a = vec1.x; gotplane.b = vec1.y; gotplane.c = vec1.z;
693 expectedplane.d = -1826.0f;
694 D3DXPlaneFromPointNormal(&gotplane, (D3DXVECTOR3 *)&gotplane, &vec2);
695 expect_plane(&expectedplane, &gotplane, 0);
697 /*_______________D3DXPlaneFromPoints_______*/
698 vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
699 vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
700 vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
701 expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
702 D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
703 expect_plane(&expectedplane, &gotplane, 64);
705 /*_______________D3DXPlaneIntersectLine___________*/
706 vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
707 vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
708 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
709 D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
710 expect_vec3(&expectedvec, &gotvec, 1);
711 /* Test a parallel line */
712 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
713 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
714 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
715 funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
716 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
718 /*_______________D3DXPlaneNormalize______________*/
719 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);
720 D3DXPlaneNormalize(&gotplane, &plane);
721 expect_plane(&expectedplane, &gotplane, 2);
722 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
723 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
724 D3DXPlaneNormalize(&gotplane, &nulplane);
725 expect_plane(&expectedplane, &gotplane, 0);
727 /*_______________D3DXPlaneTransform____________*/
728 expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
729 D3DXPlaneTransform(&gotplane,&plane,&mat);
730 expect_plane(&expectedplane, &gotplane, 0);
733 static void D3DXQuaternionTest(void)
735 D3DXMATRIX mat;
736 D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
737 BOOL expectedbool, gotbool, equal;
738 float angle, got, scale, scale2;
739 LPD3DXQUATERNION funcpointer;
740 D3DXVECTOR3 axis, expectedvec;
742 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
743 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
744 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
745 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
746 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
747 smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
748 smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallr.w = 0.8f;
750 scale = 0.3f;
751 scale2 = 0.78f;
753 /*_______________D3DXQuaternionBaryCentric________________________*/
754 expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
755 D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
756 expect_quaternion(&expectedquat, &gotquat, 1);
758 /*_______________D3DXQuaternionConjugate________________*/
759 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
760 D3DXQuaternionConjugate(&gotquat,&q);
761 expect_quaternion(&expectedquat, &gotquat, 0);
762 /* Test the NULL case */
763 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
764 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
765 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
766 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
768 /*_______________D3DXQuaternionDot______________________*/
769 got = D3DXQuaternionDot(&q,&r);
770 equal = compare_float(got, 55.0f, 0);
771 ok(equal, "Got unexpected dot %.8e.\n", got);
772 /* Tests the case NULL */
773 got = D3DXQuaternionDot(NULL,&r);
774 equal = compare_float(got, 0.0f, 0);
775 ok(equal, "Got unexpected dot %.8e.\n", got);
776 got = D3DXQuaternionDot(NULL,NULL);
777 equal = compare_float(got, 0.0f, 0);
778 ok(equal, "Got unexpected dot %.8e.\n", got);
780 /*_______________D3DXQuaternionExp______________________________*/
781 expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
782 D3DXQuaternionExp(&gotquat,&q);
783 expect_quaternion(&expectedquat, &gotquat, 16);
784 /* Test the null quaternion */
785 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
786 D3DXQuaternionExp(&gotquat,&nul);
787 expect_quaternion(&expectedquat, &gotquat, 0);
788 /* Test the case where the norm of the quaternion is <1 */
789 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
790 expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
791 D3DXQuaternionExp(&gotquat,&Nq1);
792 expect_quaternion(&expectedquat, &gotquat, 8);
794 /*_______________D3DXQuaternionIdentity________________*/
795 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
796 D3DXQuaternionIdentity(&gotquat);
797 expect_quaternion(&expectedquat, &gotquat, 0);
798 /* Test the NULL case */
799 funcpointer = D3DXQuaternionIdentity(NULL);
800 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
802 /*_______________D3DXQuaternionInverse________________________*/
803 expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
804 D3DXQuaternionInverse(&gotquat,&q);
805 expect_quaternion(&expectedquat, &gotquat, 0);
807 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 10.0f;
808 D3DXQuaternionInverse(&gotquat,&gotquat);
809 expect_quaternion(&expectedquat, &gotquat, 1);
812 /*_______________D3DXQuaternionIsIdentity________________*/
813 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
814 expectedbool = TRUE;
815 gotbool = D3DXQuaternionIsIdentity(&s);
816 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
817 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
818 expectedbool = FALSE;
819 gotbool = D3DXQuaternionIsIdentity(&q);
820 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
821 /* Test the NULL case */
822 gotbool = D3DXQuaternionIsIdentity(NULL);
823 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
825 /*_______________D3DXQuaternionLength__________________________*/
826 got = D3DXQuaternionLength(&q);
827 equal = compare_float(got, 11.0f, 0);
828 ok(equal, "Got unexpected length %.8e.\n", got);
829 /* Tests the case NULL. */
830 got = D3DXQuaternionLength(NULL);
831 equal = compare_float(got, 0.0f, 0);
832 ok(equal, "Got unexpected length %.8e.\n", got);
834 /*_______________D3DXQuaternionLengthSq________________________*/
835 got = D3DXQuaternionLengthSq(&q);
836 equal = compare_float(got, 121.0f, 0);
837 ok(equal, "Got unexpected length %.8e.\n", got);
838 /* Tests the case NULL */
839 got = D3DXQuaternionLengthSq(NULL);
840 equal = compare_float(got, 0.0f, 0);
841 ok(equal, "Got unexpected length %.8e.\n", got);
843 /*_______________D3DXQuaternionLn______________________________*/
844 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
845 D3DXQuaternionLn(&gotquat,&q);
846 expect_quaternion(&expectedquat, &gotquat, 0);
847 expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
848 D3DXQuaternionLn(&gotquat,&r);
849 expect_quaternion(&expectedquat, &gotquat, 0);
850 Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
851 expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
852 D3DXQuaternionLn(&gotquat,&Nq);
853 expect_quaternion(&expectedquat, &gotquat, 32);
854 Nq.x = 0.0f; Nq.y = 0.0f; Nq.z = 0.0f; Nq.w = 1.0f;
855 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
856 D3DXQuaternionLn(&gotquat,&Nq);
857 expect_quaternion(&expectedquat, &gotquat, 0);
858 Nq.x = 5.4f; Nq.y = 1.2f; Nq.z = -0.3f; Nq.w = -0.3f;
859 expectedquat.x = 10.616652f; expectedquat.y = 2.359256f; expectedquat.z = -0.589814f; expectedquat.w = 0.0f;
860 D3DXQuaternionLn(&gotquat,&Nq);
861 expect_quaternion(&expectedquat, &gotquat, 1);
862 /* Test the case where the norm of the quaternion is <1 */
863 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = 0.9f;
864 expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
865 D3DXQuaternionLn(&gotquat,&Nq1);
866 expect_quaternion(&expectedquat, &gotquat, 64);
867 /* Test the case where the real part of the quaternion is -1.0f */
868 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = -1.0f;
869 expectedquat.x = 0.2f; expectedquat.y = 0.1f; expectedquat.z = 0.3f; expectedquat.w = 0.0f;
870 D3DXQuaternionLn(&gotquat,&Nq1);
871 expect_quaternion(&expectedquat, &gotquat, 0);
873 /*_______________D3DXQuaternionMultiply________________________*/
874 expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
875 D3DXQuaternionMultiply(&gotquat,&q,&r);
876 expect_quaternion(&expectedquat, &gotquat, 0);
878 /*_______________D3DXQuaternionNormalize________________________*/
879 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
880 D3DXQuaternionNormalize(&gotquat,&q);
881 expect_quaternion(&expectedquat, &gotquat, 1);
883 /*_______________D3DXQuaternionRotationAxis___________________*/
884 axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
885 angle = D3DX_PI/3.0f;
886 expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
887 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
888 expect_quaternion(&expectedquat, &gotquat, 64);
889 /* Test the nul quaternion */
890 axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
891 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
892 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
893 expect_quaternion(&expectedquat, &gotquat, 8);
895 /*_______________D3DXQuaternionRotationMatrix___________________*/
896 /* test when the trace is >0 */
897 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
898 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
899 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
900 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
901 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
902 U(mat).m[3][3] = 48.0f;
903 expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
904 D3DXQuaternionRotationMatrix(&gotquat,&mat);
905 expect_quaternion(&expectedquat, &gotquat, 16);
906 /* test the case when the greater element is (2,2) */
907 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
908 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
909 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
910 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
911 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
912 U(mat).m[3][3] = 48.0f;
913 expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
914 D3DXQuaternionRotationMatrix(&gotquat,&mat);
915 expect_quaternion(&expectedquat, &gotquat, 64);
916 /* test the case when the greater element is (1,1) */
917 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
918 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
919 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
920 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
921 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
922 U(mat).m[3][3] = 48.0f;
923 expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
924 D3DXQuaternionRotationMatrix(&gotquat,&mat);
925 expect_quaternion(&expectedquat, &gotquat, 8);
926 /* test the case when the trace is near 0 in a matrix which is not a rotation */
927 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
928 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
929 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
930 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
931 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
932 U(mat).m[3][3] = 48.0f;
933 expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
934 D3DXQuaternionRotationMatrix(&gotquat,&mat);
935 expect_quaternion(&expectedquat, &gotquat, 8);
936 /* test the case when the trace is 0.49 in a matrix which is not a rotation */
937 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
938 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
939 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
940 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
941 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
942 U(mat).m[3][3] = 48.0f;
943 expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
944 D3DXQuaternionRotationMatrix(&gotquat,&mat);
945 expect_quaternion(&expectedquat, &gotquat, 8);
946 /* test the case when the trace is 0.51 in a matrix which is not a rotation */
947 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
948 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
949 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
950 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
951 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
952 U(mat).m[3][3] = 48.0f;
953 expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
954 D3DXQuaternionRotationMatrix(&gotquat,&mat);
955 expect_quaternion(&expectedquat, &gotquat, 8);
956 /* test the case when the trace is 0.99 in a matrix which is not a rotation */
957 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
958 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
959 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
960 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
961 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
962 U(mat).m[3][3] = 48.0f;
963 expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
964 D3DXQuaternionRotationMatrix(&gotquat,&mat);
965 expect_quaternion(&expectedquat, &gotquat, 4);
966 /* test the case when the trace is 1.0 in a matrix which is not a rotation */
967 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
968 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
969 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
970 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
971 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
972 U(mat).m[3][3] = 48.0f;
973 expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
974 D3DXQuaternionRotationMatrix(&gotquat,&mat);
975 expect_quaternion(&expectedquat, &gotquat, 8);
976 /* test the case when the trace is 1.01 in a matrix which is not a rotation */
977 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
978 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
979 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
980 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
981 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
982 U(mat).m[3][3] = 48.0f;
983 expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
984 D3DXQuaternionRotationMatrix(&gotquat,&mat);
985 expect_quaternion(&expectedquat, &gotquat, 4);
986 /* test the case when the trace is 1.5 in a matrix which is not a rotation */
987 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
988 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
989 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
990 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
991 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
992 U(mat).m[3][3] = 48.0f;
993 expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
994 D3DXQuaternionRotationMatrix(&gotquat,&mat);
995 expect_quaternion(&expectedquat, &gotquat, 8);
996 /* test the case when the trace is 1.7 in a matrix which is not a rotation */
997 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
998 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
999 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1000 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1001 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
1002 U(mat).m[3][3] = 48.0f;
1003 expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
1004 D3DXQuaternionRotationMatrix(&gotquat,&mat);
1005 expect_quaternion(&expectedquat, &gotquat, 4);
1006 /* test the case when the trace is 1.99 in a matrix which is not a rotation */
1007 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1008 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1009 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1010 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1011 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
1012 U(mat).m[3][3] = 48.0f;
1013 expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
1014 D3DXQuaternionRotationMatrix(&gotquat,&mat);
1015 expect_quaternion(&expectedquat, &gotquat, 4);
1016 /* test the case when the trace is 2.0 in a matrix which is not a rotation */
1017 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
1018 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
1019 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
1020 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
1021 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
1022 U(mat).m[3][3] = 48.0f;
1023 expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
1024 D3DXQuaternionRotationMatrix(&gotquat,&mat);
1025 expect_quaternion(&expectedquat, &gotquat, 8);
1027 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
1028 expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
1029 D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
1030 expect_quaternion(&expectedquat, &gotquat, 16);
1032 /*_______________D3DXQuaternionSlerp________________________*/
1033 expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
1034 D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
1035 expect_quaternion(&expectedquat, &gotquat, 4);
1036 expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
1037 D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
1038 expect_quaternion(&expectedquat, &gotquat, 2);
1039 expectedquat.x = 0.239485f; expectedquat.y = 0.346580f; expectedquat.z = 0.453676f; expectedquat.w = 0.560772f;
1040 D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
1041 expect_quaternion(&expectedquat, &gotquat, 32);
1043 /*_______________D3DXQuaternionSquad________________________*/
1044 expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
1045 D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
1046 expect_quaternion(&expectedquat, &gotquat, 2);
1048 /*_______________D3DXQuaternionSquadSetup___________________*/
1049 r.x = 1.0f, r.y = 2.0f; r.z = 4.0f; r.w = 10.0f;
1050 s.x = -3.0f; s.y = 4.0f; s.z = -5.0f; s.w = 7.0;
1051 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
1052 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
1053 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1054 expectedquat.x = 7.121285f; expectedquat.y = 2.159964f; expectedquat.z = -3.855094f; expectedquat.w = 5.362844f;
1055 expect_quaternion(&expectedquat, &gotquat, 2);
1056 expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
1057 expect_quaternion(&expectedquat, &Nq, 2);
1058 expectedquat.x = -1111.0f; expectedquat.y = 111.0f; expectedquat.z = -11.0f; expectedquat.w = 1.0f;
1059 expect_quaternion(&expectedquat, &Nq1, 0);
1060 gotquat = s;
1061 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &gotquat, &t, &u);
1062 expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
1063 expect_quaternion(&expectedquat, &Nq, 2);
1064 Nq1 = u;
1065 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &Nq1);
1066 expect_quaternion(&expectedquat, &Nq, 2);
1067 r.x = 0.2f; r.y = 0.3f; r.z = 1.3f; r.w = -0.6f;
1068 s.x = -3.0f; s.y =-2.0f; s.z = 4.0f; s.w = 0.2f;
1069 t.x = 0.4f; t.y = 8.3f; t.z = -3.1f; t.w = -2.7f;
1070 u.x = 1.1f; u.y = -0.7f; u.z = 9.2f; u.w = 0.0f;
1071 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &u, &t);
1072 expectedquat.x = -4.139569f; expectedquat.y = -2.469115f; expectedquat.z = 2.364477f; expectedquat.w = 0.465494f;
1073 expect_quaternion(&expectedquat, &gotquat, 16);
1074 expectedquat.x = 2.342533f; expectedquat.y = 2.365127f; expectedquat.z = 8.628538f; expectedquat.w = -0.898356f;
1075 expect_quaternion(&expectedquat, &Nq, 16);
1076 expectedquat.x = 1.1f; expectedquat.y = -0.7f; expectedquat.z = 9.2f; expectedquat.w = 0.0f;
1077 expect_quaternion(&expectedquat, &Nq1, 0);
1078 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1079 expectedquat.x = -3.754567f; expectedquat.y = -0.586085f; expectedquat.z = 3.815818f; expectedquat.w = -0.198150f;
1080 expect_quaternion(&expectedquat, &gotquat, 32);
1081 expectedquat.x = 0.140773f; expectedquat.y = -8.737090f; expectedquat.z = -0.516593f; expectedquat.w = 3.053942f;
1082 expect_quaternion(&expectedquat, &Nq, 16);
1083 expectedquat.x = -0.4f; expectedquat.y = -8.3f; expectedquat.z = 3.1f; expectedquat.w = 2.7f;
1084 expect_quaternion(&expectedquat, &Nq1, 0);
1085 r.x = -1.0f; r.y = 0.0f; r.z = 0.0f; r.w = 0.0f;
1086 s.x = 1.0f; s.y =0.0f; s.z = 0.0f; s.w = 0.0f;
1087 t.x = 1.0f; t.y = 0.0f; t.z = 0.0f; t.w = 0.0f;
1088 u.x = -1.0f; u.y = 0.0f; u.z = 0.0f; u.w = 0.0f;
1089 D3DXQuaternionSquadSetup(&gotquat, &Nq, &Nq1, &r, &s, &t, &u);
1090 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1091 expect_quaternion(&expectedquat, &gotquat, 0);
1092 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1093 expect_quaternion(&expectedquat, &Nq, 0);
1094 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1095 expect_quaternion(&expectedquat, &Nq1, 0);
1097 /*_______________D3DXQuaternionToAxisAngle__________________*/
1098 Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
1099 expectedvec.x = 1.0f/22.0f; expectedvec.y = 2.0f/22.0f; expectedvec.z = 4.0f/22.0f;
1100 D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
1101 expect_vec3(&expectedvec, &axis, 0);
1102 equal = compare_float(angle, 2.197869f, 0);
1103 ok(equal, "Got unexpected angle %.8e.\n", angle);
1104 /* Test if |w|>1.0f */
1105 expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f;
1106 D3DXQuaternionToAxisAngle(&q,&axis,&angle);
1107 expect_vec3(&expectedvec, &axis, 0);
1108 /* Test the null quaternion */
1109 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1110 D3DXQuaternionToAxisAngle(&nul, &axis, &angle);
1111 expect_vec3(&expectedvec, &axis, 0);
1112 equal = compare_float(angle, 3.14159274e+00f, 0);
1113 ok(equal, "Got unexpected angle %.8e.\n", angle);
1115 D3DXQuaternionToAxisAngle(&nul, &axis, NULL);
1116 D3DXQuaternionToAxisAngle(&nul, NULL, &angle);
1117 expect_vec3(&expectedvec, &axis, 0);
1118 equal = compare_float(angle, 3.14159274e+00f, 0);
1119 ok(equal, "Got unexpected angle %.8e.\n", angle);
1122 static void D3DXVector2Test(void)
1124 D3DXVECTOR2 expectedvec, gotvec, nul, u, v, w, x;
1125 LPD3DXVECTOR2 funcpointer;
1126 D3DXVECTOR4 expectedtrans, gottrans;
1127 float coeff1, coeff2, got, scale;
1128 D3DXMATRIX mat;
1129 BOOL equal;
1131 nul.x = 0.0f; nul.y = 0.0f;
1132 u.x = 3.0f; u.y = 4.0f;
1133 v.x = -7.0f; v.y = 9.0f;
1134 w.x = 4.0f; w.y = -3.0f;
1135 x.x = 2.0f; x.y = -11.0f;
1137 U(mat).m[0][0] = 1.0f; U(mat).m[0][1] = 2.0f; U(mat).m[0][2] = 3.0f; U(mat).m[0][3] = 4.0f;
1138 U(mat).m[1][0] = 5.0f; U(mat).m[1][1] = 6.0f; U(mat).m[1][2] = 7.0f; U(mat).m[1][3] = 8.0f;
1139 U(mat).m[2][0] = 9.0f; U(mat).m[2][1] = 10.0f; U(mat).m[2][2] = 11.0f; U(mat).m[2][3] = 12.0f;
1140 U(mat).m[3][0] = 13.0f; U(mat).m[3][1] = 14.0f; U(mat).m[3][2] = 15.0f; U(mat).m[3][3] = 16.0f;
1142 coeff1 = 2.0f; coeff2 = 5.0f;
1143 scale = -6.5f;
1145 /*_______________D3DXVec2Add__________________________*/
1146 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
1147 D3DXVec2Add(&gotvec,&u,&v);
1148 expect_vec2(&expectedvec, &gotvec, 0);
1149 /* Tests the case NULL */
1150 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
1151 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1152 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
1153 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1155 /*_______________D3DXVec2BaryCentric___________________*/
1156 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
1157 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1158 expect_vec2(&expectedvec, &gotvec, 0);
1160 /*_______________D3DXVec2CatmullRom____________________*/
1161 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
1162 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1163 expect_vec2(&expectedvec, &gotvec, 0);
1165 /*_______________D3DXVec2CCW__________________________*/
1166 got = D3DXVec2CCW(&u, &v);
1167 equal = compare_float(got, 55.0f, 0);
1168 ok(equal, "Got unexpected ccw %.8e.\n", got);
1169 /* Tests the case NULL. */
1170 got = D3DXVec2CCW(NULL, &v);
1171 equal = compare_float(got, 0.0f, 0);
1172 ok(equal, "Got unexpected ccw %.8e.\n", got);
1173 got = D3DXVec2CCW(NULL, NULL);
1174 equal = compare_float(got, 0.0f, 0);
1175 ok(equal, "Got unexpected ccw %.8e.\n", got);
1177 /*_______________D3DXVec2Dot__________________________*/
1178 got = D3DXVec2Dot(&u, &v);
1179 equal = compare_float(got, 15.0f, 0);
1180 ok(equal, "Got unexpected dot %.8e.\n", got);
1181 /* Tests the case NULL */
1182 got = D3DXVec2Dot(NULL, &v);
1183 equal = compare_float(got, 0.0f, 0);
1184 ok(equal, "Got unexpected dot %.8e.\n", got);
1185 got = D3DXVec2Dot(NULL, NULL);
1186 equal = compare_float(got, 0.0f, 0);
1187 ok(equal, "Got unexpected dot %.8e.\n", got);
1189 /*_______________D3DXVec2Hermite__________________________*/
1190 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
1191 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
1192 expect_vec2(&expectedvec, &gotvec, 0);
1194 /*_______________D3DXVec2Length__________________________*/
1195 got = D3DXVec2Length(&u);
1196 equal = compare_float(got, 5.0f, 0);
1197 ok(equal, "Got unexpected length %.8e.\n", got);
1198 /* Tests the case NULL. */
1199 got = D3DXVec2Length(NULL);
1200 equal = compare_float(got, 0.0f, 0);
1201 ok(equal, "Got unexpected length %.8e.\n", got);
1203 /*_______________D3DXVec2LengthSq________________________*/
1204 got = D3DXVec2LengthSq(&u);
1205 equal = compare_float(got, 25.0f, 0);
1206 ok(equal, "Got unexpected length %.8e.\n", got);
1207 /* Tests the case NULL. */
1208 got = D3DXVec2LengthSq(NULL);
1209 equal = compare_float(got, 0.0f, 0);
1210 ok(equal, "Got unexpected length %.8e.\n", got);
1212 /*_______________D3DXVec2Lerp__________________________*/
1213 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
1214 D3DXVec2Lerp(&gotvec, &u, &v, scale);
1215 expect_vec2(&expectedvec, &gotvec, 0);
1216 /* Tests the case NULL. */
1217 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
1218 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1219 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1220 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1222 /*_______________D3DXVec2Maximize__________________________*/
1223 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1224 D3DXVec2Maximize(&gotvec, &u, &v);
1225 expect_vec2(&expectedvec, &gotvec, 0);
1226 /* Tests the case NULL. */
1227 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1228 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1229 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1230 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1232 /*_______________D3DXVec2Minimize__________________________*/
1233 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1234 D3DXVec2Minimize(&gotvec,&u,&v);
1235 expect_vec2(&expectedvec, &gotvec, 0);
1236 /* Tests the case NULL */
1237 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1238 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1239 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1240 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1242 /*_______________D3DXVec2Normalize_________________________*/
1243 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1244 D3DXVec2Normalize(&gotvec,&u);
1245 expect_vec2(&expectedvec, &gotvec, 0);
1246 /* Test the nul vector */
1247 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1248 D3DXVec2Normalize(&gotvec,&nul);
1249 expect_vec2(&expectedvec, &gotvec, 0);
1251 /*_______________D3DXVec2Scale____________________________*/
1252 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1253 D3DXVec2Scale(&gotvec,&u,scale);
1254 expect_vec2(&expectedvec, &gotvec, 0);
1255 /* Tests the case NULL */
1256 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
1257 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1258 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
1259 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1261 /*_______________D3DXVec2Subtract__________________________*/
1262 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
1263 D3DXVec2Subtract(&gotvec, &u, &v);
1264 expect_vec2(&expectedvec, &gotvec, 0);
1265 /* Tests the case NULL. */
1266 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
1267 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1268 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
1269 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1271 /*_______________D3DXVec2Transform_______________________*/
1272 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
1273 D3DXVec2Transform(&gottrans, &u, &mat);
1274 expect_vec4(&expectedtrans, &gottrans, 0);
1275 gottrans.x = u.x; gottrans.y = u.y;
1276 D3DXVec2Transform(&gottrans, (D3DXVECTOR2 *)&gottrans, &mat);
1277 expect_vec4(&expectedtrans, &gottrans, 0);
1279 /*_______________D3DXVec2TransformCoord_______________________*/
1280 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
1281 D3DXVec2TransformCoord(&gotvec, &u, &mat);
1282 expect_vec2(&expectedvec, &gotvec, 1);
1283 gotvec.x = u.x; gotvec.y = u.y;
1284 D3DXVec2TransformCoord(&gotvec, (D3DXVECTOR2 *)&gotvec, &mat);
1285 expect_vec2(&expectedvec, &gotvec, 1);
1287 /*_______________D3DXVec2TransformNormal______________________*/
1288 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1289 D3DXVec2TransformNormal(&gotvec,&u,&mat);
1290 expect_vec2(&expectedvec, &gotvec, 0);
1293 static void D3DXVector3Test(void)
1295 D3DVIEWPORT9 viewport;
1296 D3DXVECTOR3 expectedvec, gotvec, nul, u, v, w, x;
1297 LPD3DXVECTOR3 funcpointer;
1298 D3DXVECTOR4 expectedtrans, gottrans;
1299 D3DXMATRIX mat, projection, view, world;
1300 float coeff1, coeff2, got, scale;
1301 BOOL equal;
1303 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
1304 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
1305 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
1306 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
1307 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
1309 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1310 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
1312 U(mat).m[0][0] = 1.0f; U(mat).m[0][1] = 2.0f; U(mat).m[0][2] = 3.0f; U(mat).m[0][3] = 4.0f;
1313 U(mat).m[1][0] = 5.0f; U(mat).m[1][1] = 6.0f; U(mat).m[1][2] = 7.0f; U(mat).m[1][3] = 8.0f;
1314 U(mat).m[2][0] = 9.0f; U(mat).m[2][1] = 10.0f; U(mat).m[2][2] = 11.0f; U(mat).m[2][3] = 12.0f;
1315 U(mat).m[3][0] = 13.0f; U(mat).m[3][1] = 14.0f; U(mat).m[3][2] = 15.0f; U(mat).m[3][3] = 16.0f;
1317 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
1318 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
1319 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
1320 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
1321 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
1322 U(view).m[3][3] = -40.0f;
1324 U(world).m[0][0] = 21.0f; U(world).m[0][1] = 2.0f; U(world).m[0][2] = 3.0f; U(world).m[0][3] = 4.0;
1325 U(world).m[1][0] = 5.0f; U(world).m[1][1] = 23.0f; U(world).m[1][2] = 7.0f; U(world).m[1][3] = 8.0f;
1326 U(world).m[2][0] = -8.0f; U(world).m[2][1] = -7.0f; U(world).m[2][2] = 25.0f; U(world).m[2][3] = -5.0f;
1327 U(world).m[3][0] = -4.0f; U(world).m[3][1] = -3.0f; U(world).m[3][2] = -2.0f; U(world).m[3][3] = 27.0f;
1329 coeff1 = 2.0f; coeff2 = 5.0f;
1330 scale = -6.5f;
1332 /*_______________D3DXVec3Add__________________________*/
1333 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
1334 D3DXVec3Add(&gotvec,&u,&v);
1335 expect_vec3(&expectedvec, &gotvec, 0);
1336 /* Tests the case NULL */
1337 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
1338 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1339 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
1340 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1342 /*_______________D3DXVec3BaryCentric___________________*/
1343 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1344 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1345 expect_vec3(&expectedvec, &gotvec, 0);
1347 /*_______________D3DXVec3CatmullRom____________________*/
1348 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
1349 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1350 expect_vec3(&expectedvec, &gotvec, 0);
1352 /*_______________D3DXVec3Cross________________________*/
1353 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
1354 D3DXVec3Cross(&gotvec,&u,&v);
1355 expect_vec3(&expectedvec, &gotvec, 0);
1356 expectedvec.x = -277.0f; expectedvec.y = -150.0f; expectedvec.z = -26.0f;
1357 D3DXVec3Cross(&gotvec,&gotvec,&v);
1358 expect_vec3(&expectedvec, &gotvec, 0);
1359 /* Tests the case NULL */
1360 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
1361 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1362 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
1363 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1365 /*_______________D3DXVec3Dot__________________________*/
1366 got = D3DXVec3Dot(&u, &v);
1367 equal = compare_float(got, -8.0f, 0);
1368 ok(equal, "Got unexpected dot %.8e.\n", got);
1369 /* Tests the case NULL */
1370 got = D3DXVec3Dot(NULL, &v);
1371 equal = compare_float(got, 0.0f, 0);
1372 ok(equal, "Got unexpected dot %.8e.\n", got);
1373 got = D3DXVec3Dot(NULL, NULL);
1374 equal = compare_float(got, 0.0f, 0);
1375 ok(equal, "Got unexpected dot %.8e.\n", got);
1377 /*_______________D3DXVec3Hermite__________________________*/
1378 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
1379 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
1380 expect_vec3(&expectedvec, &gotvec, 0);
1382 /*_______________D3DXVec3Length__________________________*/
1383 got = D3DXVec3Length(&u);
1384 equal = compare_float(got, 11.0f, 0);
1385 ok(equal, "Got unexpected length %.8e.\n", got);
1386 /* Tests the case NULL. */
1387 got = D3DXVec3Length(NULL);
1388 equal = compare_float(got, 0.0f, 0);
1389 ok(equal, "Got unexpected length %.8e.\n", got);
1391 /*_______________D3DXVec3LengthSq________________________*/
1392 got = D3DXVec3LengthSq(&u);
1393 equal = compare_float(got, 121.0f, 0);
1394 ok(equal, "Got unexpected length %.8e.\n", got);
1395 /* Tests the case NULL. */
1396 got = D3DXVec3LengthSq(NULL);
1397 equal = compare_float(got, 0.0f, 0);
1398 ok(equal, "Got unexpected length %.8e.\n", got);
1400 /*_______________D3DXVec3Lerp__________________________*/
1401 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
1402 D3DXVec3Lerp(&gotvec,&u,&v,scale);
1403 expect_vec3(&expectedvec, &gotvec, 0);
1404 /* Tests the case NULL */
1405 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
1406 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1407 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
1408 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1410 /*_______________D3DXVec3Maximize__________________________*/
1411 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
1412 D3DXVec3Maximize(&gotvec,&u,&v);
1413 expect_vec3(&expectedvec, &gotvec, 0);
1414 /* Tests the case NULL */
1415 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
1416 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1417 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
1418 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1420 /*_______________D3DXVec3Minimize__________________________*/
1421 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
1422 D3DXVec3Minimize(&gotvec,&u,&v);
1423 expect_vec3(&expectedvec, &gotvec, 0);
1424 /* Tests the case NULL */
1425 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
1426 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1427 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
1428 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1430 /*_______________D3DXVec3Normalize_________________________*/
1431 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
1432 D3DXVec3Normalize(&gotvec,&u);
1433 expect_vec3(&expectedvec, &gotvec, 1);
1434 /* Test the nul vector */
1435 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1436 D3DXVec3Normalize(&gotvec,&nul);
1437 expect_vec3(&expectedvec, &gotvec, 0);
1439 /*_______________D3DXVec3Scale____________________________*/
1440 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
1441 D3DXVec3Scale(&gotvec,&u,scale);
1442 expect_vec3(&expectedvec, &gotvec, 0);
1443 /* Tests the case NULL */
1444 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
1445 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1446 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
1447 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1449 /*_______________D3DXVec3Subtract_______________________*/
1450 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1451 D3DXVec3Subtract(&gotvec,&u,&v);
1452 expect_vec3(&expectedvec, &gotvec, 0);
1453 /* Tests the case NULL */
1454 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1455 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1456 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1457 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1459 /*_______________D3DXVec3Transform_______________________*/
1460 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1461 D3DXVec3Transform(&gottrans, &u, &mat);
1462 expect_vec4(&expectedtrans, &gottrans, 0);
1464 gottrans.x = u.x; gottrans.y = u.y; gottrans.z = u.z;
1465 D3DXVec3Transform(&gottrans, (D3DXVECTOR3 *)&gottrans, &mat);
1466 expect_vec4(&expectedtrans, &gottrans, 0);
1468 /*_______________D3DXVec3TransformCoord_______________________*/
1469 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1470 D3DXVec3TransformCoord(&gotvec,&u,&mat);
1471 expect_vec3(&expectedvec, &gotvec, 1);
1473 /*_______________D3DXVec3TransformNormal______________________*/
1474 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1475 D3DXVec3TransformNormal(&gotvec,&u,&mat);
1476 expect_vec3(&expectedvec, &gotvec, 0);
1478 /*_______________D3DXVec3Project_________________________*/
1479 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
1480 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1481 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
1482 expect_vec3(&expectedvec, &gotvec, 32);
1483 /* World matrix can be omitted */
1484 D3DXMatrixMultiply(&mat,&world,&view);
1485 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&mat,NULL);
1486 expect_vec3(&expectedvec, &gotvec, 32);
1487 /* Projection matrix can be omitted */
1488 D3DXMatrixMultiply(&mat,&view,&projection);
1489 D3DXVec3Project(&gotvec,&u,&viewport,NULL,&mat,&world);
1490 expect_vec3(&expectedvec, &gotvec, 32);
1491 /* View matrix can be omitted */
1492 D3DXMatrixMultiply(&mat,&world,&view);
1493 D3DXVec3Project(&gotvec,&u,&viewport,&projection,NULL,&mat);
1494 expect_vec3(&expectedvec, &gotvec, 32);
1495 /* All matrices can be omitted */
1496 expectedvec.x = 4010.000000f; expectedvec.y = -1695.000000f; expectedvec.z = 1.600000f;
1497 D3DXVec3Project(&gotvec,&u,&viewport,NULL,NULL,NULL);
1498 expect_vec3(&expectedvec, &gotvec, 2);
1499 /* Viewport can be omitted */
1500 expectedvec.x = 1.814305f; expectedvec.y = 0.582097f; expectedvec.z = -0.066555f;
1501 D3DXVec3Project(&gotvec,&u,NULL,&projection,&view,&world);
1502 expect_vec3(&expectedvec, &gotvec, 64);
1504 /*_______________D3DXVec3Unproject_________________________*/
1505 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1506 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1507 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1508 expect_vec3(&expectedvec, &gotvec, 16);
1509 /* World matrix can be omitted */
1510 D3DXMatrixMultiply(&mat,&world,&view);
1511 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&mat,NULL);
1512 expect_vec3(&expectedvec, &gotvec, 16);
1513 /* Projection matrix can be omitted */
1514 D3DXMatrixMultiply(&mat,&view,&projection);
1515 D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,&mat,&world);
1516 expect_vec3(&expectedvec, &gotvec, 32);
1517 /* View matrix can be omitted */
1518 D3DXMatrixMultiply(&mat,&world,&view);
1519 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,NULL,&mat);
1520 expect_vec3(&expectedvec, &gotvec, 16);
1521 /* All matrices can be omitted */
1522 expectedvec.x = -1.002500f; expectedvec.y = 0.997059f; expectedvec.z = 2.571429f;
1523 D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,NULL,NULL);
1524 expect_vec3(&expectedvec, &gotvec, 4);
1525 /* Viewport can be omitted */
1526 expectedvec.x = -11.018396f; expectedvec.y = 3.218991f; expectedvec.z = 1.380329f;
1527 D3DXVec3Unproject(&gotvec,&u,NULL,&projection,&view,&world);
1528 expect_vec3(&expectedvec, &gotvec, 8);
1531 static void D3DXVector4Test(void)
1533 D3DXVECTOR4 expectedvec, gotvec, u, v, w, x;
1534 LPD3DXVECTOR4 funcpointer;
1535 D3DXVECTOR4 expectedtrans, gottrans;
1536 float coeff1, coeff2, got, scale;
1537 D3DXMATRIX mat;
1538 BOOL equal;
1540 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1541 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1542 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1543 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1545 U(mat).m[0][0] = 1.0f; U(mat).m[0][1] = 2.0f; U(mat).m[0][2] = 3.0f; U(mat).m[0][3] = 4.0f;
1546 U(mat).m[1][0] = 5.0f; U(mat).m[1][1] = 6.0f; U(mat).m[1][2] = 7.0f; U(mat).m[1][3] = 8.0f;
1547 U(mat).m[2][0] = 9.0f; U(mat).m[2][1] = 10.0f; U(mat).m[2][2] = 11.0f; U(mat).m[2][3] = 12.0f;
1548 U(mat).m[3][0] = 13.0f; U(mat).m[3][1] = 14.0f; U(mat).m[3][2] = 15.0f; U(mat).m[3][3] = 16.0f;
1550 coeff1 = 2.0f; coeff2 = 5.0;
1551 scale = -6.5f;
1553 /*_______________D3DXVec4Add__________________________*/
1554 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1555 D3DXVec4Add(&gotvec,&u,&v);
1556 expect_vec4(&expectedvec, &gotvec, 0);
1557 /* Tests the case NULL */
1558 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1559 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1560 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1561 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1563 /*_______________D3DXVec4BaryCentric____________________*/
1564 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
1565 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1566 expect_vec4(&expectedvec, &gotvec, 0);
1568 /*_______________D3DXVec4CatmullRom____________________*/
1569 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1570 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1571 expect_vec4(&expectedvec, &gotvec, 0);
1573 /*_______________D3DXVec4Cross_________________________*/
1574 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1575 D3DXVec4Cross(&gotvec,&u,&v,&w);
1576 expect_vec4(&expectedvec, &gotvec, 0);
1578 /*_______________D3DXVec4Dot__________________________*/
1579 got = D3DXVec4Dot(&u, &v);
1580 equal = compare_float(got, 55.0f, 0);
1581 ok(equal, "Got unexpected dot %.8e.\n", got);
1582 /* Tests the case NULL. */
1583 got = D3DXVec4Dot(NULL, &v);
1584 equal = compare_float(got, 0.0f, 0);
1585 ok(equal, "Got unexpected dot %.8e.\n", got);
1586 got = D3DXVec4Dot(NULL, NULL);
1587 equal = compare_float(got, 0.0f, 0);
1588 ok(equal, "Got unexpected dot %.8e.\n", got);
1590 /*_______________D3DXVec4Hermite_________________________*/
1591 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1592 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1593 expect_vec4(&expectedvec, &gotvec, 0);
1595 /*_______________D3DXVec4Length__________________________*/
1596 got = D3DXVec4Length(&u);
1597 equal = compare_float(got, 11.0f, 0);
1598 ok(equal, "Got unexpected length %.8e.\n", got);
1599 /* Tests the case NULL. */
1600 got = D3DXVec4Length(NULL);
1601 equal = compare_float(got, 0.0f, 0);
1602 ok(equal, "Got unexpected length %.8e.\n", got);
1604 /*_______________D3DXVec4LengthSq________________________*/
1605 got = D3DXVec4LengthSq(&u);
1606 equal = compare_float(got, 121.0f, 0);
1607 ok(equal, "Got unexpected length %.8e.\n", got);
1608 /* Tests the case NULL. */
1609 got = D3DXVec4LengthSq(NULL);
1610 equal = compare_float(got, 0.0f, 0);
1611 ok(equal, "Got unexpected length %.8e.\n", got);
1613 /*_______________D3DXVec4Lerp__________________________*/
1614 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1615 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1616 expect_vec4(&expectedvec, &gotvec, 0);
1617 /* Tests the case NULL */
1618 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1619 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1620 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1621 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1623 /*_______________D3DXVec4Maximize__________________________*/
1624 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1625 D3DXVec4Maximize(&gotvec,&u,&v);
1626 expect_vec4(&expectedvec, &gotvec, 0);
1627 /* Tests the case NULL */
1628 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1629 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1630 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1631 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1633 /*_______________D3DXVec4Minimize__________________________*/
1634 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1635 D3DXVec4Minimize(&gotvec,&u,&v);
1636 expect_vec4(&expectedvec, &gotvec, 0);
1637 /* Tests the case NULL */
1638 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1639 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1640 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1641 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1643 /*_______________D3DXVec4Normalize_________________________*/
1644 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1645 D3DXVec4Normalize(&gotvec,&u);
1646 expect_vec4(&expectedvec, &gotvec, 1);
1648 /*_______________D3DXVec4Scale____________________________*/
1649 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1650 D3DXVec4Scale(&gotvec,&u,scale);
1651 expect_vec4(&expectedvec, &gotvec, 0);
1652 /* Tests the case NULL */
1653 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1654 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1655 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1656 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1658 /*_______________D3DXVec4Subtract__________________________*/
1659 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1660 D3DXVec4Subtract(&gotvec,&u,&v);
1661 expect_vec4(&expectedvec, &gotvec, 0);
1662 /* Tests the case NULL */
1663 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1664 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1665 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1666 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1668 /*_______________D3DXVec4Transform_______________________*/
1669 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1670 D3DXVec4Transform(&gottrans,&u,&mat);
1671 expect_vec4(&expectedtrans, &gottrans, 0);
1674 static void test_matrix_stack(void)
1676 ID3DXMatrixStack *stack;
1677 ULONG refcount;
1678 HRESULT hr;
1680 const D3DXMATRIX mat1 = {{{
1681 1.0f, 2.0f, 3.0f, 4.0f,
1682 5.0f, 6.0f, 7.0f, 8.0f,
1683 9.0f, 10.0f, 11.0f, 12.0f,
1684 13.0f, 14.0f, 15.0f, 16.0f
1685 }}};
1687 const D3DXMATRIX mat2 = {{{
1688 17.0f, 18.0f, 19.0f, 20.0f,
1689 21.0f, 22.0f, 23.0f, 24.0f,
1690 25.0f, 26.0f, 27.0f, 28.0f,
1691 29.0f, 30.0f, 31.0f, 32.0f
1692 }}};
1694 hr = D3DXCreateMatrixStack(0, &stack);
1695 ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1696 if (FAILED(hr)) return;
1698 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1699 "The top of an empty matrix stack should be an identity matrix\n");
1701 hr = ID3DXMatrixStack_Pop(stack);
1702 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1704 hr = ID3DXMatrixStack_Push(stack);
1705 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1706 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1708 hr = ID3DXMatrixStack_Push(stack);
1709 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1711 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1712 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1713 expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
1715 hr = ID3DXMatrixStack_Push(stack);
1716 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1717 expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
1719 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1720 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1721 expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
1723 hr = ID3DXMatrixStack_Push(stack);
1724 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1725 expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
1727 hr = ID3DXMatrixStack_LoadIdentity(stack);
1728 ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
1729 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1731 hr = ID3DXMatrixStack_Pop(stack);
1732 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1733 expect_matrix(&mat2, ID3DXMatrixStack_GetTop(stack), 0);
1735 hr = ID3DXMatrixStack_Pop(stack);
1736 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1737 expect_matrix(&mat1, ID3DXMatrixStack_GetTop(stack), 0);
1739 hr = ID3DXMatrixStack_Pop(stack);
1740 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1741 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1743 hr = ID3DXMatrixStack_Pop(stack);
1744 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1745 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1747 refcount = ID3DXMatrixStack_Release(stack);
1748 ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1751 static void test_Matrix_AffineTransformation2D(void)
1753 D3DXMATRIX exp_mat, got_mat;
1754 D3DXVECTOR2 center, position;
1755 FLOAT angle, scale;
1757 center.x = 3.0f;
1758 center.y = 4.0f;
1760 position.x = -6.0f;
1761 position.y = 7.0f;
1763 angle = D3DX_PI/3.0f;
1765 scale = 20.0f;
1767 U(exp_mat).m[0][0] = 10.0f;
1768 U(exp_mat).m[1][0] = -17.320507f;
1769 U(exp_mat).m[2][0] = 0.0f;
1770 U(exp_mat).m[3][0] = -1.035898f;
1771 U(exp_mat).m[0][1] = 17.320507f;
1772 U(exp_mat).m[1][1] = 10.0f;
1773 U(exp_mat).m[2][1] = 0.0f;
1774 U(exp_mat).m[3][1] = 6.401924f;
1775 U(exp_mat).m[0][2] = 0.0f;
1776 U(exp_mat).m[1][2] = 0.0f;
1777 U(exp_mat).m[2][2] = 1.0f;
1778 U(exp_mat).m[3][2] = 0.0f;
1779 U(exp_mat).m[0][3] = 0.0f;
1780 U(exp_mat).m[1][3] = 0.0f;
1781 U(exp_mat).m[2][3] = 0.0f;
1782 U(exp_mat).m[3][3] = 1.0f;
1784 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, &position);
1785 expect_matrix(&exp_mat, &got_mat, 2);
1787 /*______________*/
1789 center.x = 3.0f;
1790 center.y = 4.0f;
1792 angle = D3DX_PI/3.0f;
1794 scale = 20.0f;
1796 U(exp_mat).m[0][0] = 10.0f;
1797 U(exp_mat).m[1][0] = -17.320507f;
1798 U(exp_mat).m[2][0] = 0.0f;
1799 U(exp_mat).m[3][0] = 4.964102f;
1800 U(exp_mat).m[0][1] = 17.320507f;
1801 U(exp_mat).m[1][1] = 10.0f;
1802 U(exp_mat).m[2][1] = 0.0f;
1803 U(exp_mat).m[3][1] = -0.598076f;
1804 U(exp_mat).m[0][2] = 0.0f;
1805 U(exp_mat).m[1][2] = 0.0f;
1806 U(exp_mat).m[2][2] = 1.0f;
1807 U(exp_mat).m[3][2] = 0.0f;
1808 U(exp_mat).m[0][3] = 0.0f;
1809 U(exp_mat).m[1][3] = 0.0f;
1810 U(exp_mat).m[2][3] = 0.0f;
1811 U(exp_mat).m[3][3] = 1.0f;
1813 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, NULL);
1814 expect_matrix(&exp_mat, &got_mat, 8);
1816 /*______________*/
1818 position.x = -6.0f;
1819 position.y = 7.0f;
1821 angle = D3DX_PI/3.0f;
1823 scale = 20.0f;
1825 U(exp_mat).m[0][0] = 10.0f;
1826 U(exp_mat).m[1][0] = -17.320507f;
1827 U(exp_mat).m[2][0] = 0.0f;
1828 U(exp_mat).m[3][0] = -6.0f;
1829 U(exp_mat).m[0][1] = 17.320507f;
1830 U(exp_mat).m[1][1] = 10.0f;
1831 U(exp_mat).m[2][1] = 0.0f;
1832 U(exp_mat).m[3][1] = 7.0f;
1833 U(exp_mat).m[0][2] = 0.0f;
1834 U(exp_mat).m[1][2] = 0.0f;
1835 U(exp_mat).m[2][2] = 1.0f;
1836 U(exp_mat).m[3][2] = 0.0f;
1837 U(exp_mat).m[0][3] = 0.0f;
1838 U(exp_mat).m[1][3] = 0.0f;
1839 U(exp_mat).m[2][3] = 0.0f;
1840 U(exp_mat).m[3][3] = 1.0f;
1842 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, &position);
1843 expect_matrix(&exp_mat, &got_mat, 1);
1845 /*______________*/
1847 angle = 5.0f * D3DX_PI/4.0f;
1849 scale = -20.0f;
1851 U(exp_mat).m[0][0] = 14.142133f;
1852 U(exp_mat).m[1][0] = -14.142133f;
1853 U(exp_mat).m[2][0] = 0.0f;
1854 U(exp_mat).m[3][0] = 0.0f;
1855 U(exp_mat).m[0][1] = 14.142133;
1856 U(exp_mat).m[1][1] = 14.142133f;
1857 U(exp_mat).m[2][1] = 0.0f;
1858 U(exp_mat).m[3][1] = 0.0f;
1859 U(exp_mat).m[0][2] = 0.0f;
1860 U(exp_mat).m[1][2] = 0.0f;
1861 U(exp_mat).m[2][2] = 1.0f;
1862 U(exp_mat).m[3][2] = 0.0f;
1863 U(exp_mat).m[0][3] = 0.0f;
1864 U(exp_mat).m[1][3] = 0.0f;
1865 U(exp_mat).m[2][3] = 0.0f;
1866 U(exp_mat).m[3][3] = 1.0f;
1868 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, NULL);
1869 expect_matrix(&exp_mat, &got_mat, 8);
1872 static void test_Matrix_Decompose(void)
1874 D3DXMATRIX pm;
1875 D3DXQUATERNION exp_rotation, got_rotation;
1876 D3DXVECTOR3 exp_scale, got_scale, exp_translation, got_translation;
1877 HRESULT hr;
1878 BOOL equal;
1880 /*___________*/
1882 U(pm).m[0][0] = -9.23879206e-01f;
1883 U(pm).m[1][0] = -2.70598412e-01f;
1884 U(pm).m[2][0] = 2.70598441e-01f;
1885 U(pm).m[3][0] = -5.00000000e+00f;
1886 U(pm).m[0][1] = 2.70598471e-01f;
1887 U(pm).m[1][1] = 3.80604863e-02f;
1888 U(pm).m[2][1] = 9.61939573e-01f;
1889 U(pm).m[3][1] = 0.00000000e+00f;
1890 U(pm).m[0][2] = -2.70598441e-01f;
1891 U(pm).m[1][2] = 9.61939573e-01f;
1892 U(pm).m[2][2] = 3.80603075e-02f;
1893 U(pm).m[3][2] = 1.00000000e+01f;
1894 U(pm).m[0][3] = 0.00000000e+00f;
1895 U(pm).m[1][3] = 0.00000000e+00f;
1896 U(pm).m[2][3] = 0.00000000e+00f;
1897 U(pm).m[3][3] = 1.00000000e+00f;
1899 exp_scale.x = 9.99999881e-01f;
1900 exp_scale.y = 9.99999881e-01f;
1901 exp_scale.z = 9.99999881e-01f;
1903 exp_rotation.x = 2.14862776e-08f;
1904 exp_rotation.y = 6.93519890e-01f;
1905 exp_rotation.z = 6.93519890e-01f;
1906 exp_rotation.w = 1.95090637e-01f;
1908 exp_translation.x = -5.0f;
1909 exp_translation.y = 0.0f;
1910 exp_translation.z = 10.0f;
1912 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1913 expect_vec3(&exp_scale, &got_scale, 1);
1914 expect_quaternion(&exp_rotation, &got_rotation, 1);
1915 expect_vec3(&exp_translation, &got_translation, 0);
1917 /*_________*/
1919 U(pm).m[0][0] = -2.255813f;
1920 U(pm).m[1][0] = 1.302324f;
1921 U(pm).m[2][0] = 1.488373f;
1922 U(pm).m[3][0] = 1.0f;
1923 U(pm).m[0][1] = 1.302327f;
1924 U(pm).m[1][1] = -0.7209296f;
1925 U(pm).m[2][1] = 2.60465f;
1926 U(pm).m[3][1] = 2.0f;
1927 U(pm).m[0][2] = 1.488371f;
1928 U(pm).m[1][2] = 2.604651f;
1929 U(pm).m[2][2] = -0.02325551f;
1930 U(pm).m[3][2] = 3.0f;
1931 U(pm).m[0][3] = 0.0f;
1932 U(pm).m[1][3] = 0.0f;
1933 U(pm).m[2][3] = 0.0f;
1934 U(pm).m[3][3] = 1.0f;
1936 exp_scale.x = 2.99999928e+00f;
1937 exp_scale.y = 2.99999905e+00f;
1938 exp_scale.z = 2.99999952e+00f;
1940 exp_rotation.x = 3.52180451e-01f;
1941 exp_rotation.y = 6.16315663e-01f;
1942 exp_rotation.z = 7.04360664e-01f;
1943 exp_rotation.w = 3.38489343e-07f;
1945 exp_translation.x = 1.0f;
1946 exp_translation.y = 2.0f;
1947 exp_translation.z = 3.0f;
1949 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1950 expect_vec3(&exp_scale, &got_scale, 0);
1951 expect_quaternion(&exp_rotation, &got_rotation, 2);
1952 expect_vec3(&exp_translation, &got_translation, 0);
1954 /*_____________*/
1956 U(pm).m[0][0] = 2.427051f;
1957 U(pm).m[1][0] = 0.0f;
1958 U(pm).m[2][0] = 1.763355f;
1959 U(pm).m[3][0] = 5.0f;
1960 U(pm).m[0][1] = 0.0f;
1961 U(pm).m[1][1] = 3.0f;
1962 U(pm).m[2][1] = 0.0f;
1963 U(pm).m[3][1] = 5.0f;
1964 U(pm).m[0][2] = -1.763355f;
1965 U(pm).m[1][2] = 0.0f;
1966 U(pm).m[2][2] = 2.427051f;
1967 U(pm).m[3][2] = 5.0f;
1968 U(pm).m[0][3] = 0.0f;
1969 U(pm).m[1][3] = 0.0f;
1970 U(pm).m[2][3] = 0.0f;
1971 U(pm).m[3][3] = 1.0f;
1973 exp_scale.x = 2.99999976e+00f;
1974 exp_scale.y = 3.00000000e+00f;
1975 exp_scale.z = 2.99999976e+00f;
1977 exp_rotation.x = 0.00000000e+00f;
1978 exp_rotation.y = 3.09016883e-01f;
1979 exp_rotation.z = 0.00000000e+00f;
1980 exp_rotation.w = 9.51056540e-01f;
1982 exp_translation.x = 5.0f;
1983 exp_translation.y = 5.0f;
1984 exp_translation.z = 5.0f;
1986 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1987 expect_vec3(&exp_scale, &got_scale, 1);
1988 expect_quaternion(&exp_rotation, &got_rotation, 1);
1989 expect_vec3(&exp_translation, &got_translation, 0);
1991 /*_____________*/
1993 U(pm).m[0][0] = -9.23879206e-01f;
1994 U(pm).m[1][0] = -2.70598412e-01f;
1995 U(pm).m[2][0] = 2.70598441e-01f;
1996 U(pm).m[3][0] = -5.00000000e+00f;
1997 U(pm).m[0][1] = 2.70598471e-01f;
1998 U(pm).m[1][1] = 3.80604863e-02f;
1999 U(pm).m[2][1] = 9.61939573e-01f;
2000 U(pm).m[3][1] = 0.00000000e+00f;
2001 U(pm).m[0][2] = -2.70598441e-01f;
2002 U(pm).m[1][2] = 9.61939573e-01f;
2003 U(pm).m[2][2] = 3.80603075e-02f;
2004 U(pm).m[3][2] = 1.00000000e+01f;
2005 U(pm).m[0][3] = 0.00000000e+00f;
2006 U(pm).m[1][3] = 0.00000000e+00f;
2007 U(pm).m[2][3] = 0.00000000e+00f;
2008 U(pm).m[3][3] = 1.00000000e+00f;
2010 exp_scale.x = 9.99999881e-01f;
2011 exp_scale.y = 9.99999881e-01f;
2012 exp_scale.z = 9.99999881e-01f;
2014 exp_rotation.x = 2.14862776e-08f;
2015 exp_rotation.y = 6.93519890e-01f;
2016 exp_rotation.z = 6.93519890e-01f;
2017 exp_rotation.w = 1.95090637e-01f;
2019 exp_translation.x = -5.0f;
2020 exp_translation.y = 0.0f;
2021 exp_translation.z = 10.0f;
2023 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2024 expect_vec3(&exp_scale, &got_scale, 1);
2025 expect_quaternion(&exp_rotation, &got_rotation, 1);
2026 expect_vec3(&exp_translation, &got_translation, 0);
2028 /*__________*/
2030 U(pm).m[0][0] = -9.23878908e-01f;
2031 U(pm).m[1][0] = -5.41196704e-01f;
2032 U(pm).m[2][0] = 8.11795175e-01f;
2033 U(pm).m[3][0] = -5.00000000e+00f;
2034 U(pm).m[0][1] = 2.70598322e-01f;
2035 U(pm).m[1][1] = 7.61209577e-02f;
2036 U(pm).m[2][1] = 2.88581824e+00f;
2037 U(pm).m[3][1] = 0.00000000e+00f;
2038 U(pm).m[0][2] = -2.70598352e-01f;
2039 U(pm).m[1][2] = 1.92387879e+00f;
2040 U(pm).m[2][2] = 1.14180908e-01f;
2041 U(pm).m[3][2] = 1.00000000e+01f;
2042 U(pm).m[0][3] = 0.00000000e+00f;
2043 U(pm).m[1][3] = 0.00000000e+00f;
2044 U(pm).m[2][3] = 0.00000000e+00f;
2045 U(pm).m[3][3] = 1.00000000e+00f;
2047 exp_scale.x = 9.99999583e-01f;
2048 exp_scale.y = 1.99999940e+00f;
2049 exp_scale.z = 2.99999928e+00f;
2051 exp_rotation.x = 1.07431388e-08f;
2052 exp_rotation.y = 6.93519890e-01f;
2053 exp_rotation.z = 6.93519831e-01f;
2054 exp_rotation.w = 1.95090622e-01f;
2056 exp_translation.x = -5.0f;
2057 exp_translation.y = 0.0f;
2058 exp_translation.z = 10.0f;
2060 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2061 expect_vec3(&exp_scale, &got_scale, 1);
2062 equal = compare_quaternion(&exp_rotation, &got_rotation, 1);
2063 exp_rotation.x = 0.0f;
2064 equal |= compare_quaternion(&exp_rotation, &got_rotation, 2);
2065 ok(equal, "Got unexpected quaternion {%.8e, %.8e, %.8e, %.8e}.\n",
2066 got_rotation.x, got_rotation.y, got_rotation.z, got_rotation.w);
2067 expect_vec3(&exp_translation, &got_translation, 0);
2069 /*__________*/
2071 U(pm).m[0][0] = 0.7156004f;
2072 U(pm).m[1][0] = -0.5098283f;
2073 U(pm).m[2][0] = -0.4774843f;
2074 U(pm).m[3][0] = -5.0f;
2075 U(pm).m[0][1] = -0.6612288f;
2076 U(pm).m[1][1] = -0.7147621f;
2077 U(pm).m[2][1] = -0.2277977f;
2078 U(pm).m[3][1] = 0.0f;
2079 U(pm).m[0][2] = -0.2251499f;
2080 U(pm).m[1][2] = 0.4787385f;
2081 U(pm).m[2][2] = -0.8485972f;
2082 U(pm).m[3][2] = 10.0f;
2083 U(pm).m[0][3] = 0.0f;
2084 U(pm).m[1][3] = 0.0f;
2085 U(pm).m[2][3] = 0.0f;
2086 U(pm).m[3][3] = 1.0f;
2088 exp_scale.x = 9.99999940e-01f;
2089 exp_scale.y = 1.00000012e+00f;
2090 exp_scale.z = 1.00000012e+00f;
2092 exp_rotation.x = 9.05394852e-01f;
2093 exp_rotation.y = -3.23355347e-01f;
2094 exp_rotation.z = -1.94013178e-01f;
2095 exp_rotation.w = 1.95090592e-01f;
2097 exp_translation.x = -5.0f;
2098 exp_translation.y = 0.0f;
2099 exp_translation.z = 10.0f;
2101 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2102 expect_vec3(&exp_scale, &got_scale, 0);
2103 expect_quaternion(&exp_rotation, &got_rotation, 1);
2104 expect_vec3(&exp_translation, &got_translation, 0);
2106 /*_____________*/
2108 U(pm).m[0][0] = 0.06554436f;
2109 U(pm).m[1][0] = -0.6873012f;
2110 U(pm).m[2][0] = 0.7234092f;
2111 U(pm).m[3][0] = -5.0f;
2112 U(pm).m[0][1] = -0.9617381f;
2113 U(pm).m[1][1] = -0.2367795f;
2114 U(pm).m[2][1] = -0.1378230f;
2115 U(pm).m[3][1] = 0.0f;
2116 U(pm).m[0][2] = 0.2660144f;
2117 U(pm).m[1][2] = -0.6866967f;
2118 U(pm).m[2][2] = -0.6765233f;
2119 U(pm).m[3][2] = 10.0f;
2120 U(pm).m[0][3] = 0.0f;
2121 U(pm).m[1][3] = 0.0f;
2122 U(pm).m[2][3] = 0.0f;
2123 U(pm).m[3][3] = 1.0f;
2125 exp_scale.x = 9.99999940e-01f;
2126 exp_scale.y = 9.99999940e-01f;
2127 exp_scale.z = 9.99999881e-01f;
2129 exp_rotation.x = 7.03357518e-01f;
2130 exp_rotation.y = -5.86131275e-01f;
2131 exp_rotation.z = 3.51678789e-01f;
2132 exp_rotation.w = -1.95090577e-01f;
2134 exp_translation.x = -5.0f;
2135 exp_translation.y = 0.0f;
2136 exp_translation.z = 10.0f;
2138 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2139 expect_vec3(&exp_scale, &got_scale, 1);
2140 expect_quaternion(&exp_rotation, &got_rotation, 2);
2141 expect_vec3(&exp_translation, &got_translation, 0);
2143 /*_________*/
2145 U(pm).m[0][0] = 7.12104797e+00f;
2146 U(pm).m[1][0] = -5.88348627e+00f;
2147 U(pm).m[2][0] = 1.18184204e+01f;
2148 U(pm).m[3][0] = -5.00000000e+00f;
2149 U(pm).m[0][1] = 5.88348627e+00f;
2150 U(pm).m[1][1] = -1.06065865e+01f;
2151 U(pm).m[2][1] = -8.82523251e+00f;
2152 U(pm).m[3][1] = 0.00000000e+00f;
2153 U(pm).m[0][2] = 1.18184204e+01f;
2154 U(pm).m[1][2] = 8.82523155e+00f;
2155 U(pm).m[2][2] = -2.72764111e+00f;
2156 U(pm).m[3][2] = 2.00000000e+00f;
2157 U(pm).m[0][3] = 0.00000000e+00f;
2158 U(pm).m[1][3] = 0.00000000e+00f;
2159 U(pm).m[2][3] = 0.00000000e+00f;
2160 U(pm).m[3][3] = 1.00000000e+00f;
2162 exp_scale.x = 1.49999933e+01f;
2163 exp_scale.y = 1.49999933e+01f;
2164 exp_scale.z = 1.49999943e+01f;
2166 exp_rotation.x = 7.68714130e-01f;
2167 exp_rotation.y = 0.00000000e+00f;
2168 exp_rotation.z = 5.12475967e-01f;
2169 exp_rotation.w = 3.82683903e-01f;
2171 exp_translation.x = -5.0f;
2172 exp_translation.y = 0.0f;
2173 exp_translation.z = 2.0f;
2175 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2176 expect_vec3(&exp_scale, &got_scale, 0);
2177 expect_quaternion(&exp_rotation, &got_rotation, 1);
2178 expect_vec3(&exp_translation, &got_translation, 0);
2180 /*__________*/
2182 U(pm).m[0][0] = 0.0f;
2183 U(pm).m[1][0] = 4.0f;
2184 U(pm).m[2][0] = 5.0f;
2185 U(pm).m[3][0] = -5.0f;
2186 U(pm).m[0][1] = 0.0f;
2187 U(pm).m[1][1] = -10.60660f;
2188 U(pm).m[2][1] = -8.825232f;
2189 U(pm).m[3][1] = 6.0f;
2190 U(pm).m[0][2] = 0.0f;
2191 U(pm).m[1][2] = 8.8252320f;
2192 U(pm).m[2][2] = 2.727645;
2193 U(pm).m[3][2] = 3.0f;
2194 U(pm).m[0][3] = 0.0f;
2195 U(pm).m[1][3] = 0.0f;
2196 U(pm).m[2][3] = 0.0f;
2197 U(pm).m[3][3] = 1.0f;
2199 hr = D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2200 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
2203 static void test_Matrix_Transformation2D(void)
2205 D3DXMATRIX exp_mat, got_mat;
2206 D3DXVECTOR2 rot_center, sca, sca_center, trans;
2207 FLOAT rot, sca_rot;
2209 rot_center.x = 3.0f;
2210 rot_center.y = 4.0f;
2212 sca.x = 12.0f;
2213 sca.y = -3.0f;
2215 sca_center.x = 9.0f;
2216 sca_center.y = -5.0f;
2218 trans.x = -6.0f;
2219 trans.y = 7.0f;
2221 rot = D3DX_PI/3.0f;
2223 sca_rot = 5.0f*D3DX_PI/4.0f;
2225 U(exp_mat).m[0][0] = -4.245192f;
2226 U(exp_mat).m[1][0] = -0.147116f;
2227 U(exp_mat).m[2][0] = 0.0f;
2228 U(exp_mat).m[3][0] = 45.265373f;
2229 U(exp_mat).m[0][1] = 7.647113f;
2230 U(exp_mat).m[1][1] = 8.745192f;
2231 U(exp_mat).m[2][1] = 0.0f;
2232 U(exp_mat).m[3][1] = -13.401899f;
2233 U(exp_mat).m[0][2] = 0.0f;
2234 U(exp_mat).m[1][2] = 0.0f;
2235 U(exp_mat).m[2][2] = 1.0f;
2236 U(exp_mat).m[3][2] = 0.0f;
2237 U(exp_mat).m[0][3] = 0.0f;
2238 U(exp_mat).m[1][3] = 0.0f;
2239 U(exp_mat).m[2][3] = 0.0f;
2240 U(exp_mat).m[3][3] = 1.0f;
2242 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
2243 expect_matrix(&exp_mat, &got_mat, 64);
2245 /*_________*/
2247 sca_center.x = 9.0f;
2248 sca_center.y = -5.0f;
2250 trans.x = -6.0f;
2251 trans.y = 7.0f;
2253 rot = D3DX_PI/3.0f;
2255 sca_rot = 5.0f*D3DX_PI/4.0f;
2257 U(exp_mat).m[0][0] = 0.50f;
2258 U(exp_mat).m[1][0] = -0.866025f;
2259 U(exp_mat).m[2][0] = 0.0f;
2260 U(exp_mat).m[3][0] = -6.0f;
2261 U(exp_mat).m[0][1] = 0.866025f;
2262 U(exp_mat).m[1][1] = 0.50f;
2263 U(exp_mat).m[2][1] = 0.0f;
2264 U(exp_mat).m[3][1] = 7.0f;
2265 U(exp_mat).m[0][2] = 0.0f;
2266 U(exp_mat).m[1][2] = 0.0f;
2267 U(exp_mat).m[2][2] = 1.0f;
2268 U(exp_mat).m[3][2] = 0.0f;
2269 U(exp_mat).m[0][3] = 0.0f;
2270 U(exp_mat).m[1][3] = 0.0f;
2271 U(exp_mat).m[2][3] = 0.0f;
2272 U(exp_mat).m[3][3] = 1.0f;
2274 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
2275 expect_matrix(&exp_mat, &got_mat, 8);
2277 /*_________*/
2279 U(exp_mat).m[0][0] = 0.50f;
2280 U(exp_mat).m[1][0] = -0.866025f;
2281 U(exp_mat).m[2][0] = 0.0f;
2282 U(exp_mat).m[3][0] = 0.0f;
2283 U(exp_mat).m[0][1] = 0.866025f;
2284 U(exp_mat).m[1][1] = 0.50f;
2285 U(exp_mat).m[2][1] = 0.0f;
2286 U(exp_mat).m[3][1] = 0.0f;
2287 U(exp_mat).m[0][2] = 0.0f;
2288 U(exp_mat).m[1][2] = 0.0f;
2289 U(exp_mat).m[2][2] = 1.0f;
2290 U(exp_mat).m[3][2] = 0.0f;
2291 U(exp_mat).m[0][3] = 0.0f;
2292 U(exp_mat).m[1][3] = 0.0f;
2293 U(exp_mat).m[2][3] = 0.0f;
2294 U(exp_mat).m[3][3] = 1.0f;
2296 D3DXMatrixTransformation2D(&got_mat, NULL, sca_rot, NULL, NULL, rot, NULL);
2297 expect_matrix(&exp_mat, &got_mat, 8);
2300 static void test_D3DXVec_Array(void)
2302 D3DXPLANE inp_plane[5], out_plane[7], exp_plane[7];
2303 D3DXVECTOR4 inp_vec[5], out_vec[7], exp_vec[7];
2304 D3DXMATRIX mat, projection, view, world;
2305 D3DVIEWPORT9 viewport;
2306 unsigned int i;
2308 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
2309 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
2311 memset(out_vec, 0, sizeof(out_vec));
2312 memset(exp_vec, 0, sizeof(exp_vec));
2313 memset(out_plane, 0, sizeof(out_plane));
2314 memset(exp_plane, 0, sizeof(exp_plane));
2316 for (i = 0; i < ARRAY_SIZE(inp_vec); ++i)
2318 inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
2319 inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE(inp_vec) - i;
2322 U(mat).m[0][0] = 1.0f; U(mat).m[0][1] = 2.0f; U(mat).m[0][2] = 3.0f; U(mat).m[0][3] = 4.0f;
2323 U(mat).m[1][0] = 5.0f; U(mat).m[1][1] = 6.0f; U(mat).m[1][2] = 7.0f; U(mat).m[1][3] = 8.0f;
2324 U(mat).m[2][0] = 9.0f; U(mat).m[2][1] = 10.0f; U(mat).m[2][2] = 11.0f; U(mat).m[2][3] = 12.0f;
2325 U(mat).m[3][0] = 13.0f; U(mat).m[3][1] = 14.0f; U(mat).m[3][2] = 15.0f; U(mat).m[3][3] = 16.0f;
2327 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2329 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
2330 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
2331 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
2332 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
2333 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
2334 U(view).m[3][3] = -40.0f;
2336 U(world).m[0][0] = 21.0f; U(world).m[0][1] = 2.0f; U(world).m[0][2] = 3.0f; U(world).m[0][3] = 4.0;
2337 U(world).m[1][0] = 5.0f; U(world).m[1][1] = 23.0f; U(world).m[1][2] = 7.0f; U(world).m[1][3] = 8.0f;
2338 U(world).m[2][0] = -8.0f; U(world).m[2][1] = -7.0f; U(world).m[2][2] = 25.0f; U(world).m[2][3] = -5.0f;
2339 U(world).m[3][0] = -4.0f; U(world).m[3][1] = -3.0f; U(world).m[3][2] = -2.0f; U(world).m[3][3] = 27.0f;
2341 /* D3DXVec2TransformCoordArray */
2342 exp_vec[1].x = 6.78571403e-01f; exp_vec[1].y = 7.85714269e-01f;
2343 exp_vec[2].x = 6.53846204e-01f; exp_vec[2].y = 7.69230783e-01f;
2344 exp_vec[3].x = 6.25000000e-01f; exp_vec[3].y = 7.50000000e-01f;
2345 exp_vec[4].x = 5.90909123e-01f; exp_vec[4].y = 7.27272749e-01f;
2346 exp_vec[5].x = 5.49999952e-01f; exp_vec[5].y = 6.99999928e-01f;
2347 D3DXVec2TransformCoordArray((D3DXVECTOR2 *)&out_vec[1], sizeof(*out_vec),
2348 (D3DXVECTOR2 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2349 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 1);
2351 /* D3DXVec2TransformNormalArray */
2352 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
2353 exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
2354 exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
2355 exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
2356 exp_vec[5].x = 9.0f; exp_vec[5].y = 14.0f;
2357 D3DXVec2TransformNormalArray((D3DXVECTOR2 *)&out_vec[1], sizeof(*out_vec),
2358 (D3DXVECTOR2 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2359 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
2361 /* D3DXVec3TransformCoordArray */
2362 exp_vec[1].x = 6.78571403e-01f; exp_vec[1].y = 7.85714269e-01f; exp_vec[1].z = 8.92857075e-01f;
2363 exp_vec[2].x = 6.71874940e-01f; exp_vec[2].y = 7.81249940e-01f; exp_vec[2].z = 8.90624940e-01f;
2364 exp_vec[3].x = 6.66666627e-01f; exp_vec[3].y = 7.77777731e-01f; exp_vec[3].z = 8.88888836e-01f;
2365 exp_vec[4].x = 6.62499964e-01f; exp_vec[4].y = 7.74999976e-01f; exp_vec[4].z = 8.87499928e-01f;
2366 exp_vec[5].x = 6.59090877e-01f; exp_vec[5].y = 7.72727251e-01f; exp_vec[5].z = 8.86363566e-01f;
2367 D3DXVec3TransformCoordArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec),
2368 (D3DXVECTOR3 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2369 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 1);
2371 /* D3DXVec3TransformNormalArray */
2372 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
2373 exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
2374 exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
2375 exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
2376 exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
2377 D3DXVec3TransformNormalArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec),
2378 (D3DXVECTOR3 *)inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2379 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
2381 /* D3DXVec3ProjectArray */
2382 exp_vec[1].x = 1.08955420e+03f; exp_vec[1].y = -2.26590622e+02f; exp_vec[1].z = 2.15272754e-01f;
2383 exp_vec[2].x = 1.06890344e+03f; exp_vec[2].y = 1.03085144e+02f; exp_vec[2].z = 1.83049560e-01f;
2384 exp_vec[3].x = 1.05177905e+03f; exp_vec[3].y = 3.76462280e+02f; exp_vec[3].z = 1.56329080e-01f;
2385 exp_vec[4].x = 1.03734888e+03f; exp_vec[4].y = 6.06827393e+02f; exp_vec[4].z = 1.33812696e-01f;
2386 exp_vec[5].x = 1.02502356e+03f; exp_vec[5].y = 8.03591248e+02f; exp_vec[5].z = 1.14580572e-01f;
2387 D3DXVec3ProjectArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
2388 sizeof(*inp_vec), &viewport, &projection, &view, &world, ARRAY_SIZE(inp_vec));
2389 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 8);
2391 /* D3DXVec3UnprojectArray */
2392 exp_vec[1].x = -6.12403107e+00f; exp_vec[1].y = 3.22536016e+00f; exp_vec[1].z = 6.20571136e-01f;
2393 exp_vec[2].x = -3.80710936e+00f; exp_vec[2].y = 2.04657936e+00f; exp_vec[2].z = 4.46894377e-01f;
2394 exp_vec[3].x = -2.92283988e+00f; exp_vec[3].y = 1.59668946e+00f; exp_vec[3].z = 3.80609393e-01f;
2395 exp_vec[4].x = -2.45622563e+00f; exp_vec[4].y = 1.35928988e+00f; exp_vec[4].z = 3.45631927e-01f;
2396 exp_vec[5].x = -2.16789746e+00f; exp_vec[5].y = 1.21259713e+00f; exp_vec[5].z = 3.24018806e-01f;
2397 D3DXVec3UnprojectArray((D3DXVECTOR3 *)&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
2398 sizeof(*inp_vec), &viewport, &projection, &view, &world, ARRAY_SIZE(inp_vec));
2399 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 4);
2401 /* D3DXVec2TransformArray */
2402 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2403 exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
2404 exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
2405 exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
2406 exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
2407 D3DXVec2TransformArray(&out_vec[1], sizeof(*out_vec), (D3DXVECTOR2 *)inp_vec,
2408 sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2409 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
2411 /* D3DXVec3TransformArray */
2412 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2413 exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
2414 exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
2415 exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
2416 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2417 D3DXVec3TransformArray(&out_vec[1], sizeof(*out_vec), (D3DXVECTOR3 *)inp_vec,
2418 sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2419 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
2421 /* D3DXVec4TransformArray */
2422 exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
2423 exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f; exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
2424 exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f; exp_vec[3].z = 94.0f; exp_vec[3].w = 104.0f;
2425 exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f; exp_vec[4].z = 86.0f; exp_vec[4].w = 96.0f;
2426 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2427 D3DXVec4TransformArray(&out_vec[1], sizeof(*out_vec), inp_vec, sizeof(*inp_vec), &mat, ARRAY_SIZE(inp_vec));
2428 expect_vec4_array(ARRAY_SIZE(exp_vec), exp_vec, out_vec, 0);
2430 /* D3DXPlaneTransformArray */
2431 exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
2432 exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f; exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
2433 exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f; exp_plane[3].c = 94.0f; exp_plane[3].d = 104.0f;
2434 exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f; exp_plane[4].c = 86.0f; exp_plane[4].d = 96.0f;
2435 exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f; exp_plane[5].c = 78.0f; exp_plane[5].d = 88.0f;
2436 D3DXPlaneTransformArray(&out_plane[1], sizeof(*out_plane), inp_plane,
2437 sizeof(*inp_plane), &mat, ARRAY_SIZE(inp_plane));
2438 for (i = 0; i < ARRAY_SIZE(exp_plane); ++i)
2440 BOOL equal = compare_plane(&exp_plane[i], &out_plane[i], 0);
2441 ok(equal, "Got unexpected plane {%.8e, %.8e, %.8e, %.8e} at index %u, expected {%.8e, %.8e, %.8e, %.8e}.\n",
2442 out_plane[i].a, out_plane[i].b, out_plane[i].c, out_plane[i].d, i,
2443 exp_plane[i].a, exp_plane[i].b, exp_plane[i].c, exp_plane[i].d);
2444 if (!equal)
2445 break;
2449 static void test_D3DXFloat_Array(void)
2451 unsigned int i;
2452 void *out = NULL;
2453 D3DXFLOAT16 half;
2454 BOOL equal;
2456 /* Input floats through bit patterns because compilers do not generate reliable INF and NaN values. */
2457 union convert
2459 DWORD d;
2460 float f;
2461 } single;
2463 struct
2465 union convert single_in;
2467 /* half_ver2 occurs on WXPPROSP3 (32 bit math), WVISTAADM (32/64 bit math), W7PRO (32 bit math) */
2468 WORD half_ver1, half_ver2;
2470 /* single_out_ver2 confirms that half -> single conversion is consistent across platforms */
2471 union convert single_out_ver1, single_out_ver2;
2473 testdata[] =
2475 { { 0x479c4000 }, 0x7c00, 0x7ce2, { 0x47800000 }, { 0x479c4000 } }, /* 80000.0f */
2476 { { 0x477fdf00 }, 0x7bff, 0x7bff, { 0x477fe000 }, { 0x477fe000 } }, /* 65503.0f */
2477 { { 0x477fe000 }, 0x7bff, 0x7bff, { 0x477fe000 }, { 0x477fe000 } }, /* 65504.0f */
2478 { { 0x477ff000 }, 0x7bff, 0x7c00, { 0x477fe000 }, { 0x47800000 } }, /* 65520.0f */
2479 { { 0x477ff100 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65521.0f */
2481 { { 0x477ffe00 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65534.0f */
2482 { { 0x477fff00 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65535.0f */
2483 { { 0x47800000 }, 0x7c00, 0x7c00, { 0x47800000 }, { 0x47800000 } }, /* 65536.0f */
2484 { { 0xc79c4000 }, 0xfc00, 0xfce2, { 0xc7800000 }, { 0xc79c4000 } }, /* -80000.0f */
2485 { { 0xc77fdf00 }, 0xfbff, 0xfbff, { 0xc77fe000 }, { 0xc77fe000 } }, /* -65503.0f */
2487 { { 0xc77fe000 }, 0xfbff, 0xfbff, { 0xc77fe000 }, { 0xc77fe000 } }, /* -65504.0f */
2488 { { 0xc77ff000 }, 0xfbff, 0xfc00, { 0xc77fe000 }, { 0xc7800000 } }, /* -65520.0f */
2489 { { 0xc77ff100 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65521.0f */
2490 { { 0xc77ffe00 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65534.0f */
2491 { { 0xc77fff00 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65535.0f */
2493 { { 0xc7800000 }, 0xfc00, 0xfc00, { 0xc7800000 }, { 0xc7800000 } }, /* -65536.0f */
2494 { { 0x7f800000 }, 0x7c00, 0x7fff, { 0x47800000 }, { 0x47ffe000 } }, /* INF */
2495 { { 0xff800000 }, 0xffff, 0xffff, { 0xc7ffe000 }, { 0xc7ffe000 } }, /* -INF */
2496 { { 0x7fc00000 }, 0x7fff, 0xffff, { 0x47ffe000 }, { 0xc7ffe000 } }, /* NaN */
2497 { { 0xffc00000 }, 0xffff, 0xffff, { 0xc7ffe000 }, { 0xc7ffe000 } }, /* -NaN */
2499 { { 0x00000000 }, 0x0000, 0x0000, { 0x00000000 }, { 0x00000000 } }, /* 0.0f */
2500 { { 0x80000000 }, 0x8000, 0x8000, { 0x80000000 }, { 0x80000000 } }, /* -0.0f */
2501 { { 0x330007ff }, 0x0000, 0x0000, { 0x00000000 }, { 0x00000000 } }, /* 2.9809595e-08f */
2502 { { 0xb30007ff }, 0x8000, 0x8000, { 0x80000000 }, { 0x80000000 } }, /* -2.9809595e-08f */
2503 { { 0x33000800 }, 0x0001, 0x0000, { 0x33800000 }, { 0x00000000 } }, /* 2.9809598e-08f */
2505 { { 0xb3000800 }, 0x8001, 0x8000, { 0xb3800000 }, { 0x80000000 } }, /* -2.9809598e-08f */
2506 { { 0x33c00000 }, 0x0002, 0x0001, { 0x34000000 }, { 0x33800000 } }, /* 8.9406967e-08f */
2509 /* exception on NULL out or in parameter */
2510 out = D3DXFloat32To16Array(&half, &single.f, 0);
2511 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2513 out = D3DXFloat16To32Array(&single.f, &half, 0);
2514 ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
2516 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
2518 out = D3DXFloat32To16Array(&half, &testdata[i].single_in.f, 1);
2519 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2520 ok(half.value == testdata[i].half_ver1 || half.value == testdata[i].half_ver2,
2521 "Got %x, expected %x or %x for index %d.\n", half.value, testdata[i].half_ver1,
2522 testdata[i].half_ver2, i);
2524 out = D3DXFloat16To32Array(&single.f, (D3DXFLOAT16 *)&testdata[i].half_ver1, 1);
2525 ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
2526 equal = compare_float(single.f, testdata[i].single_out_ver1.f, 0);
2527 ok(equal, "Got %#x, expected %#x at index %u.\n", single.d, testdata[i].single_out_ver1.d, i);
2529 out = D3DXFloat16To32Array(&single.f, (D3DXFLOAT16 *)&testdata[i].half_ver2, 1);
2530 ok(out == &single.f, "Got %p, expected %p.\n", out, &single.f);
2531 equal = compare_float(single.f, testdata[i].single_out_ver2.f, 0);
2532 ok(equal, "Got %#x, expected %#x at index %u.\n", single.d, testdata[i].single_out_ver2.d, i);
2536 static void test_D3DXSHAdd(void)
2538 float out[50] = {0.0f};
2539 unsigned int i, k;
2540 float *ret;
2541 BOOL equal;
2543 static const float in1[50] =
2545 1.11f, 1.12f, 1.13f, 1.14f, 1.15f, 1.16f, 1.17f, 1.18f,
2546 1.19f, 1.20f, 1.21f, 1.22f, 1.23f, 1.24f, 1.25f, 1.26f,
2547 1.27f, 1.28f, 1.29f, 1.30f, 1.31f, 1.32f, 1.33f, 1.34f,
2548 1.35f, 1.36f, 1.37f, 1.38f, 1.39f, 1.40f, 1.41f, 1.42f,
2549 1.43f, 1.44f, 1.45f, 1.46f, 1.47f, 1.48f, 1.49f, 1.50f,
2550 1.51f, 1.52f, 1.53f, 1.54f, 1.55f, 1.56f, 1.57f, 1.58f,
2551 1.59f, 1.60f,
2553 static const float in2[50] =
2555 2.11f, 2.12f, 2.13f, 2.14f, 2.15f, 2.16f, 2.17f, 2.18f,
2556 2.19f, 2.20f, 2.21f, 2.22f, 2.23f, 2.24f, 2.25f, 2.26f,
2557 2.27f, 2.28f, 2.29f, 2.30f, 2.31f, 2.32f, 2.33f, 2.34f,
2558 2.35f, 2.36f, 2.37f, 2.38f, 2.39f, 2.40f, 2.41f, 2.42f,
2559 2.43f, 2.44f, 2.45f, 2.46f, 2.47f, 2.48f, 2.49f, 2.50f,
2560 2.51f, 2.52f, 2.53f, 2.54f, 2.55f, 2.56f, 2.57f, 2.58f,
2561 2.59f, 2.60f,
2565 * Order is not limited by D3DXSH_MINORDER and D3DXSH_MAXORDER!
2566 * All values will work, test from 0-7 [D3DXSH_MINORDER = 2, D3DXSH_MAXORDER = 6]
2567 * Exceptions will show up when out, in1 or in2 is NULL
2569 for (k = 0; k <= D3DXSH_MAXORDER + 1; k++)
2571 UINT count = k * k;
2573 ret = D3DXSHAdd(&out[0], k, &in1[0], &in2[0]);
2574 ok(ret == out, "%u: D3DXSHAdd() failed, got %p, expected %p\n", k, out, ret);
2576 for (i = 0; i < count; ++i)
2578 equal = compare_float(in1[i] + in2[i], out[i], 0);
2579 ok(equal, "%u-%u: Got %.8e, expected %.8e.\n", k, i, out[i], in1[i] + in2[i]);
2581 equal = compare_float(out[count], 0.0f, 0);
2582 ok(equal, "%u-%u: Got %.8e, expected 0.0.\n", k, k * k, out[count]);
2586 static void test_D3DXSHDot(void)
2588 float a[49], b[49], got;
2589 unsigned int i;
2590 BOOL equal;
2592 static const float expected[] = {0.5f, 0.5f, 25.0f, 262.5f, 1428.0f, 5362.5f, 15873.0f, 39812.5f};
2594 for (i = 0; i < ARRAY_SIZE(a); ++i)
2596 a[i] = i + 1.0f;
2597 b[i] = i + 0.5f;
2600 /* D3DXSHDot computes by using order * order elements */
2601 for (i = 0; i <= D3DXSH_MAXORDER + 1; i++)
2603 got = D3DXSHDot(i, a, b);
2604 equal = compare_float(got, expected[i], 0);
2605 ok(equal, "order %u: Got %.8e, expected %.8e.\n", i, got, expected[i]);
2609 static void test_D3DXSHEvalConeLight(void)
2611 float bout[49], expected, gout[49], rout[49];
2612 unsigned int j, l, order;
2613 D3DXVECTOR3 dir;
2614 HRESULT hr;
2615 BOOL equal;
2617 static const float table[] =
2619 /* Red colour */
2620 1.604815f, -3.131381f, 7.202175f, -2.870432f, 6.759296f, -16.959688f,
2621 32.303082f, -15.546381f, -0.588878f, -5.902123f, 40.084042f, -77.423569f,
2622 137.556320f, -70.971603f, -3.492171f, 7.683092f, -2.129311f, -35.971344f,
2623 183.086548f, -312.414948f, 535.091064f, -286.380371f, -15.950727f, 46.825714f,
2624 -12.127637f, 11.289261f, -12.417809f, -155.039566f, 681.182556f, -1079.733643f,
2625 1807.650513f, -989.755798f, -59.345467f, 201.822815f, -70.726486f, 7.206529f,
2627 3.101155f, -3.128710f, 7.196033f, -2.867984f, -0.224708f, 0.563814f,
2628 -1.073895f, 0.516829f, 0.019577f, 2.059788f, -13.988971f, 27.020128f,
2629 -48.005917f, 24.768450f, 1.218736f, -2.681329f, -0.088639f, -1.497410f,
2630 7.621501f, -13.005165f, 22.274696f, -11.921401f, -0.663995f, 1.949254f,
2631 -0.504848f, 4.168484f, -4.585193f, -57.247314f, 251.522095f, -398.684387f,
2632 667.462891f, -365.460693f, -21.912912f, 74.521721f, -26.115280f, 2.660963f,
2633 /* Green colour */
2634 2.454422f, -4.789170f, 11.015091f, -4.390072f, 10.337747f, -25.938347f,
2635 49.404713f, -23.776817f, -0.900637f, -9.026776f, 61.305000f, -118.412514f,
2636 210.380249f, -108.544792f, -5.340967f, 11.750610f, -3.256593f, -55.014996f,
2637 280.014709f, -477.811066f, 818.374512f, -437.993469f, -24.395227f, 71.615799f,
2638 -18.548151f, 17.265928f, -18.991943f, -237.119324f, 1041.808594f, -1651.357300f,
2639 2764.642090f, -1513.744141f, -90.763657f, 308.670197f, -108.169922f, 11.021750f,
2641 4.742942f, -4.785086f, 11.005697f, -4.386329f, -0.343672f, 0.862303f,
2642 -1.642427f, 0.790444f, 0.029941f, 3.150264f, -21.394896f, 41.324898f,
2643 -73.420807f, 37.881153f, 1.863950f, -4.100857f, -0.135565f, -2.290156f,
2644 11.656413f, -19.890251f, 34.067181f, -18.232729f, -1.015521f, 2.981212f,
2645 -0.772120f, 6.375328f, -7.012648f, -87.554710f, 384.680817f, -609.752563f,
2646 1020.825500f, -558.939819f, -33.513863f, 113.974388f, -39.941013f, 4.069707f,
2647 /* Blue colour */
2648 3.304030f, -6.446959f, 14.828006f, -5.909713f, 13.916198f, -34.917004f,
2649 66.506340f, -32.007256f, -1.212396f, -12.151429f, 82.525963f, -159.401459f,
2650 283.204193f, -146.117996f, -7.189764f, 15.818130f, -4.383876f, -74.058655f,
2651 376.942871f, -643.207214f, 1101.658081f, -589.606628f, -32.839729f, 96.405884f,
2652 -24.968664f, 23.242596f, -25.566080f, -319.199097f, 1402.434692f, -2222.980957f,
2653 3721.633545f, -2037.732544f, -122.181847f, 415.517578f, -145.613358f, 14.836972f,
2655 6.384730f, -6.441462f, 14.815362f, -5.904673f, -0.462635f, 1.160793f,
2656 -2.210959f, 1.064060f, 0.040305f, 4.240739f, -28.800821f, 55.629673f,
2657 -98.835709f, 50.993862f, 2.509163f, -5.520384f, -0.182491f, -3.082903f,
2658 15.691326f, -26.775339f, 45.859665f, -24.544060f, -1.367048f, 4.013170f,
2659 -1.039392f, 8.582172f, -9.440103f, -117.862114f, 517.839600f, -820.820740f,
2660 1374.188232f, -752.419067f, -45.114819f, 153.427063f, -53.766754f, 5.478452f, };
2661 const struct
2663 float *red_received, *green_received, *blue_received;
2664 const float *red_expected, *green_expected, *blue_expected;
2665 float radius, roffset, goffset, boffset;
2667 test[] =
2669 { rout, gout, bout, table, &table[72], &table[144], 0.5f, 1.01f, 1.02f, 1.03f, },
2670 { rout, gout, bout, &table[36], &table[108], &table[180], 1.6f, 1.01f, 1.02f, 1.03f, },
2671 { rout, rout, rout, &table[144], &table[144], &table[144], 0.5f, 1.03f, 1.03f, 1.03f, },
2672 { rout, rout, bout, &table[72], &table[72], &table[144], 0.5, 1.02f, 1.02f, 1.03f, },
2673 { rout, gout, gout, table, &table[144], &table[144], 0.5f, 1.01f, 1.03f, 1.03f, },
2674 { rout, gout, rout, &table[144], &table[72], &table[144], 0.5f, 1.03f, 1.02f, 1.03f, },
2675 /* D3DXSHEvalConeLight accepts NULL green or blue colour. */
2676 { rout, NULL, bout, table, NULL, &table[144], 0.5f, 1.01f, 0.0f, 1.03f, },
2677 { rout, gout, NULL, table, &table[72], NULL, 0.5f, 1.01f, 1.02f, 0.0f, },
2678 { rout, NULL, NULL, table, NULL, NULL, 0.5f, 1.01f, 0.0f, 0.0f, },
2681 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
2683 for (l = 0; l < ARRAY_SIZE(test); ++l)
2685 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2687 for (j = 0; j < 49; j++)
2689 test[l].red_received[j] = 1.01f + j;
2690 if (test[l].green_received)
2691 test[l].green_received[j] = 1.02f + j;
2692 if (test[l].blue_received)
2693 test[l].blue_received[j] = 1.03f + j;
2696 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);
2697 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2699 for (j = 0; j < 49; j++)
2701 if (j >= order * order)
2702 expected = j + test[l].roffset;
2703 else
2704 expected = test[l].red_expected[j];
2705 equal = compare_float(test[l].red_received[j], expected, 128);
2706 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2707 l, order, j, expected, test[l].red_received[j]);
2709 if (test[l].green_received)
2711 if (j >= order * order)
2712 expected = j + test[l].goffset;
2713 else
2714 expected = test[l].green_expected[j];
2715 equal = compare_float(test[l].green_received[j], expected, 64);
2716 ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2717 l, order, j, expected, test[l].green_received[j]);
2720 if (test[l].blue_received)
2722 if (j >= order * order)
2723 expected = j + test[l].boffset;
2724 else
2725 expected = test[l].blue_expected[j];
2726 equal = compare_float(test[l].blue_received[j], expected, 128);
2727 ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2728 l, order, j, expected, test[l].blue_received[j]);
2734 /* Cone light with radius <= 0.0f behaves as a directional light */
2735 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2737 FLOAT blue[49], green[49], red[49];
2739 for (j = 0; j < 49; j++)
2741 rout[j] = 1.01f + j;
2742 gout[j] = 1.02f + j;
2743 bout[j] = 1.03f + j;
2744 red[j] = 1.01f + j;
2745 green[j] = 1.02f + j;
2746 blue[j] = 1.03f + j;
2749 hr = D3DXSHEvalConeLight(order, &dir, -0.1f, 1.7f, 2.6f, 3.5f, rout, gout, bout);
2750 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2751 D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red, green, blue);
2753 for (j = 0; j < 49; j++)
2755 equal = compare_float(red[j], rout[j], 0);
2756 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2757 l, order, j, red[j], rout[j]);
2759 equal = compare_float(green[j], gout[j], 0);
2760 ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2761 l, order, j, green[j], gout[j]);
2763 equal = compare_float(blue[j], bout[j], 0);
2764 ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2765 l, order, j, blue[j], bout[j]);
2769 /* D3DXSHEvalConeLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
2770 hr = D3DXSHEvalConeLight(7, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2771 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2772 hr = D3DXSHEvalConeLight(0, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2773 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2774 hr = D3DXSHEvalConeLight(1, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2775 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2778 static void test_D3DXSHEvalDirection(void)
2780 float a[49], expected, *received_ptr;
2781 unsigned int i, order;
2782 D3DXVECTOR3 d;
2783 BOOL equal;
2785 static const float table[36] =
2787 2.82094806e-01f, -9.77205038e-01f, 1.46580756e+00f, -4.88602519e-01f, 2.18509698e+00f, -6.55529118e+00f,
2788 8.20018101e+00f, -3.27764559e-00f, -1.63882279e+00f, 1.18008721e+00f, 1.73436680e+01f, -4.02200317e+01f,
2789 4.70202179e+01f, -2.01100159e+01f, -1.30077515e+01f, 6.49047947e+00f, -1.50200577e+01f, 1.06207848e+01f,
2790 1.17325661e+02f, -2.40856750e+02f, 2.71657288e+02f, -1.20428375e+02f, -8.79942474e+01f, 5.84143143e+01f,
2791 -4.38084984e+00f, 2.49425201e+01f, -1.49447693e+02f, 7.82781296e+01f, 7.47791748e+02f, -1.42768787e+03f,
2792 1.57461914e+03f, -7.13843933e+02f, -5.60843811e+02f, 4.30529724e+02f, -4.35889091e+01f, -2.69116650e+01f,
2795 d.x = 1.0; d.y = 2.0f; d.z = 3.0f;
2797 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
2799 for (i = 0; i < ARRAY_SIZE(a); ++i)
2800 a[i] = 1.5f + i;
2802 received_ptr = D3DXSHEvalDirection(a, order, &d);
2803 ok(received_ptr == a, "Expected %p, received %p\n", a, received_ptr);
2805 for (i = 0; i < ARRAY_SIZE(a); ++i)
2807 /* if the order is < D3DXSH_MINORDER or order > D3DXSH_MAXORDER or
2808 * the index of the element is greater than order * order - 1,
2809 * D3DXSHEvalDirection() does not modify the output. */
2810 if ((order < D3DXSH_MINORDER) || (order > D3DXSH_MAXORDER) || (i >= order * order))
2811 expected = 1.5f + i;
2812 else
2813 expected = table[i];
2815 equal = compare_float(a[i], expected, 2);
2816 ok(equal, "order %u, index %u: Got unexpected result %.8e, expected %.8e.\n",
2817 order, i, a[i], expected);
2822 static void test_D3DXSHEvalDirectionalLight(void)
2824 float *blue_out, bout[49], expected, gout[49], *green_out, *red_out, rout[49];
2825 unsigned int j, l, order, startindex;
2826 D3DXVECTOR3 dir;
2827 HRESULT hr;
2828 BOOL equal;
2830 static const float table[] =
2832 /* Red colour */
2833 2.008781f, -4.175174f, 9.602900f, -3.827243f, 1.417963f, -2.947181f,
2834 6.778517f, -2.701583f, 7.249108f, -18.188671f, 34.643921f, -16.672949f,
2835 -0.631551f, 1.417963f, -2.947181f, 6.778517f, -2.701583f, 7.249108f,
2836 -18.188671f, 34.643921f, -16.672949f, -0.631551f, -7.794341f, 52.934967f,
2837 -102.245529f, 181.656815f, -93.725060f, -4.611760f, 10.146287f, 1.555186f,
2838 -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f, 37.996559f,
2839 -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f, 199.236496f,
2840 -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f, 360.268829f,
2841 -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f, -23.864176f,
2842 1.555186f, -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f,
2843 37.996559f, -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f,
2844 199.236496f, -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f,
2845 360.268829f, -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f,
2846 -23.864176f, 34.868664f, -38.354366f, -478.864166f, 2103.939941f, -3334.927734f,
2847 5583.213867f, -3057.017090f, -183.297836f, 623.361633f, -218.449921f, 22.258503f,
2848 /* Green colour */
2849 3.072254f, -6.385560f, 14.686787f, -5.853429f, 2.168650f, -4.507453f,
2850 10.367143f, -4.131832f, 11.086870f, -27.817965f, 52.984818f, -25.499800f,
2851 -0.965902f, 2.168650f, -4.507453f, 10.367143f, -4.131832f, 11.086870f,
2852 -27.817965f, 52.984818f, -25.499800f, -0.965902f, -11.920755f, 80.959351f,
2853 -156.375488f, 277.828033f, -143.344193f, -7.053278f, 15.517849f, 2.378519f,
2854 -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f, 58.112385f,
2855 -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f, 304.714630f,
2856 -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f, 550.999390f,
2857 -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f, -36.498150f,
2858 2.378519f, -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f,
2859 58.112385f, -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f,
2860 304.714630f, -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f,
2861 550.999390f, -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f,
2862 -36.498150f, 53.328545f, -58.659618f, -732.380493f, 3217.790283f, -5100.477539f,
2863 8539.033203f, -4675.437500f, -280.337860f, 953.376587f, -334.099884f, 34.042416f,
2864 /* Blue colour */
2865 4.135726f, -8.595945f, 19.770674f, -7.879617f, 2.919336f, -6.067726f,
2866 13.955770f, -5.562082f, 14.924634f, -37.447262f, 71.325722f, -34.326656f,
2867 -1.300252f, 2.919336f, -6.067726f, 13.955770f, -5.562082f, 14.924634f,
2868 -37.447262f, 71.325722f, -34.326656f, -1.300252f, -16.047173f, 108.983749f,
2869 -210.505493f, 373.999298f, -192.963348f, -9.494799f, 20.889414f, 3.201853f,
2870 -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f, 78.228210f,
2871 -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f, 410.192780f,
2872 -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f, 741.729919f,
2873 -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f, -49.132126f,
2874 3.201853f, -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f,
2875 78.228210f, -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f,
2876 410.192780f, -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f,
2877 741.729919f, -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f,
2878 -49.132126f, 71.788422f, -78.964867f, -985.896790f, 4331.640625f, -6866.027344f,
2879 11494.852539f, -6293.858398f, -377.377899f, 1283.391479f, -449.749817f, 45.826328f, };
2880 const struct
2882 float *red_in, *green_in, *blue_in;
2883 const float *red_out, *green_out, *blue_out;
2884 float roffset, goffset, boffset;
2886 test[] =
2888 { rout, gout, bout, table, &table[90], &table[180], 1.01f, 1.02f, 1.03f, },
2889 { rout, rout, rout, &table[180], &table[180], &table[180], 1.03f, 1.03f, 1.03f, },
2890 { rout, rout, bout, &table[90], &table[90], &table[180], 1.02f, 1.02f, 1.03f, },
2891 { rout, gout, gout, table, &table[180], &table[180], 1.01f, 1.03f, 1.03f, },
2892 { rout, gout, rout, &table[180], &table[90], &table[180], 1.03f, 1.02f, 1.03f, },
2893 /* D3DXSHEvalDirectionaLight accepts NULL green or blue colour. */
2894 { rout, NULL, bout, table, NULL, &table[180], 1.01f, 0.0f, 1.03f, },
2895 { rout, gout, NULL, table, &table[90], NULL, 1.01f, 1.02f, 0.0f, },
2896 { rout, NULL, NULL, table, NULL, NULL, 1.01f, 0.0f, 0.0f, },
2899 dir.x = 1.1f; dir.y= 1.2f; dir.z = 2.76f;
2901 for (l = 0; l < ARRAY_SIZE(test); ++l)
2903 startindex = 0;
2905 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2907 red_out = test[l].red_in;
2908 green_out = test[l].green_in;
2909 blue_out = test[l].blue_in;
2911 for (j = 0; j < ARRAY_SIZE(rout); ++j)
2913 red_out[j] = 1.01f + j;
2914 if ( green_out )
2915 green_out[j] = 1.02f + j;
2916 if ( blue_out )
2917 blue_out[j] = 1.03f + j;
2920 hr = D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red_out, green_out, blue_out);
2921 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2923 for (j = 0; j < ARRAY_SIZE(rout); ++j)
2925 if ( j >= order * order )
2926 expected = j + test[l].roffset;
2927 else
2928 expected = test[l].red_out[startindex + j];
2929 equal = compare_float(expected, red_out[j], 8);
2930 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2931 l, order, j, expected, red_out[j]);
2933 if ( green_out )
2935 if ( j >= order * order )
2936 expected = j + test[l].goffset;
2937 else
2938 expected = test[l].green_out[startindex + j];
2939 equal = compare_float(expected, green_out[j], 8);
2940 ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2941 l, order, j, expected, green_out[j]);
2944 if ( blue_out )
2946 if ( j >= order * order )
2947 expected = j + test[l].boffset;
2948 else
2949 expected = test[l].blue_out[startindex + j];
2950 equal = compare_float(expected, blue_out[j], 4);
2951 ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
2952 l, order, j, expected, blue_out[j]);
2956 startindex += order * order;
2960 /* D3DXSHEvalDirectionalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set*/
2961 hr = D3DXSHEvalDirectionalLight(7, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2962 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2963 hr = D3DXSHEvalDirectionalLight(0, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2964 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2965 hr = D3DXSHEvalDirectionalLight(1, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2966 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2969 static void test_D3DXSHEvalHemisphereLight(void)
2971 float bout[49], expected, gout[49], rout[49];
2972 unsigned int j, l, order;
2973 D3DXCOLOR bottom, top;
2974 D3DXVECTOR3 dir;
2975 HRESULT hr;
2976 BOOL equal;
2978 static const float table[] =
2980 /* Red colour. */
2981 23.422981f, 15.859521f, -36.476898f, 14.537894f,
2982 /* Green colour. */
2983 19.966694f, 6.096982f, -14.023058f, 5.588900f,
2984 /* Blue colour. */
2985 24.566214f, 8.546826f, -19.657701f, 7.834591f,
2987 const struct
2989 float *red_received, *green_received, *blue_received;
2990 const float *red_expected, *green_expected, *blue_expected;
2991 const float roffset, goffset, boffset;
2993 test[] =
2995 { rout, gout, bout, table, &table[4], &table[8], 1.01f, 1.02f, 1.03f, },
2996 { rout, rout, rout, &table[8], &table[8], &table[8], 1.03f, 1.03f, 1.03f, },
2997 { rout, rout, bout, &table[4], &table[4], &table[8], 1.02f, 1.02f, 1.03f, },
2998 { rout, gout, gout, table, &table[8], &table[8], 1.01f, 1.03f, 1.03f, },
2999 { rout, gout, rout, &table[8], &table[4], &table[8], 1.03f, 1.02f, 1.03f, },
3000 /* D3DXSHEvalHemisphereLight accepts NULL green or blue colour. */
3001 { rout, NULL, bout, table, NULL, &table[8], 1.01f, 1.02f, 1.03f, },
3002 { rout, gout, NULL, table, &table[4], NULL, 1.01f, 1.02f, 1.03f, },
3003 { rout, NULL, NULL, table, NULL, NULL, 1.01f, 1.02f, 1.03f, },
3006 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
3007 top.r = 0.1f; top.g = 2.1f; top.b = 2.3f; top.a = 4.3f;
3008 bottom.r = 8.71f; bottom.g = 5.41f; bottom.b = 6.94f; bottom.a = 8.43f;
3010 for (l = 0; l < ARRAY_SIZE(test); ++l)
3011 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER + 1; order++)
3013 for (j = 0; j < 49; j++)
3015 test[l].red_received[j] = 1.01f + j;
3016 if (test[l].green_received)
3017 test[l].green_received[j] = 1.02f + j;
3018 if (test[l].blue_received)
3019 test[l].blue_received[j] = 1.03f + j;
3022 hr = D3DXSHEvalHemisphereLight(order, &dir, top, bottom, test[l].red_received, test[l].green_received, test[l].blue_received);
3023 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3025 for (j = 0; j < 49; j++)
3027 if (j < 4)
3028 expected = test[l].red_expected[j];
3029 else if (j < order * order)
3030 expected = 0.0f;
3031 else
3032 expected = test[l].roffset + j;
3033 equal = compare_float(test[l].red_received[j], expected, 4);
3034 ok(equal, "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3035 l, order, j, expected, test[l].red_received[j]);
3037 if (test[l].green_received)
3039 if (j < 4)
3040 expected = test[l].green_expected[j];
3041 else if (j < order * order)
3042 expected = 0.0f;
3043 else
3044 expected = test[l].goffset + j;
3045 equal = compare_float(expected, test[l].green_received[j], 4);
3046 ok(equal, "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3047 l, order, j, expected, test[l].green_received[j]);
3050 if (test[l].blue_received)
3052 if (j < 4)
3053 expected = test[l].blue_expected[j];
3054 else if (j < order * order)
3055 expected = 0.0f;
3056 else
3057 expected = test[l].boffset + j;
3058 equal = compare_float(expected, test[l].blue_received[j], 4);
3059 ok(equal, "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3060 l, order, j, expected, test[l].blue_received[j]);
3066 static void test_D3DXSHEvalSphericalLight(void)
3068 float bout[49], expected, gout[49], rout[49];
3069 unsigned int j, l, order;
3070 D3DXVECTOR3 dir;
3071 HRESULT hr;
3072 BOOL equal;
3074 static const float table[] =
3076 /* Red colour. */
3077 3.01317239e+00f, -9.77240324e-01f, 2.24765277e+00f, -8.95803630e-01f, -1.22213947e-07f, 3.06645916e-07f,
3078 -3.36369283e-07f, 2.81092071e-07f, 1.06474305e-08f, 6.29281402e-02f, -4.27374065e-01f, 6.19212627e-01f,
3079 -3.04508984e-01f, 5.67611575e-01f, 3.72333601e-02f, -8.19167346e-02f, -4.70457762e-09f, -7.94764006e-08f,
3080 3.32868979e-07f, -3.08902315e-07f, 5.30925970e-10f, -2.83160460e-07f, -2.89999580e-08f, 1.03458447e-07f,
3081 -2.67952434e-08f, 1.24992710e-02f, -1.37487827e-02f, -1.48109317e-01f, 4.34345961e-01f, -2.45986164e-01f,
3082 -1.51757941e-01f, -2.25487292e-01f, -3.78407575e-02f, 1.92801371e-01f, -7.83071220e-02f, 7.97894225e-03f,
3084 4.02519643e-01f, -2.43653327e-01f, 5.60402632e-01f, -2.23348871e-01f, 1.62046894e-01f, -4.06590402e-01f,
3085 4.46001410e-01f, -3.72707844e-01f, -1.41177261e-02f, -4.31995131e-02f, 2.93387860e-01f, -4.25083041e-01f,
3086 2.09042251e-01f, -3.89659435e-01f, -2.55603138e-02f, 5.62349856e-02f, -4.68822848e-03f, -7.92002082e-02f,
3087 3.31712216e-01f, -3.07828844e-01f, 5.29080920e-04f, -2.82176435e-01f, -2.88991798e-02f, 1.03098914e-01f,
3088 -2.67021265e-02f, 7.24340184e-03f, -7.96750095e-03f, -8.58302265e-02f, 2.51706064e-01f, -1.42550439e-01f,
3089 -8.79446268e-02f, -1.30671218e-01f, -2.19289437e-02f, 1.11729540e-01f, -4.53794412e-02f, 4.62384429e-03f,
3091 1.95445275e+00f, -8.56593668e-01f, 1.97016549e+00f, -7.85210848e-01f, 2.31033459e-01f, -5.79683959e-01f,
3092 6.35873020e-01f, -5.31376958e-01f, -2.01279204e-02f, 2.11104341e-02f, -1.43370718e-01f, 2.07726598e-01f,
3093 -1.02153301e-01f, 1.90416038e-01f, 1.24906348e-02f, -2.74805184e-02f, 6.33162493e-03f, 1.06962793e-01f,
3094 -4.47989494e-01f, 4.15734142e-01f, -7.14543217e-04f, 3.81089628e-01f, 3.90294008e-02f, -1.39238864e-01f,
3095 3.60621996e-02f, -4.47360286e-03f, 4.92081419e-03f, 5.30096702e-02f, -1.55456364e-01f, 8.80406797e-02f,
3096 5.43155447e-02f, 8.07039514e-02f, 1.35435509e-02f, -6.90053627e-02f, 2.80268304e-02f, -2.85573583e-03f,
3097 /* Green colour. */
3098 4.60838127e+00f, -1.49460280e+00f, 3.43758631e+00f, -1.37005258e+00f, -1.86915443e-07f, 4.68987878e-07f,
3099 -5.14447095e-07f, 4.29905526e-07f, 1.62843055e-08f, 9.62430239e-02f, -6.53630912e-01f, 9.47031021e-01f,
3100 -4.65719581e-01f, 8.68111789e-01f, 5.69451340e-02f, -1.25284418e-01f, -7.19523641e-09f, -1.21552148e-07f,
3101 5.09093695e-07f, -4.72438842e-07f, 8.12004408e-10f, -4.33068919e-07f, -4.43528769e-08f, 1.58230563e-07f,
3102 -4.09809608e-08f, 1.91165321e-02f, -2.10275482e-02f, -2.26520121e-01f, 6.64293766e-01f, -3.76214117e-01f,
3103 -2.32100368e-01f, -3.44862908e-01f, -5.78740984e-02f, 2.94872671e-01f, -1.19763829e-01f, 1.22030871e-02f,
3105 6.15618229e-01f, -3.72646272e-01f, 8.57086360e-01f, -3.41592401e-01f, 2.47836411e-01f, -6.21844113e-01f,
3106 6.82119787e-01f, -5.70023775e-01f, -2.15918161e-02f, -6.60698414e-02f, 4.48710799e-01f, -6.50126934e-01f,
3107 3.19711655e-01f, -5.95949709e-01f, -3.90922427e-02f, 8.60064477e-02f, -7.17023155e-03f, -1.21129729e-01f,
3108 5.07324517e-01f, -4.70797032e-01f, 8.09182529e-04f, -4.31563944e-01f, -4.41987440e-02f, 1.57680690e-01f,
3109 -4.08385433e-02f, 1.10781426e-02f, -1.21855885e-02f, -1.31269753e-01f, 3.84962171e-01f, -2.18018293e-01f,
3110 -1.34503528e-01f, -1.99850082e-01f, -3.35383788e-02f, 1.70880452e-01f, -6.94038495e-02f, 7.07176095e-03f,
3112 2.98916292e+00f, -1.31008446e+00f, 3.01319408e+00f, -1.20091069e+00f, 3.53345245e-01f, -8.86575401e-01f,
3113 9.72511649e-01f, -8.12694073e-01f, -3.07838768e-02f, 3.22865434e-02f, -2.19272852e-01f, 3.17699492e-01f,
3114 -1.56234443e-01f, 2.91224509e-01f, 1.91033222e-02f, -4.20290269e-02f, 9.68366116e-03f, 1.63590148e-01f,
3115 -6.85160398e-01f, 6.35828674e-01f, -1.09283067e-03f, 5.82842946e-01f, 5.96920252e-02f, -2.12953553e-01f,
3116 5.51539510e-02f, -6.84198039e-03f, 7.52595067e-03f, 8.10736120e-02f, -2.37756789e-01f, 1.34650454e-01f,
3117 8.30708295e-02f, 1.23429567e-01f, 2.07136646e-02f, -1.05537608e-01f, 4.28645648e-02f, -4.36759600e-03f,
3118 /* Blue colour. */
3119 6.20359039e+00f, -2.01196527e+00f, 4.62752008e+00f, -1.84430146e+00f, -2.51616967e-07f, 6.31329840e-07f,
3120 -6.92524964e-07f, 5.78718982e-07f, 2.19211813e-08f, 1.29557922e-01f, -8.79887760e-01f, 1.27484941e+00f,
3121 -6.26930237e-01f, 1.16861200e+00f, 7.66569078e-02f, -1.68652087e-01f, -9.68589564e-09f, -1.63627888e-07f,
3122 6.85318469e-07f, -6.35975368e-07f, 1.09308285e-09f, -5.82977407e-07f, -5.97057976e-08f, 2.13002679e-07f,
3123 -5.51666766e-08f, 2.57337932e-02f, -2.83063166e-02f, -3.04930955e-01f, 8.94241691e-01f, -5.06442070e-01f,
3124 -3.12442809e-01f, -4.64238554e-01f, -7.79074430e-02f, 3.96944016e-01f, -1.61220551e-01f, 1.64272338e-02f,
3126 8.28716874e-01f, -5.01639187e-01f, 1.15377009e+00f, -4.59835887e-01f, 3.33625972e-01f, -8.37097943e-01f,
3127 9.18238282e-01f, -7.67339706e-01f, -2.90659070e-02f, -8.89401734e-02f, 6.04033828e-01f, -8.75170946e-01f,
3128 4.30381119e-01f, -8.02240014e-01f, -5.26241735e-02f, 1.15777917e-01f, -9.65223555e-03f, -1.63059264e-01f,
3129 6.82936907e-01f, -6.33765280e-01f, 1.08928420e-03f, -5.80951512e-01f, -5.94983101e-02f, 2.12262481e-01f,
3130 -5.49749658e-02f, 1.49128847e-02f, -1.64036769e-02f, -1.76709279e-01f, 5.18218338e-01f, -2.93486178e-01f,
3131 -1.81062460e-01f, -2.69028962e-01f, -4.51478213e-02f, 2.30031401e-01f, -9.34282616e-02f, 9.51967947e-03f,
3133 4.02387333e+00f, -1.76357520e+00f, 4.05622292e+00f, -1.61661065e+00f, 4.75657105e-01f, -1.19346702e+00f,
3134 1.30915034e+00f, -1.09401131e+00f, -4.14398350e-02f, 4.34626564e-02f, -2.95174986e-01f, 4.27672386e-01f,
3135 -2.10315600e-01f, 3.92033011e-01f, 2.57160105e-02f, -5.65775372e-02f, 1.30356979e-02f, 2.20217496e-01f,
3136 -9.22331274e-01f, 8.55923176e-01f, -1.47111830e-03f, 7.84596264e-01f, 8.03546458e-02f, -2.86668241e-01f,
3137 7.42457062e-02f, -9.21035837e-03f, 1.01310881e-02f, 1.09137557e-01f, -3.20057213e-01f, 1.81260213e-01f,
3138 1.11826122e-01f, 1.66155189e-01f, 2.78837811e-02f, -1.42069861e-01f, 5.77022992e-02f, -5.87945618e-03f,
3140 const struct
3142 float *red_received, *green_received, *blue_received;
3143 const float *red_expected, *green_expected, *blue_expected;
3144 float radius, roffset, goffset, boffset;
3146 test[] =
3148 { rout, gout, bout, table, &table[108], &table[216], 17.4f, 1.01f, 1.02f, 1.03f, },
3149 { rout, gout, bout, &table[36], &table[144], &table[252], 1.6f, 1.01f, 1.02f, 1.03f, },
3150 { rout, gout, bout, &table[72], &table[180], &table[288], -3.0f, 1.01f, 1.02f, 1.03f, },
3151 { rout, rout, rout, &table[216], &table[216], &table[216], 17.4f, 1.03f, 1.03f, 1.03f, },
3152 { rout, rout, bout, &table[108], &table[108], &table[216], 17.4, 1.02f, 1.02f, 1.03f, },
3153 { rout, gout, gout, table, &table[216], &table[216], 17.4f, 1.01f, 1.03f, 1.03f, },
3154 { rout, gout, rout, &table[216], &table[108], &table[216], 17.4f, 1.03f, 1.02f, 1.03f, },
3155 /* D3DXSHEvalSphericalLight accepts NULL green or blue colour. */
3156 { rout, NULL, bout, table, NULL, &table[216], 17.4f, 1.01f, 0.0f, 1.03f, },
3157 { rout, gout, NULL, table, &table[108], NULL, 17.4f, 1.01f, 1.02f, 0.0f, },
3158 { rout, NULL, NULL, table, NULL, NULL, 17.4f, 1.01f, 0.0f, 0.0f, },
3161 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
3163 for (l = 0; l < ARRAY_SIZE(test); ++l)
3165 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3167 for (j = 0; j < 49; j++)
3169 test[l].red_received[j] = 1.01f + j;
3170 if (test[l].green_received)
3171 test[l].green_received[j] = 1.02f + j;
3172 if (test[l].blue_received)
3173 test[l].blue_received[j] = 1.03f + j;
3176 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);
3177 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3179 for (j = 0; j < 49; j++)
3181 if (j >= order * order)
3182 expected = j + test[l].roffset;
3183 else
3184 expected = test[l].red_expected[j];
3185 equal = compare_float(expected, test[l].red_received[j], 2048);
3186 ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].red_received[j]) < 1.0e-6f),
3187 "Red: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3188 l, order, j, expected, test[l].red_received[j]);
3190 if (test[l].green_received)
3192 if (j >= order * order)
3193 expected = j + test[l].goffset;
3194 else
3195 expected = test[l].green_expected[j];
3196 equal = compare_float(expected, test[l].green_received[j], 2048);
3197 ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].green_received[j]) < 1.0e-6f),
3198 "Green: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3199 l, order, j, expected, test[l].green_received[j]);
3202 if (test[l].blue_received)
3204 if (j >= order * order)
3205 expected = j + test[l].boffset;
3206 else
3207 expected = test[l].blue_expected[j];
3208 equal = compare_float(expected, test[l].blue_received[j], 2048);
3209 ok(equal || (fabs(expected) < 1.0e-6f && fabs(test[l].blue_received[j]) < 1.0e-6f),
3210 "Blue: case %u, order %u: expected[%u] = %.8e, received %.8e.\n",
3211 l, order, j, expected, test[l].blue_received[j]);
3217 /* D3DXSHEvalSphericalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
3218 hr = D3DXSHEvalSphericalLight(7, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3219 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3220 hr = D3DXSHEvalSphericalLight(0, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3221 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3222 hr = D3DXSHEvalSphericalLight(1, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3223 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3226 static void test_D3DXSHMultiply2(void)
3228 float a[20], b[20], c[20];
3229 unsigned int i;
3230 BOOL equal;
3232 /* D3DXSHMultiply2() only modifies the first 4 elements of the array. */
3233 static const float expected[20] =
3235 3.41859412f, 1.69821072f, 1.70385253f, 1.70949447f, 4.0f, 5.0f, 6.0f,
3236 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
3237 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
3240 for (i = 0; i < ARRAY_SIZE(a); ++i)
3242 a[i] = 1.0f + i / 100.0f;
3243 b[i] = 3.0f - i / 100.0f;
3244 c[i] = i;
3247 D3DXSHMultiply2(c, a, b);
3248 for (i = 0; i < ARRAY_SIZE(expected); ++i)
3250 equal = compare_float(c[i], expected[i], 2);
3251 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
3255 static void test_D3DXSHMultiply3(void)
3257 float a[20], b[20], c[20];
3258 unsigned int i;
3259 BOOL equal;
3261 /* D3DXSHMultiply3() only modifies the first 9 elements of the array. */
3262 static const float expected[20] =
3264 7.81391382e+00f, 2.25605774e+00f, 5.94839954e+00f, 4.97089481e+00f, 2.89985824e+00f, 3.59894633e+00f,
3265 1.72657156e+00f, 5.57353783e+00f, 6.22063160e-01f, 9.00000000e+00f, 1.00000000e+01f, 1.10000000e+01f,
3266 1.20000000e+01f, 1.30000000e+01f, 1.40000000e+01f, 1.50000000e+01f, 1.60000000e+01f, 1.70000000e+01f,
3267 1.80000000e+01f, 1.90000000e+01f,
3269 static const float expected_aliased[20] =
3271 4.54092499e+02f, 2.12640405e+00f, 5.57040071e+00f, 1.53303785e+01f, 2.27960873e+01f, 4.36041260e+01f,
3272 4.27384138e+00f, 1.75772034e+02f, 2.37672729e+02f, 1.09000003e+00f, 1.10000002e+00f, 1.11000001e+00f,
3273 1.12000000e+00f, 1.13000000e+00f, 1.13999999e+00f, 1.14999998e+00f, 1.15999997e+00f, 1.16999996e+00f,
3274 1.17999995e+00f, 1.19000006e+00f,
3277 for (i = 0; i < ARRAY_SIZE(a); ++i)
3279 a[i] = 1.0f + i / 100.0f;
3280 b[i] = 3.0f - i / 100.0f;
3281 c[i] = i;
3284 D3DXSHMultiply3(c, a, b);
3285 for (i = 0; i < ARRAY_SIZE(expected); ++i)
3287 equal = compare_float(c[i], expected[i], 4);
3288 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
3291 memcpy(c, a, sizeof(c));
3292 D3DXSHMultiply3(c, c, b);
3293 for (i = 0; i < ARRAY_SIZE(expected_aliased); ++i)
3295 equal = compare_float(c[i], expected_aliased[i], 32);
3296 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected_aliased[i], c[i]);
3300 static void test_D3DXSHMultiply4(void)
3302 float a[20], b[20], c[20];
3303 unsigned int i;
3304 BOOL equal;
3306 /* D3DXSHMultiply4() only modifies the first 16 elements of the array. */
3307 static const float expected[] =
3309 /* c, a, b */
3310 1.41825991e+01f, 2.61570334e+00f, 1.28286009e+01f, 9.82059574e+00f, 3.03969646e+00f, 4.53044176e+00f,
3311 5.82058382e+00f, 1.22498465e+01f, 2.19434643e+00f, 3.90015244e+00f, 5.41660881e+00f, 5.60181284e+00f,
3312 9.59981740e-01f, 7.03754997e+00f, 3.62523031e+00f, 4.63601470e-01f, 1.60000000e+01f, 1.70000000e+01f,
3313 1.80000000e+01f, 1.90000000e+01f,
3314 /* c, c, b */
3315 -2.11441266e+05f, -2.52915771e+03f, -1.00233936e+04f, -4.41277191e+02f, -1.63994385e+02f, -5.26305115e+02f,
3316 2.96361875e+04f, -3.93183081e+03f, -1.35771113e+04f, -3.97897388e+03f, -1.03303418e+04f, -1.37797871e+04f,
3317 -1.66851094e+04f, -4.49813750e+04f, -7.32697422e+04f, -9.52373359e+04f, 1.60000000e+01f, 1.70000000e+01f,
3318 1.80000000e+01f, 1.90000000e+01f,
3319 /* c, c, c */
3320 2.36682415e-01f, -7.17648506e-01f, -1.80499524e-01f, -7.71235973e-02f, 1.44830629e-01f, 5.73285699e-01f,
3321 -3.37959230e-01f, 5.56938872e-02f, -4.42100227e-01f, 1.47701755e-01f, -5.51566519e-02f, 8.43374059e-02f,
3322 1.79876596e-01f, 9.09878965e-03f, 2.32199892e-01f, 7.41420984e-02f, 1.60000002e+00f, 1.70000005e+00f,
3323 1.80000007e+00f, 1.89999998e+00f,
3326 for (i = 0; i < ARRAY_SIZE(a); ++i)
3328 a[i] = 1.0f + i / 100.0f;
3329 b[i] = 3.0f - i / 100.0f;
3330 c[i] = i;
3333 D3DXSHMultiply4(c, a, b);
3334 for (i = 0; i < ARRAY_SIZE(c); ++i)
3336 equal = compare_float(c[i], expected[i], 16);
3337 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[i], c[i]);
3340 for (i = 0; i < ARRAY_SIZE(b); ++i)
3342 b[i] = 3.0f - i / 100.0f;
3343 c[i] = i;
3346 D3DXSHMultiply4(c, c, b);
3347 for (i = 0; i < ARRAY_SIZE(c); ++i)
3349 equal = compare_float(c[i], expected[20 + i], 32);
3350 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[20 + i], c[i]);
3353 for (i = 0; i < ARRAY_SIZE(c); ++i)
3354 c[i] = 0.1f * i;
3356 D3DXSHMultiply4(c, c, c);
3357 for (i = 0; i < ARRAY_SIZE(c); ++i)
3359 equal = compare_float(c[i], expected[40 + i], 8);
3360 ok(equal, "Expected[%u] = %.8e, received = %.8e.\n", i, expected[40 + i], c[i]);
3364 static void test_D3DXSHRotate(void)
3366 float expected, in[49], out[49], *out_temp, *received_ptr;
3367 unsigned int i, j, l, order;
3368 D3DXMATRIX m[4];
3369 BOOL equal;
3371 static const float table[]=
3373 /* Rotation around the x-axis, π/2. */
3374 1.00999999e+00f, -3.00999999e+00f, 2.00999975e+00f, 4.01000023e+00f, -8.01000023e+00f, -6.00999928e+00f,
3375 -1.13078899e+01f, 5.00999975e+00f, -1.56583869e+00f, 1.09359801e+00f, -1.10099983e+01f, 1.98334141e+01f,
3376 -1.52681913e+01f, -1.90041180e+01f, -3.36488891e+00f, -9.56262684e+00f, 1.20996542e+01f, -2.72131383e-01f,
3377 3.02410126e+01f, 2.69199905e+01f, 3.92368774e+01f, -2.26324463e+01f, 6.70738792e+00f, -1.17682819e+01f,
3378 3.44367194e+00f, -6.07445812e+00f, 1.16183939e+01f, 1.52756083e+00f, 3.78963356e+01f, -5.69012184e+01f,
3379 4.74228935e+01f, 5.03915329e+01f, 1.06181908e+01f, 2.55010109e+01f, 4.92456071e-02f, 1.69833069e+01f,
3381 1.00999999e+00f, -3.00999999e+00f, -3.01000023e+00f, 4.01000023e+00f, -8.01000023e+00f, -6.00999928e+00f,
3382 -1.13078890e+01f, -8.01000023e+00f, 1.42979193e+01f,
3383 /* Rotation around the x-axis, -π/2. */
3384 1.00999999e+00f, 3.00999999e+00f, -2.01000023e+00f, 4.01000023e+00f, 8.01000023e+00f, -6.01000118e+00f,
3385 -1.13078880e+01f, -5.01000071e+00f, -1.56583774e+00f, -1.09359753e+00f, -1.10100021e+01f, -1.98334103e+01f,
3386 1.52681961e+01f, -1.90041142e+01f, 3.36489248e+00f, -9.56262398e+00f, -1.20996523e+01f, -2.72129118e-01f,
3387 -3.02410049e+01f, 2.69200020e+01f, 3.92368736e+01f, 2.26324520e+01f, 6.70738268e+00f, 1.17682877e+01f,
3388 3.44367099e+00f, 6.07445717e+00f, 1.16183996e+01f, -1.52756333e+00f, 3.78963509e+01f, 5.69011993e+01f,
3389 -4.74229126e+01f, 5.03915253e+01f, -1.06182041e+01f, 2.55009995e+01f, -4.92481887e-02f, 1.69833050e+01f,
3391 1.00999999e+00f, 3.00999999e+00f, -3.01000023e+00f, 4.01000023e+00f, 8.01000023e+00f, -6.01000118e+00f,
3392 -1.13078899e+01f, -8.01000023e+00f, 1.42979193e+01f,
3393 /* Yaw π/3, pitch π/4, roll π/5. */
3394 1.00999999e+00f, 4.94489908e+00f, 1.44230127e+00f, 1.62728095e+00f, 2.19220325e-01f, 1.05408239e+01f,
3395 -9.13690281e+00f, 2.76374960e+00f, -7.30904531e+00f, -5.87572050e+00f, 5.30312395e+00f, -8.68215370e+00f,
3396 -2.56833839e+01f, 1.68027866e+00f, -1.88083878e+01f, 7.65365601e+00f, 1.69391327e+01f, -1.73280182e+01f,
3397 1.46297951e+01f, -5.44671021e+01f, -1.22310352e+01f, -4.08985710e+00f, -9.44422245e+00f, 3.05603528e+00f,
3398 1.79257303e-01f, -1.00418749e+01f, 2.30900917e+01f, -2.31887093e+01f, 1.17270985e+01f, -6.51830902e+01f,
3399 4.86715775e+01f, -1.50732088e+01f, 3.87931709e+01f, -2.60395355e+01f, 6.19276857e+00f, -1.76722469e+01f,
3401 1.00999999e+00f, 4.94489908e+00f, -8.91142070e-01f, 4.60769463e+00f, 2.19218358e-01f, 1.07733250e+01f,
3402 -8.20476913e+00f, 1.35638294e+01f, -1.20077667e+01f,
3403 /* Rotation around the z-axis, π/6. */
3404 1.00999999e+00f, 3.74571109e+00f, 3.00999999e+00f, 2.46776199e+00f, 1.03078890e+01f, 9.20981312e+00f,
3405 7.01000023e+00f, 3.93186355e+00f, 1.66212186e-01f, 1.60099983e+01f, 1.85040417e+01f, 1.74059658e+01f,
3406 1.30100002e+01f, 6.12801647e+00f, -2.02994061e+00f, -1.00100012e+01f, 1.31542921e+01f, 2.40099964e+01f,
3407 2.94322453e+01f, 2.83341675e+01f, 2.10100021e+01f, 9.05622101e+00f, -4.95814323e+00f, -1.80100002e+01f,
3408 -2.72360935e+01f, -4.52033186e+00f, 1.68145428e+01f, 3.40099945e+01f, 4.30924950e+01f, 4.19944229e+01f,
3409 3.10100002e+01f, 1.27164707e+01f, -8.61839962e+00f, -2.80100021e+01f, -4.08963470e+01f, -4.41905708e+01f,
3411 1.00999999e+00f, 3.74571109e+00f, 3.00999999e+00f, 1.59990644e+00f, 1.03078890e+01f, 9.20981312e+00f,
3412 7.01000023e+00f, 2.33195710e+00f, -4.42189360e+00f,
3415 D3DXMatrixRotationX(&m[0], -D3DX_PI / 2.0f);
3416 D3DXMatrixRotationX(&m[1], D3DX_PI / 2.0f);
3417 D3DXMatrixRotationYawPitchRoll(&m[2], D3DX_PI / 3.0f, D3DX_PI / 4.0f, D3DX_PI / 5.0f);
3418 D3DXMatrixRotationZ(&m[3], D3DX_PI / 6.0f);
3420 for (l = 0; l < 2; l++)
3422 if (l == 0)
3423 out_temp = out;
3424 else
3425 out_temp = in;
3427 for (j = 0; j < ARRAY_SIZE(m); ++j)
3429 for (order = 0; order <= D3DXSH_MAXORDER; order++)
3431 for (i = 0; i < ARRAY_SIZE(out); ++i)
3433 out[i] = ( i + 1.0f ) * ( i + 1.0f );
3434 in[i] = i + 1.01f;
3437 received_ptr = D3DXSHRotate(out_temp, order, &m[j], in);
3438 ok(received_ptr == out_temp, "Order %u, expected %p, received %p.\n",
3439 order, out, received_ptr);
3441 for (i = 0; i < ARRAY_SIZE(out); ++i)
3443 if ((i > 0) && ((i >= order * order) || (order > D3DXSH_MAXORDER)))
3445 if (l == 0)
3446 expected = ( i + 1.0f ) * ( i + 1.0f );
3447 else
3448 expected = i + 1.01f;
3450 else if ((l == 0) || (order > 3))
3451 expected = table[45 * j + i];
3452 else
3453 expected = table[45 * j + 36 +i];
3454 equal = compare_float(out_temp[i], expected, 4096);
3455 ok(equal, "Order %u index %u, expected %.8e, received %.8e.\n",
3456 order, i, expected, out_temp[i]);
3463 static void test_D3DXSHRotateZ(void)
3465 float expected, in[49], out[49], *out_temp, *received_ptr;
3466 unsigned int end, i, j, l, order, square;
3467 BOOL equal;
3469 static const float angle[] = {D3DX_PI / 3.0f, -D3DX_PI / 3.0f, 4.0f * D3DX_PI / 3.0f};
3470 static const float table[] =
3472 /* Angle π/3. */
3473 1.00999999e+00f, 4.47776222e+00f, 3.00999999e+00f, 2.64288902e-01f, 5.29788828e+00f, 9.94186401e+00f,
3474 7.01000023e+00f, -1.19981313e+00f, -8.84378910e+00f, -1.00100021e+01f, 7.49403954e+00f, 1.81380157e+01f,
3475 1.30100002e+01f, -3.39596605e+00f, -1.70399418e+01f, -1.60099983e+01f, -3.01642971e+01f, -1.80100040e+01f,
3476 1.04222422e+01f, 2.90662193e+01f, 2.10100002e+01f, -6.32417059e+00f, -2.79681454e+01f, -2.40099983e+01f,
3477 2.22609901e+00f, -1.81805649e+01f, -4.38245506e+01f, -2.80100040e+01f, 1.40824928e+01f, 4.27264709e+01f,
3478 3.10100002e+01f, -9.98442554e+00f, -4.16283989e+01f, -3.40099945e+01f, 5.88635778e+00f, 4.05303307e+01f,
3480 1.00999999e+00f, 4.47776222e+00f, 0.00000000e+00f, -5.81678391e+00f, 5.29788828e+00f, 6.93686390e+00f,
3481 0.00000000e+00f, -9.01125050e+00f, -2.29405236e+00f, -1.00100021e+01f, 1.29990416e+01f, 1.21330166e+01f,
3482 0.00000000e+00f, -1.57612505e+01f, -5.62874842e+00f, 0.00000000e+00f, -3.01642971e+01f, -3.29017075e-06f,
3483 1.99272442e+01f, 1.90612202e+01f, 0.00000000e+00f, -2.47612514e+01f, -8.62874794e+00f, 0.00000000e+00f,
3484 -1.30615301e+01f, -1.81805649e+01f, -3.03195534e+01f, -4.66050415e-06f, 2.85874958e+01f, 2.77214737e+01f,
3485 0.00000000e+00f, -3.60112534e+01f, -1.23787460e+01f, 0.00000000e+00f, -1.31287584e+01f, -2.36172504e+01f,
3487 1.00999999e+00f, 3.97776222e+00f, 3.97776222e+00f, 1.11419535e+00f, 7.24579096e+00f, 1.05597591e+01f,
3488 1.05597591e+01f, -9.95159924e-01f, -4.67341393e-01f, 4.67339337e-01f, 1.27653713e+01f, 1.85157013e+01f,
3489 1.85157013e+01f, -1.79728663e+00f, 4.93915796e-01f, -4.93915856e-01f, -2.14123421e+01f, 2.14123383e+01f,
3490 9.22107220e+00f, 2.36717567e+01f, 2.36717567e+01f, 3.85019469e+00f, -2.04687271e+01f, 2.04687233e+01f,
3491 -1.06621027e+01f, -3.65166283e+01f, -1.20612450e+01f, 1.20612402e+01f, 2.25568752e+01f, 3.89999084e+01f,
3492 3.89999084e+01f, -3.48751247e-02f, -1.04279022e+01f, 1.04279003e+01f, -3.68382835e+01f, -2.76528034e+01f,
3493 /* Angle -π/3. */
3494 1.00999999e+00f, -2.46776247e+00f, 3.00999999e+00f, 3.74571109e+00f, -1.03078899e+01f, -3.93186426e+00f,
3495 7.01000023e+00f, 9.20981312e+00f, -1.66213632e-01f, -1.00099983e+01f, -1.85040436e+01f, -6.12801695e+00f,
3496 1.30100002e+01f, 1.74059658e+01f, 2.02993774e+00f, -1.60100021e+01f, 1.31543026e+01f, -1.80099964e+01f,
3497 -2.94322472e+01f, -9.05622101e+00f, 2.10100002e+01f, 2.83341694e+01f, 4.95813942e+00f, -2.40100021e+01f,
3498 -2.72360916e+01f, 4.41905823e+01f, 1.68145580e+01f, -2.80099964e+01f, -4.30924988e+01f, -1.27164736e+01f,
3499 3.10100002e+01f, 4.19944229e+01f, 8.61839294e+00f, -3.40100021e+01f, -4.08963470e+01f, -4.52030993e+00f,
3501 1.00999999e+00f, -2.46776247e+00f, 0.00000000e+00f, -3.20571756e+00f, -1.03078899e+01f, -6.93686390e+00f,
3502 0.00000000e+00f, -9.01125050e+00f, -4.46344614e+00f, -1.00099983e+01f, -1.29990416e+01f, -1.21330166e+01f,
3503 0.00000000e+00f, -1.57612505e+01f, -5.62874842e+00f, 0.00000000e+00f, 1.31543026e+01f, 3.29017075e-06f,
3504 -1.99272442e+01f, -1.90612202e+01f, 0.00000000e+00f, -2.47612514e+01f, -8.62874794e+00f, 0.00000000e+00f,
3505 -5.69598293e+00f, 4.41905823e+01f, 3.03195534e+01f, 4.66050415e-06f, -2.85874958e+01f, -2.77214737e+01f,
3506 0.00000000e+00f, -3.60112534e+01f, -1.23787460e+01f, 0.00000000e+00f, -1.31287584e+01f, -5.74052582e+01f,
3508 1.00999999e+00f, -2.96776223e+00f, -2.96776223e+00f, -6.09195352e-01f, -7.49829102e+00f, -1.06860094e+01f,
3509 -1.06860094e+01f, -1.18367157e+01f, 5.39078045e+00f, -5.39077854e+00f, -1.03036509e+01f, -1.72848415e+01f,
3510 -1.72848415e+01f, -1.75656433e+01f, 4.11427259e+00f, -4.11427307e+00f, 2.37164364e+01f, -2.37164326e+01f,
3511 -8.06902504e+00f, -2.30957317e+01f, -2.30957317e+01f, -1.85358467e+01f, -1.12711067e+01f, 1.12711039e+01f,
3512 -2.07248449e+00f, 3.01493301e+01f, 1.52448931e+01f, -1.52448883e+01f, -2.09650497e+01f, -3.82039986e+01f,
3513 -3.82039986e+01f, -3.72582664e+01f, 5.42667723e+00f, -5.42667913e+00f, -2.33967514e+01f, -9.90355873e+00f,
3514 /* Angle 4π/3. */
3515 1.00999999e+00f, -4.47776222e+00f, 3.00999999e+00f, -2.64288664e-01f, 5.29788685e+00f, -9.94186401e+00f,
3516 7.01000023e+00f, 1.19981360e+00f, -8.84378815e+00f, 1.00100040e+01f, 7.49403811e+00f, -1.81380157e+01f,
3517 1.30100002e+01f, 3.39596677e+00f, -1.70399399e+01f, 1.60099964e+01f, -3.01642933e+01f, 1.80100060e+01f,
3518 1.04222393e+01f, -2.90662193e+01f, 2.10100002e+01f, 6.32417202e+00f, -2.79681435e+01f, 2.40099926e+01f,
3519 2.22610497e+00f, 1.81805515e+01f, -4.38245430e+01f, 2.80100079e+01f, 1.40824890e+01f, -4.27264709e+01f,
3520 3.10100002e+01f, 9.98442745e+00f, -4.16283989e+01f, 3.40099869e+01f, 5.88636589e+00f, -4.05303268e+01f,
3522 1.00999999e+00f, -4.47776222e+00f, 0.00000000e+00f, -1.93892837e+00f, 5.29788685e+00f, -6.93686390e+00f,
3523 0.00000000e+00f, -3.00375080e+00f, -2.29405141e+00f, 1.00100040e+01f, 1.29990396e+01f, -1.21330166e+01f,
3524 0.00000000e+00f, -5.25375128e+00f, -5.62874699e+00f, -5.68378528e-06f, -3.01642933e+01f, 7.00829787e-06f,
3525 1.99272423e+01f, -1.90612202e+01f, 0.00000000e+00f, -8.25375271e+00f, -8.62874603e+00f, -4.09131496e-12f,
3526 -1.30615349e+01f, 1.81805515e+01f, -3.03195534e+01f, 9.92720470e-06f, 2.85874920e+01f, -2.77214737e+01f,
3527 0.00000000e+00f, -1.20037527e+01f, -1.23787422e+01f, -5.79531909e-12f, -1.31287651e+01f, -7.87240028e+00f,
3529 1.00999999e+00f, -3.97776222e+00f, -3.97776222e+00f, 2.86356640e+00f, 6.37110424e+00f, -1.01224155e+01f,
3530 -1.01224155e+01f, 1.05787458e+01f, -7.76929522e+00f, -7.76928997e+00f, 1.68836861e+01f, -2.05748577e+01f,
3531 -2.05748577e+01f, 2.49091301e+01f, -5.72616625e+00f, -5.72616386e+00f, -1.87962208e+01f, -1.87962112e+01f,
3532 2.93253498e+01f, -3.37238922e+01f, -3.37238922e+01f, 4.22584419e+01f, -4.85123205e+00f, -4.85122633e+00f,
3533 -2.53339314e+00f, 3.24522591e+01f, -4.65456696e+01f, -4.65456543e+01f, 5.18603249e+01f, -5.36516304e+01f,
3534 -5.36516304e+01f, 7.17381744e+01f, 4.44061565e+00f, 4.44062901e+00f, 2.58841743e+01f, -1.07481155e+01f,
3537 for (l = 0; l < 3; l++)
3539 if (l == 0)
3540 out_temp = out;
3541 else
3542 out_temp = &in[l - 1];
3544 if (l < 2)
3545 end = 49;
3546 else
3547 end = 48;
3549 for (j = 0; j < ARRAY_SIZE(angle); ++j)
3551 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
3553 for (i = 0; i < ARRAY_SIZE(out); ++i)
3555 out[i] = ( i + 1.0f ) * ( i + 1.0f );
3556 in[i] = i + 1.01f;
3559 received_ptr = D3DXSHRotateZ(out_temp, order, angle[j], in);
3560 ok(received_ptr == out_temp, "angle %f, order %u, expected %p, received %p\n", angle[j], order, out_temp, received_ptr);
3562 for (i = 0; i < end; i++)
3564 /* order = 0 or order = 1 behaves like order = D3DXSH_MINORDER */
3565 square = (order <= D3DXSH_MINORDER) ? D3DXSH_MINORDER * D3DXSH_MINORDER : order * order;
3566 if (i >= square || ((order >= D3DXSH_MAXORDER) && (i >= D3DXSH_MAXORDER * D3DXSH_MAXORDER)))
3567 if (l > 0)
3568 expected = i + l + 0.01f;
3569 else
3570 expected = ( i + 1.0f ) * ( i + 1.0f );
3571 else
3572 expected = table[36 * (l + 3 * j) + i];
3573 equal = compare_float(expected, out_temp[i], 256);
3574 ok(equal || (fabs(expected) < 2.0e-5f && fabs(out_temp[i]) < 2.0e-5f),
3575 "angle %.8e, order %u index %u, expected %.8e, received %.8e.\n",
3576 angle[j], order, i, expected, out_temp[i]);
3583 static void test_D3DXSHScale(void)
3585 float a[49], b[49], expected, *received_array;
3586 unsigned int i, order;
3587 BOOL equal;
3589 for (i = 0; i < ARRAY_SIZE(a); ++i)
3591 a[i] = i;
3592 b[i] = i;
3595 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
3597 received_array = D3DXSHScale(b, order, a, 5.0f);
3598 ok(received_array == b, "Expected %p, received %p\n", b, received_array);
3600 for (i = 0; i < ARRAY_SIZE(b); ++i)
3602 if (i < order * order)
3603 expected = 5.0f * a[i];
3604 /* D3DXSHScale does not modify the elements of the array after the order * order-th element */
3605 else
3606 expected = a[i];
3607 equal = compare_float(b[i], expected, 0);
3608 ok(equal, "order %u, element %u, expected %.8e, received %.8e.\n", order, i, expected, b[i]);
3613 START_TEST(math)
3615 D3DXColorTest();
3616 D3DXFresnelTest();
3617 D3DXMatrixTest();
3618 D3DXPlaneTest();
3619 D3DXQuaternionTest();
3620 D3DXVector2Test();
3621 D3DXVector3Test();
3622 D3DXVector4Test();
3623 test_matrix_stack();
3624 test_Matrix_AffineTransformation2D();
3625 test_Matrix_Decompose();
3626 test_Matrix_Transformation2D();
3627 test_D3DXVec_Array();
3628 test_D3DXFloat_Array();
3629 test_D3DXSHAdd();
3630 test_D3DXSHDot();
3631 test_D3DXSHEvalConeLight();
3632 test_D3DXSHEvalDirection();
3633 test_D3DXSHEvalDirectionalLight();
3634 test_D3DXSHEvalHemisphereLight();
3635 test_D3DXSHEvalSphericalLight();
3636 test_D3DXSHMultiply2();
3637 test_D3DXSHMultiply3();
3638 test_D3DXSHMultiply4();
3639 test_D3DXSHRotate();
3640 test_D3DXSHRotateZ();
3641 test_D3DXSHScale();