TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / d3dx9_36 / tests / math.c
blobac4475ddb3c30186510ac0bfda611aabec46f55f
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 5
28 #define admitted_error 0.0001f
30 #define relative_error(exp, out) (fabsf(exp) < 1e-38f ? fabsf(exp - out) : fabsf(1.0f - (out) / (exp)))
32 #define expect_color(expectedcolor,gotcolor) ok((relative_error(expectedcolor.r, gotcolor.r)<admitted_error)&&(relative_error(expectedcolor.g, gotcolor.g)<admitted_error)&&(relative_error(expectedcolor.b, gotcolor.b)<admitted_error)&&(relative_error(expectedcolor.a, gotcolor.a)<admitted_error),"Expected Color= (%f, %f, %f, %f)\n , Got Color= (%f, %f, %f, %f)\n", expectedcolor.r, expectedcolor.g, expectedcolor.b, expectedcolor.a, gotcolor.r, gotcolor.g, gotcolor.b, gotcolor.a);
34 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
36 int i, j;
38 for (i = 0; i < 4; ++i)
40 for (j = 0; j < 4; ++j)
42 if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
43 return FALSE;
47 return TRUE;
50 #define expect_mat(expectedmat, gotmat) \
51 do { \
52 const D3DXMATRIX *__m1 = (expectedmat); \
53 const D3DXMATRIX *__m2 = (gotmat); \
54 ok(compare_matrix(__m1, __m2), "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \
55 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
56 U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
57 U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
58 U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
59 U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
60 U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
61 U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
62 U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
63 U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
64 } while(0)
66 #define compare_rotation(exp, got) \
67 ok(relative_error(exp.w, got.w) < admitted_error && \
68 relative_error(exp.x, got.x) < admitted_error && \
69 relative_error(exp.y, got.y) < admitted_error && \
70 relative_error(exp.z, got.z) < admitted_error, \
71 "Expected rotation = (%f, %f, %f, %f), \
72 got rotation = (%f, %f, %f, %f)\n", \
73 exp.w, exp.x, exp.y, exp.z, got.w, got.x, got.y, got.z)
75 #define compare_scale(exp, got) \
76 ok(relative_error(exp.x, got.x) < admitted_error && \
77 relative_error(exp.y, got.y) < admitted_error && \
78 relative_error(exp.z, got.z) < admitted_error, \
79 "Expected scale = (%f, %f, %f), \
80 got scale = (%f, %f, %f)\n", \
81 exp.x, exp.y, exp.z, got.x, got.y, got.z)
83 #define compare_translation(exp, got) \
84 ok(relative_error(exp.x, got.x) < admitted_error && \
85 relative_error(exp.y, got.y) < admitted_error && \
86 relative_error(exp.z, got.z) < admitted_error, \
87 "Expected translation = (%f, %f, %f), \
88 got translation = (%f, %f, %f)\n", \
89 exp.x, exp.y, exp.z, got.x, got.y, got.z)
91 #define compare_vectors(exp, out) \
92 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
93 ok(relative_error(exp[i].x, out[i].x) < admitted_error && \
94 relative_error(exp[i].y, out[i].y) < admitted_error && \
95 relative_error(exp[i].z, out[i].z) < admitted_error && \
96 relative_error(exp[i].w, out[i].w) < admitted_error, \
97 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
98 out[i].x, out[i].y, out[i].z, out[i].w, \
99 exp[i].x, exp[i].y, exp[i].z, exp[i].w, \
100 i); \
103 #define compare_planes(exp, out) \
104 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
105 ok(relative_error(exp[i].a, out[i].a) < admitted_error && \
106 relative_error(exp[i].b, out[i].b) < admitted_error && \
107 relative_error(exp[i].c, out[i].c) < admitted_error && \
108 relative_error(exp[i].d, out[i].d) < admitted_error, \
109 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
110 out[i].a, out[i].b, out[i].c, out[i].d, \
111 exp[i].a, exp[i].b, exp[i].c, exp[i].d, \
112 i); \
115 #define expect_plane(expectedplane,gotplane) ok((relative_error(expectedplane.a, gotplane.a)<admitted_error)&&(relative_error(expectedplane.b, gotplane.b)<admitted_error)&&(relative_error(expectedplane.c, gotplane.c)<admitted_error)&&(relative_error(expectedplane.d, gotplane.d)<admitted_error),"Expected Plane= (%f, %f, %f, %f)\n , Got Plane= (%f, %f, %f, %f)\n", expectedplane.a, expectedplane.b, expectedplane.c, expectedplane.d, gotplane.a, gotplane.b, gotplane.c, gotplane.d);
117 #define expect_vec(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
119 #define expect_vec3(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error)&&(relative_error(expectedvec.z, gotvec.z)<admitted_error),"Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x, gotvec.y, gotvec.z);
121 #define expect_vec4(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error)&&(relative_error(expectedvec.z, gotvec.z)<admitted_error)&&(relative_error(expectedvec.w, gotvec.w)<admitted_error),"Expected Vector= (%f, %f, %f, %f)\n , Got Vector= (%f, %f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, expectedvec.w, gotvec.x, gotvec.y, gotvec.z, gotvec.w);
124 static void D3DXColorTest(void)
126 D3DXCOLOR color, color1, color2, expected, got;
127 LPD3DXCOLOR funcpointer;
128 FLOAT scale;
130 color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
131 color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
132 color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
134 scale = 0.3f;
136 /*_______________D3DXColorAdd________________*/
137 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
138 D3DXColorAdd(&got,&color1,&color2);
139 expect_color(expected,got);
140 /* Test the NULL case */
141 funcpointer = D3DXColorAdd(&got,NULL,&color2);
142 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
143 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
144 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
145 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
146 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
148 /*_______________D3DXColorAdjustContrast______*/
149 expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
150 D3DXColorAdjustContrast(&got,&color,scale);
151 expect_color(expected,got);
153 /*_______________D3DXColorAdjustSaturation______*/
154 expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
155 D3DXColorAdjustSaturation(&got,&color,scale);
156 expect_color(expected,got);
158 /*_______________D3DXColorLerp________________*/
159 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
160 D3DXColorLerp(&got,&color,&color1,scale);
161 expect_color(expected,got);
162 /* Test the NULL case */
163 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
164 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
165 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
166 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
167 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
168 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
170 /*_______________D3DXColorModulate________________*/
171 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
172 D3DXColorModulate(&got,&color1,&color2);
173 expect_color(expected,got);
174 /* Test the NULL case */
175 funcpointer = D3DXColorModulate(&got,NULL,&color2);
176 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
177 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
178 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
179 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
180 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
182 /*_______________D3DXColorNegative________________*/
183 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
184 D3DXColorNegative(&got,&color);
185 expect_color(got,expected);
186 /* Test the greater than 1 case */
187 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
188 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
189 D3DXColorNegative(&got,&color1);
190 expect_color(got,expected);
191 /* Test the negative case */
192 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
193 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
194 D3DXColorNegative(&got,&color1);
195 expect_color(got,expected);
196 /* Test the NULL case */
197 funcpointer = D3DXColorNegative(&got,NULL);
198 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
199 funcpointer = D3DXColorNegative(NULL,NULL);
200 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
202 /*_______________D3DXColorScale________________*/
203 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
204 D3DXColorScale(&got,&color,scale);
205 expect_color(expected,got);
206 /* Test the NULL case */
207 funcpointer = D3DXColorScale(&got,NULL,scale);
208 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
209 funcpointer = D3DXColorScale(NULL,NULL,scale);
210 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
212 /*_______________D3DXColorSubtract_______________*/
213 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
214 D3DXColorSubtract(&got,&color,&color2);
215 expect_color(expected,got);
216 /* Test the NULL case */
217 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
218 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
219 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
220 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
221 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
222 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
225 static void D3DXFresnelTest(void)
227 FLOAT expected, got;
229 expected = 0.089187;
230 got = D3DXFresnelTerm(0.5f,1.5);
231 ok(relative_error(got, expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
234 static void D3DXMatrixTest(void)
236 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
237 D3DXMATRIX *funcpointer;
238 D3DXPLANE plane;
239 D3DXQUATERNION q, r;
240 D3DXVECTOR3 at, axis, eye, last;
241 D3DXVECTOR4 light;
242 BOOL expected, got;
243 FLOAT angle, determinant, expectedfloat, gotfloat;
245 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
246 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
247 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
248 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
249 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
250 U(mat).m[3][3] = -40.0f;
252 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
253 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
254 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
255 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
256 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
257 U(mat2).m[3][3] = -1.0f;
259 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
261 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
262 r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
264 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
265 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
266 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
267 last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
269 light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
271 angle = D3DX_PI/3.0f;
273 /*____________D3DXMatrixAffineTransformation______*/
274 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;
275 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;
276 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;
277 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;
278 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, &axis);
279 expect_mat(&expectedmat, &gotmat);
281 /* Test the NULL case */
282 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;
283 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, &axis);
284 expect_mat(&expectedmat, &gotmat);
286 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;
287 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, &q, NULL);
288 expect_mat(&expectedmat, &gotmat);
290 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;
291 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, &q, NULL);
292 expect_mat(&expectedmat, &gotmat);
294 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;
295 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;
296 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;
297 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;
298 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, &axis);
299 expect_mat(&expectedmat, &gotmat);
301 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, &axis);
302 expect_mat(&expectedmat, &gotmat);
304 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;
305 D3DXMatrixAffineTransformation(&gotmat, 3.56f, &at, NULL, NULL);
306 expect_mat(&expectedmat, &gotmat);
308 D3DXMatrixAffineTransformation(&gotmat, 3.56f, NULL, NULL, NULL);
309 expect_mat(&expectedmat, &gotmat);
311 /*____________D3DXMatrixfDeterminant_____________*/
312 expectedfloat = -147888.0f;
313 gotfloat = D3DXMatrixDeterminant(&mat);
314 ok(relative_error(gotfloat, expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
316 /*____________D3DXMatrixInverse______________*/
317 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;
318 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;
319 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;
320 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;
321 expectedfloat = -147888.0f;
322 D3DXMatrixInverse(&gotmat,&determinant,&mat);
323 expect_mat(&expectedmat, &gotmat);
324 ok(relative_error( determinant, expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
325 funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
326 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
328 /*____________D3DXMatrixIsIdentity______________*/
329 expected = FALSE;
330 memset(&mat3, 0, sizeof(mat3));
331 got = D3DXMatrixIsIdentity(&mat3);
332 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
333 D3DXMatrixIdentity(&mat3);
334 expected = TRUE;
335 got = D3DXMatrixIsIdentity(&mat3);
336 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
337 U(mat3).m[0][0] = 0.000009f;
338 expected = FALSE;
339 got = D3DXMatrixIsIdentity(&mat3);
340 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
341 /* Test the NULL case */
342 expected = FALSE;
343 got = D3DXMatrixIsIdentity(NULL);
344 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
346 /*____________D3DXMatrixLookatLH_______________*/
347 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;
348 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;
349 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;
350 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;
351 D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
352 expect_mat(&expectedmat, &gotmat);
354 /*____________D3DXMatrixLookatRH_______________*/
355 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;
356 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;
357 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;
358 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;
359 D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
360 expect_mat(&expectedmat, &gotmat);
362 /*____________D3DXMatrixMultiply______________*/
363 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;
364 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;
365 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;
366 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;
367 D3DXMatrixMultiply(&gotmat,&mat,&mat2);
368 expect_mat(&expectedmat, &gotmat);
370 /*____________D3DXMatrixMultiplyTranspose____*/
371 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;
372 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;
373 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;
374 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;
375 D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
376 expect_mat(&expectedmat, &gotmat);
378 /*____________D3DXMatrixOrthoLH_______________*/
379 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;
380 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;
381 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;
382 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;
383 D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
384 expect_mat(&expectedmat, &gotmat);
386 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
387 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;
388 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;
389 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;
390 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;
391 D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
392 expect_mat(&expectedmat, &gotmat);
394 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
395 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;
396 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;
397 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;
398 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;
399 D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
400 expect_mat(&expectedmat, &gotmat);
402 /*____________D3DXMatrixOrthoRH_______________*/
403 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;
404 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;
405 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;
406 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;
407 D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
408 expect_mat(&expectedmat, &gotmat);
410 /*____________D3DXMatrixPerspectiveFovLH_______________*/
411 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;
412 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;
413 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;
414 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;
415 D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
416 expect_mat(&expectedmat, &gotmat);
418 /*____________D3DXMatrixPerspectiveFovRH_______________*/
419 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;
420 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;
421 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;
422 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;
423 D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
424 expect_mat(&expectedmat, &gotmat);
426 /*____________D3DXMatrixPerspectiveLH_______________*/
427 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;
428 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;
429 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;
430 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;
431 D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
432 expect_mat(&expectedmat, &gotmat);
434 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
435 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;
436 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;
437 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;
438 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;
439 D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
440 expect_mat(&expectedmat, &gotmat);
442 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
443 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;
444 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;
445 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;
446 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;
447 D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
448 expect_mat(&expectedmat, &gotmat);
450 /*____________D3DXMatrixPerspectiveRH_______________*/
451 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;
452 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;
453 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;
454 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;
455 D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
456 expect_mat(&expectedmat, &gotmat);
458 /*____________D3DXMatrixReflect______________*/
459 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;
460 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;
461 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;
462 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;
463 D3DXMatrixReflect(&gotmat,&plane);
464 expect_mat(&expectedmat, &gotmat);
466 /*____________D3DXMatrixRotationAxis_____*/
467 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;
468 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;
469 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;
470 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;
471 D3DXMatrixRotationAxis(&gotmat,&axis,angle);
472 expect_mat(&expectedmat, &gotmat);
474 /*____________D3DXMatrixRotationQuaternion______________*/
475 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;
476 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;
477 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;
478 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;
479 D3DXMatrixRotationQuaternion(&gotmat,&q);
480 expect_mat(&expectedmat, &gotmat);
482 /*____________D3DXMatrixRotationX______________*/
483 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;
484 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;
485 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;
486 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;
487 D3DXMatrixRotationX(&gotmat,angle);
488 expect_mat(&expectedmat, &gotmat);
490 /*____________D3DXMatrixRotationY______________*/
491 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;
492 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;
493 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;
494 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;
495 D3DXMatrixRotationY(&gotmat,angle);
496 expect_mat(&expectedmat, &gotmat);
498 /*____________D3DXMatrixRotationYawPitchRoll____*/
499 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;
500 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;
501 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;
502 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;
503 D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
504 expect_mat(&expectedmat, &gotmat);
506 /*____________D3DXMatrixRotationZ______________*/
507 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;
508 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;
509 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;
510 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;
511 D3DXMatrixRotationZ(&gotmat,angle);
512 expect_mat(&expectedmat, &gotmat);
514 /*____________D3DXMatrixScaling______________*/
515 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;
516 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;
517 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;
518 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;
519 D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
520 expect_mat(&expectedmat, &gotmat);
522 /*____________D3DXMatrixShadow______________*/
523 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;
524 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;
525 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;
526 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;
527 D3DXMatrixShadow(&gotmat,&light,&plane);
528 expect_mat(&expectedmat, &gotmat);
530 /*____________D3DXMatrixTransformation______________*/
531 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;
532 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;
533 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;
534 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;
535 D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
536 expect_mat(&expectedmat, &gotmat);
538 /*____________D3DXMatrixTranslation______________*/
539 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;
540 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;
541 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;
542 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;
543 D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
544 expect_mat(&expectedmat, &gotmat);
546 /*____________D3DXMatrixTranspose______________*/
547 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;
548 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;
549 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;
550 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;
551 D3DXMatrixTranspose(&gotmat,&mat);
552 expect_mat(&expectedmat, &gotmat);
555 static void D3DXPlaneTest(void)
557 D3DXMATRIX mat;
558 D3DXPLANE expectedplane, gotplane, nulplane, plane;
559 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
560 LPD3DXVECTOR3 funcpointer;
561 D3DXVECTOR4 vec;
562 FLOAT expected, got;
564 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
565 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
566 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
567 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
568 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
569 U(mat).m[3][3] = -40.0f;
571 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
573 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
575 /*_______________D3DXPlaneDot________________*/
576 expected = 42.0f;
577 got = D3DXPlaneDot(&plane,&vec),
578 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
579 expected = 0.0f;
580 got = D3DXPlaneDot(NULL,&vec),
581 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
582 expected = 0.0f;
583 got = D3DXPlaneDot(NULL,NULL),
584 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
586 /*_______________D3DXPlaneDotCoord________________*/
587 expected = -28.0f;
588 got = D3DXPlaneDotCoord(&plane,&vec),
589 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
590 expected = 0.0f;
591 got = D3DXPlaneDotCoord(NULL,&vec),
592 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
593 expected = 0.0f;
594 got = D3DXPlaneDotCoord(NULL,NULL),
595 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
597 /*_______________D3DXPlaneDotNormal______________*/
598 expected = -35.0f;
599 got = D3DXPlaneDotNormal(&plane,&vec),
600 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
601 expected = 0.0f;
602 got = D3DXPlaneDotNormal(NULL,&vec),
603 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
604 expected = 0.0f;
605 got = D3DXPlaneDotNormal(NULL,NULL),
606 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
608 /*_______________D3DXPlaneFromPointNormal_______*/
609 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
610 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
611 expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
612 D3DXPlaneFromPointNormal(&gotplane,&vec1,&vec2);
613 expect_plane(expectedplane, gotplane);
615 /*_______________D3DXPlaneFromPoints_______*/
616 vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
617 vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
618 vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
619 expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
620 D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
621 expect_plane(expectedplane, gotplane);
623 /*_______________D3DXPlaneIntersectLine___________*/
624 vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
625 vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
626 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
627 D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
628 expect_vec3(expectedvec, gotvec);
629 /* Test a parallel line */
630 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
631 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
632 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
633 funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
634 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
636 /*_______________D3DXPlaneNormalize______________*/
637 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);
638 D3DXPlaneNormalize(&gotplane, &plane);
639 expect_plane(expectedplane, gotplane);
640 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
641 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
642 D3DXPlaneNormalize(&gotplane, &nulplane);
643 expect_plane(expectedplane, gotplane);
645 /*_______________D3DXPlaneTransform____________*/
646 expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
647 D3DXPlaneTransform(&gotplane,&plane,&mat);
648 expect_plane(expectedplane, gotplane);
651 static void D3DXQuaternionTest(void)
653 D3DXMATRIX mat;
654 D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
655 LPD3DXQUATERNION funcpointer;
656 D3DXVECTOR3 axis, expectedvec;
657 FLOAT angle, expected, got, scale, scale2;
658 BOOL expectedbool, gotbool;
660 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
661 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
662 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
663 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
664 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
665 smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
666 smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallr.w = 0.8f;
668 scale = 0.3f;
669 scale2 = 0.78f;
671 /*_______________D3DXQuaternionBaryCentric________________________*/
672 expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
673 D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
674 expect_vec4(expectedquat,gotquat);
676 /*_______________D3DXQuaternionConjugate________________*/
677 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
678 D3DXQuaternionConjugate(&gotquat,&q);
679 expect_vec4(expectedquat,gotquat);
680 /* Test the NULL case */
681 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
682 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
683 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
684 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
686 /*_______________D3DXQuaternionDot______________________*/
687 expected = 55.0f;
688 got = D3DXQuaternionDot(&q,&r);
689 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
690 /* Tests the case NULL */
691 expected=0.0f;
692 got = D3DXQuaternionDot(NULL,&r);
693 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
694 expected=0.0f;
695 got = D3DXQuaternionDot(NULL,NULL);
696 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
698 /*_______________D3DXQuaternionExp______________________________*/
699 expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
700 D3DXQuaternionExp(&gotquat,&q);
701 expect_vec4(expectedquat,gotquat);
702 /* Test the null quaternion */
703 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
704 D3DXQuaternionExp(&gotquat,&nul);
705 expect_vec4(expectedquat,gotquat);
706 /* Test the case where the norm of the quaternion is <1 */
707 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
708 expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
709 D3DXQuaternionExp(&gotquat,&Nq1);
710 expect_vec4(expectedquat,gotquat);
712 /*_______________D3DXQuaternionIdentity________________*/
713 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
714 D3DXQuaternionIdentity(&gotquat);
715 expect_vec4(expectedquat,gotquat);
716 /* Test the NULL case */
717 funcpointer = D3DXQuaternionIdentity(NULL);
718 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
720 /*_______________D3DXQuaternionInverse________________________*/
721 expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
722 D3DXQuaternionInverse(&gotquat,&q);
723 expect_vec4(expectedquat,gotquat);
725 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 10.0f;
726 D3DXQuaternionInverse(&gotquat,&gotquat);
727 expect_vec4(expectedquat,gotquat);
730 /*_______________D3DXQuaternionIsIdentity________________*/
731 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
732 expectedbool = TRUE;
733 gotbool = D3DXQuaternionIsIdentity(&s);
734 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
735 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
736 expectedbool = FALSE;
737 gotbool = D3DXQuaternionIsIdentity(&q);
738 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
739 /* Test the NULL case */
740 gotbool = D3DXQuaternionIsIdentity(NULL);
741 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
743 /*_______________D3DXQuaternionLength__________________________*/
744 expected = 11.0f;
745 got = D3DXQuaternionLength(&q);
746 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
747 /* Tests the case NULL */
748 expected=0.0f;
749 got = D3DXQuaternionLength(NULL);
750 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
752 /*_______________D3DXQuaternionLengthSq________________________*/
753 expected = 121.0f;
754 got = D3DXQuaternionLengthSq(&q);
755 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
756 /* Tests the case NULL */
757 expected=0.0f;
758 got = D3DXQuaternionLengthSq(NULL);
759 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
761 /*_______________D3DXQuaternionLn______________________________*/
762 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
763 D3DXQuaternionLn(&gotquat,&q);
764 expect_vec4(expectedquat,gotquat);
765 expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
766 D3DXQuaternionLn(&gotquat,&r);
767 expect_vec4(expectedquat,gotquat);
768 Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
769 expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
770 D3DXQuaternionLn(&gotquat,&Nq);
771 expect_vec4(expectedquat,gotquat);
772 Nq.x = 0.0f; Nq.y = 0.0f; Nq.z = 0.0f; Nq.w = 1.0f;
773 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
774 D3DXQuaternionLn(&gotquat,&Nq);
775 expect_vec4(expectedquat,gotquat);
776 Nq.x = 5.4f; Nq.y = 1.2f; Nq.z = -0.3f; Nq.w = -0.3f;
777 expectedquat.x = 10.616652f; expectedquat.y = 2.359256f; expectedquat.z = -0.589814f; expectedquat.w = 0.0f;
778 D3DXQuaternionLn(&gotquat,&Nq);
779 expect_vec4(expectedquat,gotquat);
780 /* Test the case where the norm of the quaternion is <1 */
781 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = 0.9f;
782 expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
783 D3DXQuaternionLn(&gotquat,&Nq1);
784 expect_vec4(expectedquat,gotquat);
785 /* Test the case where the real part of the quaternion is -1.0f */
786 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = -1.0f;
787 expectedquat.x = 0.2f; expectedquat.y = 0.1f; expectedquat.z = 0.3f; expectedquat.w = 0.0f;
788 D3DXQuaternionLn(&gotquat,&Nq1);
789 expect_vec4(expectedquat,gotquat);
791 /*_______________D3DXQuaternionMultiply________________________*/
792 expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
793 D3DXQuaternionMultiply(&gotquat,&q,&r);
794 expect_vec4(expectedquat,gotquat);
796 /*_______________D3DXQuaternionNormalize________________________*/
797 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
798 D3DXQuaternionNormalize(&gotquat,&q);
799 expect_vec4(expectedquat,gotquat);
801 /*_______________D3DXQuaternionRotationAxis___________________*/
802 axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
803 angle = D3DX_PI/3.0f;
804 expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
805 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
806 expect_vec4(expectedquat,gotquat);
807 /* Test the nul quaternion */
808 axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
809 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
810 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
811 expect_vec4(expectedquat,gotquat);
813 /*_______________D3DXQuaternionRotationMatrix___________________*/
814 /* test when the trace is >0 */
815 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
816 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
817 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
818 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
819 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
820 U(mat).m[3][3] = 48.0f;
821 expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
822 D3DXQuaternionRotationMatrix(&gotquat,&mat);
823 expect_vec4(expectedquat,gotquat);
824 /* test the case when the greater element is (2,2) */
825 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
826 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
827 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
828 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
829 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
830 U(mat).m[3][3] = 48.0f;
831 expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
832 D3DXQuaternionRotationMatrix(&gotquat,&mat);
833 expect_vec4(expectedquat,gotquat);
834 /* test the case when the greater element is (1,1) */
835 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
836 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
837 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
838 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
839 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
840 U(mat).m[3][3] = 48.0f;
841 expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
842 D3DXQuaternionRotationMatrix(&gotquat,&mat);
843 expect_vec4(expectedquat,gotquat);
844 /* test the case when the trace is near 0 in a matrix which is not a rotation */
845 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
846 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
847 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
848 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
849 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
850 U(mat).m[3][3] = 48.0f;
851 expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
852 D3DXQuaternionRotationMatrix(&gotquat,&mat);
853 expect_vec4(expectedquat,gotquat);
854 /* test the case when the trace is 0.49 in a matrix which is not a rotation */
855 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
856 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
857 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
858 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
859 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
860 U(mat).m[3][3] = 48.0f;
861 expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
862 D3DXQuaternionRotationMatrix(&gotquat,&mat);
863 expect_vec4(expectedquat,gotquat);
864 /* test the case when the trace is 0.51 in a matrix which is not a rotation */
865 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
866 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
867 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
868 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
869 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
870 U(mat).m[3][3] = 48.0f;
871 expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
872 D3DXQuaternionRotationMatrix(&gotquat,&mat);
873 expect_vec4(expectedquat,gotquat);
874 /* test the case when the trace is 0.99 in a matrix which is not a rotation */
875 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
876 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
877 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
878 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
879 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
880 U(mat).m[3][3] = 48.0f;
881 expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
882 D3DXQuaternionRotationMatrix(&gotquat,&mat);
883 expect_vec4(expectedquat,gotquat);
884 /* test the case when the trace is 1.0 in a matrix which is not a rotation */
885 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
886 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
887 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
888 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
889 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
890 U(mat).m[3][3] = 48.0f;
891 expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
892 D3DXQuaternionRotationMatrix(&gotquat,&mat);
893 expect_vec4(expectedquat,gotquat);
894 /* test the case when the trace is 1.01 in a matrix which is not a rotation */
895 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
896 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
897 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
898 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
899 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
900 U(mat).m[3][3] = 48.0f;
901 expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
902 D3DXQuaternionRotationMatrix(&gotquat,&mat);
903 expect_vec4(expectedquat,gotquat);
904 /* test the case when the trace is 1.5 in a matrix which is not a rotation */
905 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
906 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
907 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
908 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
909 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
910 U(mat).m[3][3] = 48.0f;
911 expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
912 D3DXQuaternionRotationMatrix(&gotquat,&mat);
913 expect_vec4(expectedquat,gotquat);
914 /* test the case when the trace is 1.7 in a matrix which is not a rotation */
915 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
916 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
917 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
918 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
919 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
920 U(mat).m[3][3] = 48.0f;
921 expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
922 D3DXQuaternionRotationMatrix(&gotquat,&mat);
923 expect_vec4(expectedquat,gotquat);
924 /* test the case when the trace is 1.99 in a matrix which is not a rotation */
925 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
926 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
927 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
928 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
929 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
930 U(mat).m[3][3] = 48.0f;
931 expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
932 D3DXQuaternionRotationMatrix(&gotquat,&mat);
933 expect_vec4(expectedquat,gotquat);
934 /* test the case when the trace is 2.0 in a matrix which is not a rotation */
935 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
936 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
937 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
938 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
939 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
940 U(mat).m[3][3] = 48.0f;
941 expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
942 D3DXQuaternionRotationMatrix(&gotquat,&mat);
943 expect_vec4(expectedquat,gotquat);
945 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
946 expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
947 D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
948 expect_vec4(expectedquat,gotquat);
950 /*_______________D3DXQuaternionSlerp________________________*/
951 expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
952 D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
953 expect_vec4(expectedquat,gotquat);
954 expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
955 D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
956 expect_vec4(expectedquat,gotquat);
957 expectedquat.x = 0.239485f; expectedquat.y = 0.346580f; expectedquat.z = 0.453676f; expectedquat.w = 0.560772f;
958 D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
959 expect_vec4(expectedquat,gotquat);
961 /*_______________D3DXQuaternionSquad________________________*/
962 expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
963 D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
964 expect_vec4(expectedquat,gotquat);
966 /*_______________D3DXQuaternionSquadSetup___________________*/
967 r.x = 1.0f, r.y = 2.0f; r.z = 4.0f; r.w = 10.0f;
968 s.x = -3.0f; s.y = 4.0f; s.z = -5.0f; s.w = 7.0;
969 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
970 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
971 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
972 expectedquat.x = 7.121285f; expectedquat.y = 2.159964f; expectedquat.z = -3.855094f; expectedquat.w = 5.362844f;
973 expect_vec4(expectedquat,gotquat);
974 expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
975 expect_vec4(expectedquat,Nq);
976 expectedquat.x = -1111.0f; expectedquat.y = 111.0f; expectedquat.z = -11.0f; expectedquat.w = 1.0f;
977 expect_vec4(expectedquat,Nq1);
978 r.x = 0.2f; r.y = 0.3f; r.z = 1.3f; r.w = -0.6f;
979 s.x = -3.0f; s.y =-2.0f; s.z = 4.0f; s.w = 0.2f;
980 t.x = 0.4f; t.y = 8.3f; t.z = -3.1f; t.w = -2.7f;
981 u.x = 1.1f; u.y = -0.7f; u.z = 9.2f; u.w = 0.0f;
982 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&u,&t);
983 expectedquat.x = -4.139569f; expectedquat.y = -2.469115f; expectedquat.z = 2.364477f; expectedquat.w = 0.465494f;
984 expect_vec4(expectedquat,gotquat);
985 expectedquat.x = 2.342533f; expectedquat.y = 2.365127f; expectedquat.z = 8.628538f; expectedquat.w = -0.898356f;
986 expect_vec4(expectedquat,Nq);
987 expectedquat.x = 1.1f; expectedquat.y = -0.7f; expectedquat.z = 9.2f; expectedquat.w = 0.0f;
988 expect_vec4(expectedquat,Nq1);
989 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
990 expectedquat.x = -3.754567f; expectedquat.y = -0.586085f; expectedquat.z = 3.815818f; expectedquat.w = -0.198150f;
991 expect_vec4(expectedquat,gotquat);
992 expectedquat.x = 0.140773f; expectedquat.y = -8.737090f; expectedquat.z = -0.516593f; expectedquat.w = 3.053942f;
993 expect_vec4(expectedquat,Nq);
994 expectedquat.x = -0.4f; expectedquat.y = -8.3f; expectedquat.z = 3.1f; expectedquat.w = 2.7f;
995 expect_vec4(expectedquat,Nq1);
996 r.x = -1.0f; r.y = 0.0f; r.z = 0.0f; r.w = 0.0f;
997 s.x = 1.0f; s.y =0.0f; s.z = 0.0f; s.w = 0.0f;
998 t.x = 1.0f; t.y = 0.0f; t.z = 0.0f; t.w = 0.0f;
999 u.x = -1.0f; u.y = 0.0f; u.z = 0.0f; u.w = 0.0f;
1000 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
1001 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1002 expect_vec4(expectedquat,gotquat);
1003 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1004 expect_vec4(expectedquat,Nq);
1005 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
1006 expect_vec4(expectedquat,Nq1);
1008 /*_______________D3DXQuaternionToAxisAngle__________________*/
1009 Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
1010 expectedvec.x = 1.0f/22.0f; expectedvec.y = 2.0f/22.0f; expectedvec.z = 4.0f/22.0f;
1011 expected = 2.197869f;
1012 D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
1013 expect_vec3(expectedvec,axis);
1014 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
1015 /* Test if |w|>1.0f */
1016 expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f;
1017 D3DXQuaternionToAxisAngle(&q,&axis,&angle);
1018 expect_vec3(expectedvec,axis);
1019 /* Test the null quaternion */
1020 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1021 expected = 3.141593f;
1022 D3DXQuaternionToAxisAngle(&nul,&axis,&angle);
1023 expect_vec3(expectedvec,axis);
1024 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
1027 static void D3DXVector2Test(void)
1029 D3DXVECTOR2 expectedvec, gotvec, nul, u, v, w, x;
1030 LPD3DXVECTOR2 funcpointer;
1031 D3DXVECTOR4 expectedtrans, gottrans;
1032 D3DXMATRIX mat;
1033 FLOAT coeff1, coeff2, expected, got, scale;
1035 nul.x = 0.0f; nul.y = 0.0f;
1036 u.x = 3.0f; u.y = 4.0f;
1037 v.x = -7.0f; v.y = 9.0f;
1038 w.x = 4.0f; w.y = -3.0f;
1039 x.x = 2.0f; x.y = -11.0f;
1041 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;
1042 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;
1043 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;
1044 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;
1046 coeff1 = 2.0f; coeff2 = 5.0f;
1047 scale = -6.5f;
1049 /*_______________D3DXVec2Add__________________________*/
1050 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
1051 D3DXVec2Add(&gotvec,&u,&v);
1052 expect_vec(expectedvec,gotvec);
1053 /* Tests the case NULL */
1054 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
1055 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1056 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
1057 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1059 /*_______________D3DXVec2BaryCentric___________________*/
1060 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
1061 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1062 expect_vec(expectedvec,gotvec);
1064 /*_______________D3DXVec2CatmullRom____________________*/
1065 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
1066 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1067 expect_vec(expectedvec,gotvec);
1069 /*_______________D3DXVec2CCW__________________________*/
1070 expected = 55.0f;
1071 got = D3DXVec2CCW(&u,&v);
1072 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1073 /* Tests the case NULL */
1074 expected=0.0f;
1075 got = D3DXVec2CCW(NULL,&v);
1076 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1077 expected=0.0f;
1078 got = D3DXVec2CCW(NULL,NULL);
1079 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1081 /*_______________D3DXVec2Dot__________________________*/
1082 expected = 15.0f;
1083 got = D3DXVec2Dot(&u,&v);
1084 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1085 /* Tests the case NULL */
1086 expected=0.0f;
1087 got = D3DXVec2Dot(NULL,&v);
1088 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1089 expected=0.0f;
1090 got = D3DXVec2Dot(NULL,NULL);
1091 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1093 /*_______________D3DXVec2Hermite__________________________*/
1094 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
1095 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
1096 expect_vec(expectedvec,gotvec);
1098 /*_______________D3DXVec2Length__________________________*/
1099 expected = 5.0f;
1100 got = D3DXVec2Length(&u);
1101 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1102 /* Tests the case NULL */
1103 expected=0.0f;
1104 got = D3DXVec2Length(NULL);
1105 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1107 /*_______________D3DXVec2LengthSq________________________*/
1108 expected = 25.0f;
1109 got = D3DXVec2LengthSq(&u);
1110 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1111 /* Tests the case NULL */
1112 expected=0.0f;
1113 got = D3DXVec2LengthSq(NULL);
1114 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1116 /*_______________D3DXVec2Lerp__________________________*/
1117 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
1118 D3DXVec2Lerp(&gotvec,&u,&v,scale);
1119 expect_vec(expectedvec,gotvec);
1120 /* Tests the case NULL */
1121 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
1122 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1123 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1124 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1126 /*_______________D3DXVec2Maximize__________________________*/
1127 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1128 D3DXVec2Maximize(&gotvec,&u,&v);
1129 expect_vec(expectedvec,gotvec);
1130 /* Tests the case NULL */
1131 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1132 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1133 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1134 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1136 /*_______________D3DXVec2Minimize__________________________*/
1137 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1138 D3DXVec2Minimize(&gotvec,&u,&v);
1139 expect_vec(expectedvec,gotvec);
1140 /* Tests the case NULL */
1141 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1142 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1143 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1144 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1146 /*_______________D3DXVec2Normalize_________________________*/
1147 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1148 D3DXVec2Normalize(&gotvec,&u);
1149 expect_vec(expectedvec,gotvec);
1150 /* Test the nul vector */
1151 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1152 D3DXVec2Normalize(&gotvec,&nul);
1153 expect_vec(expectedvec,gotvec);
1155 /*_______________D3DXVec2Scale____________________________*/
1156 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1157 D3DXVec2Scale(&gotvec,&u,scale);
1158 expect_vec(expectedvec,gotvec);
1159 /* Tests the case NULL */
1160 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
1161 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1162 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
1163 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1165 /*_______________D3DXVec2Subtract__________________________*/
1166 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
1167 D3DXVec2Subtract(&gotvec,&u,&v);
1168 expect_vec(expectedvec,gotvec);
1169 /* Tests the case NULL */
1170 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
1171 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1172 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
1173 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1175 /*_______________D3DXVec2Transform_______________________*/
1176 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
1177 D3DXVec2Transform(&gottrans,&u,&mat);
1178 expect_vec4(expectedtrans,gottrans);
1180 /*_______________D3DXVec2TransformCoord_______________________*/
1181 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
1182 D3DXVec2TransformCoord(&gotvec,&u,&mat);
1183 expect_vec(expectedvec,gotvec);
1185 /*_______________D3DXVec2TransformNormal______________________*/
1186 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1187 D3DXVec2TransformNormal(&gotvec,&u,&mat);
1188 expect_vec(expectedvec,gotvec);
1191 static void D3DXVector3Test(void)
1193 D3DVIEWPORT9 viewport;
1194 D3DXVECTOR3 expectedvec, gotvec, nul, u, v, w, x;
1195 LPD3DXVECTOR3 funcpointer;
1196 D3DXVECTOR4 expectedtrans, gottrans;
1197 D3DXMATRIX mat, projection, view, world;
1198 FLOAT coeff1, coeff2, expected, got, scale;
1200 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
1201 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
1202 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
1203 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
1204 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
1206 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1207 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
1209 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;
1210 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;
1211 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;
1212 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;
1214 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
1215 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
1216 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
1217 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
1218 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
1219 U(view).m[3][3] = -40.0f;
1221 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;
1222 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;
1223 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;
1224 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;
1226 coeff1 = 2.0f; coeff2 = 5.0f;
1227 scale = -6.5f;
1229 /*_______________D3DXVec3Add__________________________*/
1230 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
1231 D3DXVec3Add(&gotvec,&u,&v);
1232 expect_vec3(expectedvec,gotvec);
1233 /* Tests the case NULL */
1234 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
1235 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1236 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
1237 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1239 /*_______________D3DXVec3BaryCentric___________________*/
1240 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1241 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1243 expect_vec3(expectedvec,gotvec);
1245 /*_______________D3DXVec3CatmullRom____________________*/
1246 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
1247 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1248 expect_vec3(expectedvec,gotvec);
1250 /*_______________D3DXVec3Cross________________________*/
1251 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
1252 D3DXVec3Cross(&gotvec,&u,&v);
1253 expect_vec3(expectedvec,gotvec);
1254 expectedvec.x = -277.0f; expectedvec.y = -150.0f; expectedvec.z = -26.0f;
1255 D3DXVec3Cross(&gotvec,&gotvec,&v);
1256 expect_vec3(expectedvec,gotvec);
1257 /* Tests the case NULL */
1258 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
1259 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1260 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
1261 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1263 /*_______________D3DXVec3Dot__________________________*/
1264 expected = -8.0f;
1265 got = D3DXVec3Dot(&u,&v);
1266 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1267 /* Tests the case NULL */
1268 expected=0.0f;
1269 got = D3DXVec3Dot(NULL,&v);
1270 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1271 expected=0.0f;
1272 got = D3DXVec3Dot(NULL,NULL);
1273 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1275 /*_______________D3DXVec3Hermite__________________________*/
1276 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
1277 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
1278 expect_vec3(expectedvec,gotvec);
1280 /*_______________D3DXVec3Length__________________________*/
1281 expected = 11.0f;
1282 got = D3DXVec3Length(&u);
1283 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1284 /* Tests the case NULL */
1285 expected=0.0f;
1286 got = D3DXVec3Length(NULL);
1287 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1289 /*_______________D3DXVec3LengthSq________________________*/
1290 expected = 121.0f;
1291 got = D3DXVec3LengthSq(&u);
1292 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1293 /* Tests the case NULL */
1294 expected=0.0f;
1295 got = D3DXVec3LengthSq(NULL);
1296 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1298 /*_______________D3DXVec3Lerp__________________________*/
1299 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
1300 D3DXVec3Lerp(&gotvec,&u,&v,scale);
1301 expect_vec3(expectedvec,gotvec);
1302 /* Tests the case NULL */
1303 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
1304 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1305 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
1306 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1308 /*_______________D3DXVec3Maximize__________________________*/
1309 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
1310 D3DXVec3Maximize(&gotvec,&u,&v);
1311 expect_vec3(expectedvec,gotvec);
1312 /* Tests the case NULL */
1313 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
1314 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1315 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
1316 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1318 /*_______________D3DXVec3Minimize__________________________*/
1319 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
1320 D3DXVec3Minimize(&gotvec,&u,&v);
1321 expect_vec3(expectedvec,gotvec);
1322 /* Tests the case NULL */
1323 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
1324 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1325 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
1326 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1328 /*_______________D3DXVec3Normalize_________________________*/
1329 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
1330 D3DXVec3Normalize(&gotvec,&u);
1331 expect_vec3(expectedvec,gotvec);
1332 /* Test the nul vector */
1333 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1334 D3DXVec3Normalize(&gotvec,&nul);
1335 expect_vec3(expectedvec,gotvec);
1337 /*_______________D3DXVec3Scale____________________________*/
1338 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
1339 D3DXVec3Scale(&gotvec,&u,scale);
1340 expect_vec3(expectedvec,gotvec);
1341 /* Tests the case NULL */
1342 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
1343 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1344 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
1345 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1347 /*_______________D3DXVec3Subtract_______________________*/
1348 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1349 D3DXVec3Subtract(&gotvec,&u,&v);
1350 expect_vec3(expectedvec,gotvec);
1351 /* Tests the case NULL */
1352 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1353 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1354 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1355 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1357 /*_______________D3DXVec3Transform_______________________*/
1358 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1359 D3DXVec3Transform(&gottrans,&u,&mat);
1360 expect_vec4(expectedtrans,gottrans);
1362 /*_______________D3DXVec3TransformCoord_______________________*/
1363 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1364 D3DXVec3TransformCoord(&gotvec,&u,&mat);
1365 expect_vec3(expectedvec,gotvec);
1367 /*_______________D3DXVec3TransformNormal______________________*/
1368 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1369 D3DXVec3TransformNormal(&gotvec,&u,&mat);
1370 expect_vec3(expectedvec,gotvec);
1372 /*_______________D3DXVec3Project_________________________*/
1373 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
1374 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1375 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
1376 expect_vec3(expectedvec,gotvec);
1377 /* World matrix can be omitted */
1378 D3DXMatrixMultiply(&mat,&world,&view);
1379 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&mat,NULL);
1380 expect_vec3(expectedvec,gotvec);
1381 /* Projection matrix can be omitted */
1382 D3DXMatrixMultiply(&mat,&view,&projection);
1383 D3DXVec3Project(&gotvec,&u,&viewport,NULL,&mat,&world);
1384 expect_vec3(expectedvec,gotvec);
1385 /* View matrix can be omitted */
1386 D3DXMatrixMultiply(&mat,&world,&view);
1387 D3DXVec3Project(&gotvec,&u,&viewport,&projection,NULL,&mat);
1388 expect_vec3(expectedvec,gotvec);
1389 /* All matrices can be omitted */
1390 expectedvec.x = 4010.000000f; expectedvec.y = -1695.000000f; expectedvec.z = 1.600000f;
1391 D3DXVec3Project(&gotvec,&u,&viewport,NULL,NULL,NULL);
1392 expect_vec3(expectedvec,gotvec);
1393 /* Viewport can be omitted */
1394 expectedvec.x = 1.814305f; expectedvec.y = 0.582097f; expectedvec.z = -0.066555f;
1395 D3DXVec3Project(&gotvec,&u,NULL,&projection,&view,&world);
1396 expect_vec3(expectedvec,gotvec);
1398 /*_______________D3DXVec3Unproject_________________________*/
1399 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1400 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1401 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1402 expect_vec3(expectedvec,gotvec);
1403 /* World matrix can be omitted */
1404 D3DXMatrixMultiply(&mat,&world,&view);
1405 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&mat,NULL);
1406 expect_vec3(expectedvec,gotvec);
1407 /* Projection matrix can be omitted */
1408 D3DXMatrixMultiply(&mat,&view,&projection);
1409 D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,&mat,&world);
1410 expect_vec3(expectedvec,gotvec);
1411 /* View matrix can be omitted */
1412 D3DXMatrixMultiply(&mat,&world,&view);
1413 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,NULL,&mat);
1414 expect_vec3(expectedvec,gotvec);
1415 /* All matrices can be omitted */
1416 expectedvec.x = -1.002500f; expectedvec.y = 0.997059f; expectedvec.z = 2.571429f;
1417 D3DXVec3Unproject(&gotvec,&u,&viewport,NULL,NULL,NULL);
1418 expect_vec3(expectedvec,gotvec);
1419 /* Viewport can be omitted */
1420 expectedvec.x = -11.018396f; expectedvec.y = 3.218991f; expectedvec.z = 1.380329f;
1421 D3DXVec3Unproject(&gotvec,&u,NULL,&projection,&view,&world);
1422 expect_vec3(expectedvec,gotvec);
1425 static void D3DXVector4Test(void)
1427 D3DXVECTOR4 expectedvec, gotvec, u, v, w, x;
1428 LPD3DXVECTOR4 funcpointer;
1429 D3DXVECTOR4 expectedtrans, gottrans;
1430 D3DXMATRIX mat;
1431 FLOAT coeff1, coeff2, expected, got, scale;
1433 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1434 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1435 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1436 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1438 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;
1439 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;
1440 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;
1441 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;
1443 coeff1 = 2.0f; coeff2 = 5.0;
1444 scale = -6.5f;
1446 /*_______________D3DXVec4Add__________________________*/
1447 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1448 D3DXVec4Add(&gotvec,&u,&v);
1449 expect_vec4(expectedvec,gotvec);
1450 /* Tests the case NULL */
1451 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1452 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1453 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1454 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1456 /*_______________D3DXVec4BaryCentric____________________*/
1457 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
1458 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1459 expect_vec4(expectedvec,gotvec);
1461 /*_______________D3DXVec4CatmullRom____________________*/
1462 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1463 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1464 expect_vec4(expectedvec,gotvec);
1466 /*_______________D3DXVec4Cross_________________________*/
1467 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1468 D3DXVec4Cross(&gotvec,&u,&v,&w);
1469 expect_vec4(expectedvec,gotvec);
1471 /*_______________D3DXVec4Dot__________________________*/
1472 expected = 55.0f;
1473 got = D3DXVec4Dot(&u,&v);
1474 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1475 /* Tests the case NULL */
1476 expected=0.0f;
1477 got = D3DXVec4Dot(NULL,&v);
1478 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1479 expected=0.0f;
1480 got = D3DXVec4Dot(NULL,NULL);
1481 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1483 /*_______________D3DXVec4Hermite_________________________*/
1484 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1485 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1486 expect_vec4(expectedvec,gotvec);
1488 /*_______________D3DXVec4Length__________________________*/
1489 expected = 11.0f;
1490 got = D3DXVec4Length(&u);
1491 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1492 /* Tests the case NULL */
1493 expected=0.0f;
1494 got = D3DXVec4Length(NULL);
1495 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1497 /*_______________D3DXVec4LengthSq________________________*/
1498 expected = 121.0f;
1499 got = D3DXVec4LengthSq(&u);
1500 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1501 /* Tests the case NULL */
1502 expected=0.0f;
1503 got = D3DXVec4LengthSq(NULL);
1504 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1506 /*_______________D3DXVec4Lerp__________________________*/
1507 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1508 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1509 expect_vec4(expectedvec,gotvec);
1510 /* Tests the case NULL */
1511 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1512 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1513 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1514 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1516 /*_______________D3DXVec4Maximize__________________________*/
1517 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1518 D3DXVec4Maximize(&gotvec,&u,&v);
1519 expect_vec4(expectedvec,gotvec);
1520 /* Tests the case NULL */
1521 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1522 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1523 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1524 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1526 /*_______________D3DXVec4Minimize__________________________*/
1527 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1528 D3DXVec4Minimize(&gotvec,&u,&v);
1529 expect_vec4(expectedvec,gotvec);
1530 /* Tests the case NULL */
1531 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1532 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1533 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1534 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1536 /*_______________D3DXVec4Normalize_________________________*/
1537 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1538 D3DXVec4Normalize(&gotvec,&u);
1539 expect_vec4(expectedvec,gotvec);
1541 /*_______________D3DXVec4Scale____________________________*/
1542 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1543 D3DXVec4Scale(&gotvec,&u,scale);
1544 expect_vec4(expectedvec,gotvec);
1545 /* Tests the case NULL */
1546 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1547 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1548 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1549 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1551 /*_______________D3DXVec4Subtract__________________________*/
1552 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1553 D3DXVec4Subtract(&gotvec,&u,&v);
1554 expect_vec4(expectedvec,gotvec);
1555 /* Tests the case NULL */
1556 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1557 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1558 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1559 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1561 /*_______________D3DXVec4Transform_______________________*/
1562 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1563 D3DXVec4Transform(&gottrans,&u,&mat);
1564 expect_vec4(expectedtrans,gottrans);
1567 static void test_matrix_stack(void)
1569 ID3DXMatrixStack *stack;
1570 ULONG refcount;
1571 HRESULT hr;
1573 const D3DXMATRIX mat1 = {{{
1574 1.0f, 2.0f, 3.0f, 4.0f,
1575 5.0f, 6.0f, 7.0f, 8.0f,
1576 9.0f, 10.0f, 11.0f, 12.0f,
1577 13.0f, 14.0f, 15.0f, 16.0f
1578 }}};
1580 const D3DXMATRIX mat2 = {{{
1581 17.0f, 18.0f, 19.0f, 20.0f,
1582 21.0f, 22.0f, 23.0f, 24.0f,
1583 25.0f, 26.0f, 27.0f, 28.0f,
1584 29.0f, 30.0f, 31.0f, 32.0f
1585 }}};
1587 hr = D3DXCreateMatrixStack(0, &stack);
1588 ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1589 if (FAILED(hr)) return;
1591 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1592 "The top of an empty matrix stack should be an identity matrix\n");
1594 hr = ID3DXMatrixStack_Pop(stack);
1595 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1597 hr = ID3DXMatrixStack_Push(stack);
1598 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1599 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1601 hr = ID3DXMatrixStack_Push(stack);
1602 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1604 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1605 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1606 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1608 hr = ID3DXMatrixStack_Push(stack);
1609 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1610 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1612 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1613 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1614 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1616 hr = ID3DXMatrixStack_Push(stack);
1617 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1618 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1620 hr = ID3DXMatrixStack_LoadIdentity(stack);
1621 ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
1622 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1624 hr = ID3DXMatrixStack_Pop(stack);
1625 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1626 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1628 hr = ID3DXMatrixStack_Pop(stack);
1629 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1630 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1632 hr = ID3DXMatrixStack_Pop(stack);
1633 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1634 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1636 hr = ID3DXMatrixStack_Pop(stack);
1637 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1638 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1640 refcount = ID3DXMatrixStack_Release(stack);
1641 ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1644 static void test_Matrix_AffineTransformation2D(void)
1646 D3DXMATRIX exp_mat, got_mat;
1647 D3DXVECTOR2 center, position;
1648 FLOAT angle, scale;
1650 center.x = 3.0f;
1651 center.y = 4.0f;
1653 position.x = -6.0f;
1654 position.y = 7.0f;
1656 angle = D3DX_PI/3.0f;
1658 scale = 20.0f;
1660 U(exp_mat).m[0][0] = 10.0f;
1661 U(exp_mat).m[1][0] = -17.320507f;
1662 U(exp_mat).m[2][0] = 0.0f;
1663 U(exp_mat).m[3][0] = -1.035898f;
1664 U(exp_mat).m[0][1] = 17.320507f;
1665 U(exp_mat).m[1][1] = 10.0f;
1666 U(exp_mat).m[2][1] = 0.0f;
1667 U(exp_mat).m[3][1] = 6.401924f;
1668 U(exp_mat).m[0][2] = 0.0f;
1669 U(exp_mat).m[1][2] = 0.0f;
1670 U(exp_mat).m[2][2] = 1.0f;
1671 U(exp_mat).m[3][2] = 0.0f;
1672 U(exp_mat).m[0][3] = 0.0f;
1673 U(exp_mat).m[1][3] = 0.0f;
1674 U(exp_mat).m[2][3] = 0.0f;
1675 U(exp_mat).m[3][3] = 1.0f;
1677 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, &position);
1679 expect_mat(&exp_mat, &got_mat);
1681 /*______________*/
1683 center.x = 3.0f;
1684 center.y = 4.0f;
1686 angle = D3DX_PI/3.0f;
1688 scale = 20.0f;
1690 U(exp_mat).m[0][0] = 10.0f;
1691 U(exp_mat).m[1][0] = -17.320507f;
1692 U(exp_mat).m[2][0] = 0.0f;
1693 U(exp_mat).m[3][0] = 4.964102f;
1694 U(exp_mat).m[0][1] = 17.320507f;
1695 U(exp_mat).m[1][1] = 10.0f;
1696 U(exp_mat).m[2][1] = 0.0f;
1697 U(exp_mat).m[3][1] = -0.598076f;
1698 U(exp_mat).m[0][2] = 0.0f;
1699 U(exp_mat).m[1][2] = 0.0f;
1700 U(exp_mat).m[2][2] = 1.0f;
1701 U(exp_mat).m[3][2] = 0.0f;
1702 U(exp_mat).m[0][3] = 0.0f;
1703 U(exp_mat).m[1][3] = 0.0f;
1704 U(exp_mat).m[2][3] = 0.0f;
1705 U(exp_mat).m[3][3] = 1.0f;
1707 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, NULL);
1709 expect_mat(&exp_mat, &got_mat);
1711 /*______________*/
1713 position.x = -6.0f;
1714 position.y = 7.0f;
1716 angle = D3DX_PI/3.0f;
1718 scale = 20.0f;
1720 U(exp_mat).m[0][0] = 10.0f;
1721 U(exp_mat).m[1][0] = -17.320507f;
1722 U(exp_mat).m[2][0] = 0.0f;
1723 U(exp_mat).m[3][0] = -6.0f;
1724 U(exp_mat).m[0][1] = 17.320507f;
1725 U(exp_mat).m[1][1] = 10.0f;
1726 U(exp_mat).m[2][1] = 0.0f;
1727 U(exp_mat).m[3][1] = 7.0f;
1728 U(exp_mat).m[0][2] = 0.0f;
1729 U(exp_mat).m[1][2] = 0.0f;
1730 U(exp_mat).m[2][2] = 1.0f;
1731 U(exp_mat).m[3][2] = 0.0f;
1732 U(exp_mat).m[0][3] = 0.0f;
1733 U(exp_mat).m[1][3] = 0.0f;
1734 U(exp_mat).m[2][3] = 0.0f;
1735 U(exp_mat).m[3][3] = 1.0f;
1737 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, &position);
1739 expect_mat(&exp_mat, &got_mat);
1741 /*______________*/
1743 angle = 5.0f * D3DX_PI/4.0f;
1745 scale = -20.0f;
1747 U(exp_mat).m[0][0] = 14.142133f;
1748 U(exp_mat).m[1][0] = -14.142133f;
1749 U(exp_mat).m[2][0] = 0.0f;
1750 U(exp_mat).m[3][0] = 0.0f;
1751 U(exp_mat).m[0][1] = 14.142133;
1752 U(exp_mat).m[1][1] = 14.142133f;
1753 U(exp_mat).m[2][1] = 0.0f;
1754 U(exp_mat).m[3][1] = 0.0f;
1755 U(exp_mat).m[0][2] = 0.0f;
1756 U(exp_mat).m[1][2] = 0.0f;
1757 U(exp_mat).m[2][2] = 1.0f;
1758 U(exp_mat).m[3][2] = 0.0f;
1759 U(exp_mat).m[0][3] = 0.0f;
1760 U(exp_mat).m[1][3] = 0.0f;
1761 U(exp_mat).m[2][3] = 0.0f;
1762 U(exp_mat).m[3][3] = 1.0f;
1764 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, NULL);
1766 expect_mat(&exp_mat, &got_mat);
1769 static void test_Matrix_Decompose(void)
1771 D3DXMATRIX pm;
1772 D3DXQUATERNION exp_rotation, got_rotation;
1773 D3DXVECTOR3 exp_scale, got_scale, exp_translation, got_translation;
1774 HRESULT hr;
1776 /*___________*/
1778 U(pm).m[0][0] = -0.9238790f;
1779 U(pm).m[1][0] = -0.2705984f;
1780 U(pm).m[2][0] = 0.2705984f;
1781 U(pm).m[3][0] = -5.0f;
1782 U(pm).m[0][1] = 0.2705984f;
1783 U(pm).m[1][1] = 0.03806049f;
1784 U(pm).m[2][1] = 0.9619395f;
1785 U(pm).m[3][1] = 0.0f;
1786 U(pm).m[0][2] = -0.2705984f;
1787 U(pm).m[1][2] = 0.9619395f;
1788 U(pm).m[2][2] = 0.03806049f;
1789 U(pm).m[3][2] = 10.0f;
1790 U(pm).m[0][3] = 0.0f;
1791 U(pm).m[1][3] = 0.0f;
1792 U(pm).m[2][3] = 0.0f;
1793 U(pm).m[3][3] = 1.0f;
1795 exp_scale.x = 1.0f;
1796 exp_scale.y = 1.0f;
1797 exp_scale.z = 1.0f;
1799 exp_rotation.w = 0.195091f;
1800 exp_rotation.x = 0.0f;
1801 exp_rotation.y = 0.693520f;
1802 exp_rotation.z = 0.693520f;
1804 exp_translation.x = -5.0f;
1805 exp_translation.y = 0.0f;
1806 exp_translation.z = 10.0f;
1808 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1810 compare_scale(exp_scale, got_scale);
1811 compare_rotation(exp_rotation, got_rotation);
1812 compare_translation(exp_translation, got_translation);
1814 /*_________*/
1816 U(pm).m[0][0] = -2.255813f;
1817 U(pm).m[1][0] = 1.302324f;
1818 U(pm).m[2][0] = 1.488373f;
1819 U(pm).m[3][0] = 1.0f;
1820 U(pm).m[0][1] = 1.302327f;
1821 U(pm).m[1][1] = -0.7209296f;
1822 U(pm).m[2][1] = 2.60465f;
1823 U(pm).m[3][1] = 2.0f;
1824 U(pm).m[0][2] = 1.488371f;
1825 U(pm).m[1][2] = 2.604651f;
1826 U(pm).m[2][2] = -0.02325551f;
1827 U(pm).m[3][2] = 3.0f;
1828 U(pm).m[0][3] = 0.0f;
1829 U(pm).m[1][3] = 0.0f;
1830 U(pm).m[2][3] = 0.0f;
1831 U(pm).m[3][3] = 1.0f;
1833 exp_scale.x = 3.0f;
1834 exp_scale.y = 3.0f;
1835 exp_scale.z = 3.0f;
1837 exp_rotation.w = 0.0;
1838 exp_rotation.x = 0.352180f;
1839 exp_rotation.y = 0.616316f;
1840 exp_rotation.z = 0.704361f;
1842 exp_translation.x = 1.0f;
1843 exp_translation.y = 2.0f;
1844 exp_translation.z = 3.0f;
1846 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1848 compare_scale(exp_scale, got_scale);
1849 compare_rotation(exp_rotation, got_rotation);
1850 compare_translation(exp_translation, got_translation);
1852 /*_____________*/
1854 U(pm).m[0][0] = 2.427051f;
1855 U(pm).m[1][0] = 0.0f;
1856 U(pm).m[2][0] = 1.763355f;
1857 U(pm).m[3][0] = 5.0f;
1858 U(pm).m[0][1] = 0.0f;
1859 U(pm).m[1][1] = 3.0f;
1860 U(pm).m[2][1] = 0.0f;
1861 U(pm).m[3][1] = 5.0f;
1862 U(pm).m[0][2] = -1.763355f;
1863 U(pm).m[1][2] = 0.0f;
1864 U(pm).m[2][2] = 2.427051f;
1865 U(pm).m[3][2] = 5.0f;
1866 U(pm).m[0][3] = 0.0f;
1867 U(pm).m[1][3] = 0.0f;
1868 U(pm).m[2][3] = 0.0f;
1869 U(pm).m[3][3] = 1.0f;
1871 exp_scale.x = 3.0f;
1872 exp_scale.y = 3.0f;
1873 exp_scale.z = 3.0f;
1875 exp_rotation.w = 0.951057f;
1876 exp_rotation.x = 0.0f;
1877 exp_rotation.y = 0.309017f;
1878 exp_rotation.z = 0.0f;
1880 exp_translation.x = 5.0f;
1881 exp_translation.y = 5.0f;
1882 exp_translation.z = 5.0f;
1884 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1886 compare_scale(exp_scale, got_scale);
1887 compare_rotation(exp_rotation, got_rotation);
1888 compare_translation(exp_translation, got_translation);
1890 /*_____________*/
1892 U(pm).m[0][0] = -0.9238790f;
1893 U(pm).m[1][0] = -0.2705984f;
1894 U(pm).m[2][0] = 0.2705984f;
1895 U(pm).m[3][0] = -5.0f;
1896 U(pm).m[0][1] = 0.2705984f;
1897 U(pm).m[1][1] = 0.03806049f;
1898 U(pm).m[2][1] = 0.9619395f;
1899 U(pm).m[3][1] = 0.0f;
1900 U(pm).m[0][2] = -0.2705984f;
1901 U(pm).m[1][2] = 0.9619395f;
1902 U(pm).m[2][2] = 0.03806049f;
1903 U(pm).m[3][2] = 10.0f;
1904 U(pm).m[0][3] = 0.0f;
1905 U(pm).m[1][3] = 0.0f;
1906 U(pm).m[2][3] = 0.0f;
1907 U(pm).m[3][3] = 1.0f;
1909 exp_scale.x = 1.0f;
1910 exp_scale.y = 1.0f;
1911 exp_scale.z = 1.0f;
1913 exp_rotation.w = 0.195091f;
1914 exp_rotation.x = 0.0f;
1915 exp_rotation.y = 0.693520f;
1916 exp_rotation.z = 0.693520f;
1918 exp_translation.x = -5.0f;
1919 exp_translation.y = 0.0f;
1920 exp_translation.z = 10.0f;
1922 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1924 compare_scale(exp_scale, got_scale);
1925 compare_rotation(exp_rotation, got_rotation);
1926 compare_translation(exp_translation, got_translation);
1928 /*__________*/
1930 U(pm).m[0][0] = -0.9238790f;
1931 U(pm).m[1][0] = -0.5411968f;
1932 U(pm).m[2][0] = 0.8117952f;
1933 U(pm).m[3][0] = -5.0f;
1934 U(pm).m[0][1] = 0.2705984f;
1935 U(pm).m[1][1] = 0.07612098f;
1936 U(pm).m[2][1] = 2.8858185f;
1937 U(pm).m[3][1] = 0.0f;
1938 U(pm).m[0][2] = -0.2705984f;
1939 U(pm).m[1][2] = 1.9238790f;
1940 U(pm).m[2][2] = 0.11418147f;
1941 U(pm).m[3][2] = 10.0f;
1942 U(pm).m[0][3] = 0.0f;
1943 U(pm).m[1][3] = 0.0f;
1944 U(pm).m[2][3] = 0.0f;
1945 U(pm).m[3][3] = 1.0f;
1947 exp_scale.x = 1.0f;
1948 exp_scale.y = 2.0f;
1949 exp_scale.z = 3.0f;
1951 exp_rotation.w = 0.195091f;
1952 exp_rotation.x = 0.0f;
1953 exp_rotation.y = 0.693520f;
1954 exp_rotation.z = 0.693520f;
1956 exp_translation.x = -5.0f;
1957 exp_translation.y = 0.0f;
1958 exp_translation.z = 10.0f;
1960 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1962 compare_scale(exp_scale, got_scale);
1963 compare_rotation(exp_rotation, got_rotation);
1964 compare_translation(exp_translation, got_translation);
1966 /*__________*/
1968 U(pm).m[0][0] = 0.7156004f;
1969 U(pm).m[1][0] = -0.5098283f;
1970 U(pm).m[2][0] = -0.4774843f;
1971 U(pm).m[3][0] = -5.0f;
1972 U(pm).m[0][1] = -0.6612288f;
1973 U(pm).m[1][1] = -0.7147621f;
1974 U(pm).m[2][1] = -0.2277977f;
1975 U(pm).m[3][1] = 0.0f;
1976 U(pm).m[0][2] = -0.2251499f;
1977 U(pm).m[1][2] = 0.4787385f;
1978 U(pm).m[2][2] = -0.8485972f;
1979 U(pm).m[3][2] = 10.0f;
1980 U(pm).m[0][3] = 0.0f;
1981 U(pm).m[1][3] = 0.0f;
1982 U(pm).m[2][3] = 0.0f;
1983 U(pm).m[3][3] = 1.0f;
1985 exp_scale.x = 1.0f;
1986 exp_scale.y = 1.0f;
1987 exp_scale.z = 1.0f;
1989 exp_rotation.w = 0.195091f;
1990 exp_rotation.x = 0.905395f;
1991 exp_rotation.y = -0.323355f;
1992 exp_rotation.z = -0.194013f;
1994 exp_translation.x = -5.0f;
1995 exp_translation.y = 0.0f;
1996 exp_translation.z = 10.0f;
1998 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2000 compare_scale(exp_scale, got_scale);
2001 compare_rotation(exp_rotation, got_rotation);
2002 compare_translation(exp_translation, got_translation);
2004 /*_____________*/
2006 U(pm).m[0][0] = 0.06554436f;
2007 U(pm).m[1][0] = -0.6873012f;
2008 U(pm).m[2][0] = 0.7234092f;
2009 U(pm).m[3][0] = -5.0f;
2010 U(pm).m[0][1] = -0.9617381f;
2011 U(pm).m[1][1] = -0.2367795f;
2012 U(pm).m[2][1] = -0.1378230f;
2013 U(pm).m[3][1] = 0.0f;
2014 U(pm).m[0][2] = 0.2660144f;
2015 U(pm).m[1][2] = -0.6866967f;
2016 U(pm).m[2][2] = -0.6765233f;
2017 U(pm).m[3][2] = 10.0f;
2018 U(pm).m[0][3] = 0.0f;
2019 U(pm).m[1][3] = 0.0f;
2020 U(pm).m[2][3] = 0.0f;
2021 U(pm).m[3][3] = 1.0f;
2023 exp_scale.x = 1.0f;
2024 exp_scale.y = 1.0f;
2025 exp_scale.z = 1.0f;
2027 exp_rotation.w = -0.195091f;
2028 exp_rotation.x = 0.703358f;
2029 exp_rotation.y = -0.586131f;
2030 exp_rotation.z = 0.351679f;
2032 exp_translation.x = -5.0f;
2033 exp_translation.y = 0.0f;
2034 exp_translation.z = 10.0f;
2036 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2038 compare_scale(exp_scale, got_scale);
2039 compare_rotation(exp_rotation, got_rotation);
2040 compare_translation(exp_translation, got_translation);
2042 /*_________*/
2044 U(pm).m[0][0] = 7.121047f;
2045 U(pm).m[1][0] = -5.883487f;
2046 U(pm).m[2][0] = 11.81843f;
2047 U(pm).m[3][0] = -5.0f;
2048 U(pm).m[0][1] = 5.883487f;
2049 U(pm).m[1][1] = -10.60660f;
2050 U(pm).m[2][1] = -8.825232f;
2051 U(pm).m[3][1] = 0.0f;
2052 U(pm).m[0][2] = 11.81843f;
2053 U(pm).m[1][2] = 8.8252320f;
2054 U(pm).m[2][2] = -2.727645f;
2055 U(pm).m[3][2] = 2.0f;
2056 U(pm).m[0][3] = 0.0f;
2057 U(pm).m[1][3] = 0.0f;
2058 U(pm).m[2][3] = 0.0f;
2059 U(pm).m[3][3] = 1.0f;
2061 exp_scale.x = 15.0f;
2062 exp_scale.y = 15.0f;
2063 exp_scale.z = 15.0f;
2065 exp_rotation.w = 0.382684f;
2066 exp_rotation.x = 0.768714f;
2067 exp_rotation.y = 0.0f;
2068 exp_rotation.z = 0.512476f;
2070 exp_translation.x = -5.0f;
2071 exp_translation.y = 0.0f;
2072 exp_translation.z = 2.0f;
2074 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2076 compare_scale(exp_scale, got_scale);
2077 compare_rotation(exp_rotation, got_rotation);
2078 compare_translation(exp_translation, got_translation);
2080 /*__________*/
2082 U(pm).m[0][0] = 0.0f;
2083 U(pm).m[1][0] = 4.0f;
2084 U(pm).m[2][0] = 5.0f;
2085 U(pm).m[3][0] = -5.0f;
2086 U(pm).m[0][1] = 0.0f;
2087 U(pm).m[1][1] = -10.60660f;
2088 U(pm).m[2][1] = -8.825232f;
2089 U(pm).m[3][1] = 6.0f;
2090 U(pm).m[0][2] = 0.0f;
2091 U(pm).m[1][2] = 8.8252320f;
2092 U(pm).m[2][2] = 2.727645;
2093 U(pm).m[3][2] = 3.0f;
2094 U(pm).m[0][3] = 0.0f;
2095 U(pm).m[1][3] = 0.0f;
2096 U(pm).m[2][3] = 0.0f;
2097 U(pm).m[3][3] = 1.0f;
2099 hr = D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2100 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
2103 static void test_Matrix_Transformation2D(void)
2105 D3DXMATRIX exp_mat, got_mat;
2106 D3DXVECTOR2 rot_center, sca, sca_center, trans;
2107 FLOAT rot, sca_rot;
2109 rot_center.x = 3.0f;
2110 rot_center.y = 4.0f;
2112 sca.x = 12.0f;
2113 sca.y = -3.0f;
2115 sca_center.x = 9.0f;
2116 sca_center.y = -5.0f;
2118 trans.x = -6.0f;
2119 trans.y = 7.0f;
2121 rot = D3DX_PI/3.0f;
2123 sca_rot = 5.0f*D3DX_PI/4.0f;
2125 U(exp_mat).m[0][0] = -4.245192f;
2126 U(exp_mat).m[1][0] = -0.147116f;
2127 U(exp_mat).m[2][0] = 0.0f;
2128 U(exp_mat).m[3][0] = 45.265373f;
2129 U(exp_mat).m[0][1] = 7.647113f;
2130 U(exp_mat).m[1][1] = 8.745192f;
2131 U(exp_mat).m[2][1] = 0.0f;
2132 U(exp_mat).m[3][1] = -13.401899f;
2133 U(exp_mat).m[0][2] = 0.0f;
2134 U(exp_mat).m[1][2] = 0.0f;
2135 U(exp_mat).m[2][2] = 1.0f;
2136 U(exp_mat).m[3][2] = 0.0f;
2137 U(exp_mat).m[0][3] = 0.0f;
2138 U(exp_mat).m[1][3] = 0.0f;
2139 U(exp_mat).m[2][3] = 0.0f;
2140 U(exp_mat).m[3][3] = 1.0f;
2142 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
2144 expect_mat(&exp_mat, &got_mat);
2146 /*_________*/
2148 sca_center.x = 9.0f;
2149 sca_center.y = -5.0f;
2151 trans.x = -6.0f;
2152 trans.y = 7.0f;
2154 rot = D3DX_PI/3.0f;
2156 sca_rot = 5.0f*D3DX_PI/4.0f;
2158 U(exp_mat).m[0][0] = 0.50f;
2159 U(exp_mat).m[1][0] = -0.866025f;
2160 U(exp_mat).m[2][0] = 0.0f;
2161 U(exp_mat).m[3][0] = -6.0f;
2162 U(exp_mat).m[0][1] = 0.866025f;
2163 U(exp_mat).m[1][1] = 0.50f;
2164 U(exp_mat).m[2][1] = 0.0f;
2165 U(exp_mat).m[3][1] = 7.0f;
2166 U(exp_mat).m[0][2] = 0.0f;
2167 U(exp_mat).m[1][2] = 0.0f;
2168 U(exp_mat).m[2][2] = 1.0f;
2169 U(exp_mat).m[3][2] = 0.0f;
2170 U(exp_mat).m[0][3] = 0.0f;
2171 U(exp_mat).m[1][3] = 0.0f;
2172 U(exp_mat).m[2][3] = 0.0f;
2173 U(exp_mat).m[3][3] = 1.0f;
2175 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
2177 expect_mat(&exp_mat, &got_mat);
2179 /*_________*/
2181 U(exp_mat).m[0][0] = 0.50f;
2182 U(exp_mat).m[1][0] = -0.866025f;
2183 U(exp_mat).m[2][0] = 0.0f;
2184 U(exp_mat).m[3][0] = 0.0f;
2185 U(exp_mat).m[0][1] = 0.866025f;
2186 U(exp_mat).m[1][1] = 0.50f;
2187 U(exp_mat).m[2][1] = 0.0f;
2188 U(exp_mat).m[3][1] = 0.0f;
2189 U(exp_mat).m[0][2] = 0.0f;
2190 U(exp_mat).m[1][2] = 0.0f;
2191 U(exp_mat).m[2][2] = 1.0f;
2192 U(exp_mat).m[3][2] = 0.0f;
2193 U(exp_mat).m[0][3] = 0.0f;
2194 U(exp_mat).m[1][3] = 0.0f;
2195 U(exp_mat).m[2][3] = 0.0f;
2196 U(exp_mat).m[3][3] = 1.0f;
2198 D3DXMatrixTransformation2D(&got_mat, NULL, sca_rot, NULL, NULL, rot, NULL);
2200 expect_mat(&exp_mat, &got_mat);
2203 static void test_D3DXVec_Array(void)
2205 unsigned int i;
2206 D3DVIEWPORT9 viewport;
2207 D3DXMATRIX mat, projection, view, world;
2208 D3DXVECTOR4 inp_vec[ARRAY_SIZE];
2209 D3DXVECTOR4 out_vec[ARRAY_SIZE + 2];
2210 D3DXVECTOR4 exp_vec[ARRAY_SIZE + 2];
2211 D3DXPLANE inp_plane[ARRAY_SIZE];
2212 D3DXPLANE out_plane[ARRAY_SIZE + 2];
2213 D3DXPLANE exp_plane[ARRAY_SIZE + 2];
2215 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
2216 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
2218 for (i = 0; i < ARRAY_SIZE + 2; ++i) {
2219 out_vec[i].x = out_vec[i].y = out_vec[i].z = out_vec[i].w = 0.0f;
2220 exp_vec[i].x = exp_vec[i].y = exp_vec[i].z = exp_vec[i].w = 0.0f;
2221 out_plane[i].a = out_plane[i].b = out_plane[i].c = out_plane[i].d = 0.0f;
2222 exp_plane[i].a = exp_plane[i].b = exp_plane[i].c = exp_plane[i].d = 0.0f;
2225 for (i = 0; i < ARRAY_SIZE; ++i) {
2226 inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
2227 inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE - i;
2230 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;
2231 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;
2232 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;
2233 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;
2235 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2237 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
2238 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
2239 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
2240 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
2241 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
2242 U(view).m[3][3] = -40.0f;
2244 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;
2245 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;
2246 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;
2247 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;
2249 /* D3DXVec2TransformCoordArray */
2250 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f;
2251 exp_vec[2].x = 0.653846f; exp_vec[2].y = 0.769231f;
2252 exp_vec[3].x = 0.625f; exp_vec[3].y = 0.75f;
2253 exp_vec[4].x = 0.590909f; exp_vec[4].y = 8.0f/11.0f;
2254 exp_vec[5].x = 0.55f; exp_vec[5].y = 0.7f;
2255 D3DXVec2TransformCoordArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2256 compare_vectors(exp_vec, out_vec);
2258 /* D3DXVec2TransformNormalArray */
2259 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
2260 exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
2261 exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
2262 exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
2263 exp_vec[5].x = 9.0f; exp_vec[5].y = 14.0f;
2264 D3DXVec2TransformNormalArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2265 compare_vectors(exp_vec, out_vec);
2267 /* D3DXVec3TransformCoordArray */
2268 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f; exp_vec[1].z = 0.892857f;
2269 exp_vec[2].x = 0.671875f; exp_vec[2].y = 0.78125f; exp_vec[2].z = 0.890625f;
2270 exp_vec[3].x = 6.0f/9.0f; exp_vec[3].y = 7.0f/9.0f; exp_vec[3].z = 8.0f/9.0f;
2271 exp_vec[4].x = 0.6625f; exp_vec[4].y = 0.775f; exp_vec[4].z = 0.8875f;
2272 exp_vec[5].x = 0.659091f; exp_vec[5].y = 0.772727f; exp_vec[5].z = 0.886364f;
2273 D3DXVec3TransformCoordArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2274 compare_vectors(exp_vec, out_vec);
2276 /* D3DXVec3TransformNormalArray */
2277 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
2278 exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
2279 exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
2280 exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
2281 exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
2282 D3DXVec3TransformNormalArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2283 compare_vectors(exp_vec, out_vec);
2285 /* D3DXVec3ProjectArray */
2286 exp_vec[1].x = 1089.554199f; exp_vec[1].y = -226.590622f; exp_vec[1].z = 0.215273f;
2287 exp_vec[2].x = 1068.903320f; exp_vec[2].y = 103.085129f; exp_vec[2].z = 0.183050f;
2288 exp_vec[3].x = 1051.778931f; exp_vec[3].y = 376.462250f; exp_vec[3].z = 0.156329f;
2289 exp_vec[4].x = 1037.348877f; exp_vec[4].y = 606.827393f; exp_vec[4].z = 0.133813f;
2290 exp_vec[5].x = 1025.023560f; exp_vec[5].y = 803.591248f; exp_vec[5].z = 0.114581f;
2291 D3DXVec3ProjectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (const D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2292 compare_vectors(exp_vec, out_vec);
2294 /* D3DXVec3UnprojectArray */
2295 exp_vec[1].x = -6.124031f; exp_vec[1].y = 3.225360f; exp_vec[1].z = 0.620571f;
2296 exp_vec[2].x = -3.807109f; exp_vec[2].y = 2.046579f; exp_vec[2].z = 0.446894f;
2297 exp_vec[3].x = -2.922839f; exp_vec[3].y = 1.596689f; exp_vec[3].z = 0.380609f;
2298 exp_vec[4].x = -2.456225f; exp_vec[4].y = 1.359290f; exp_vec[4].z = 0.345632f;
2299 exp_vec[5].x = -2.167897f; exp_vec[5].y = 1.212597f; exp_vec[5].z = 0.324019f;
2300 D3DXVec3UnprojectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (const D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2301 compare_vectors(exp_vec, out_vec);
2303 /* D3DXVec2TransformArray */
2304 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2305 exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
2306 exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
2307 exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
2308 exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
2309 D3DXVec2TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2310 compare_vectors(exp_vec, out_vec);
2312 /* D3DXVec3TransformArray */
2313 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2314 exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
2315 exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
2316 exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
2317 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2318 D3DXVec3TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2319 compare_vectors(exp_vec, out_vec);
2321 /* D3DXVec4TransformArray */
2322 exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
2323 exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f; exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
2324 exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f; exp_vec[3].z = 94.0f; exp_vec[3].w = 104.0f;
2325 exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f; exp_vec[4].z = 86.0f; exp_vec[4].w = 96.0f;
2326 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2327 D3DXVec4TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2328 compare_vectors(exp_vec, out_vec);
2330 /* D3DXPlaneTransformArray */
2331 exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
2332 exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f; exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
2333 exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f; exp_plane[3].c = 94.0f; exp_plane[3].d = 104.0f;
2334 exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f; exp_plane[4].c = 86.0f; exp_plane[4].d = 96.0f;
2335 exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f; exp_plane[5].c = 78.0f; exp_plane[5].d = 88.0f;
2336 D3DXPlaneTransformArray(out_plane + 1, sizeof(D3DXPLANE), inp_plane, sizeof(D3DXPLANE), &mat, ARRAY_SIZE);
2337 compare_planes(exp_plane, out_plane);
2340 static void test_D3DXFloat_Array(void)
2342 static const float z = 0.0f;
2343 /* Compilers set different sign bits on 0.0 / 0.0, pick the right ones for NaN and -NaN */
2344 float tmpnan = 0.0f/z;
2345 float nnan = copysignf(1, tmpnan) < 0.0f ? tmpnan : -tmpnan;
2346 float nan = -nnan;
2347 unsigned int i;
2348 void *out = NULL;
2349 D3DXFLOAT16 half;
2350 FLOAT single;
2351 struct
2353 FLOAT single_in;
2355 /* half_ver2 occurs on WXPPROSP3 (32 bit math), WVISTAADM (32/64 bit math), W7PRO (32 bit math) */
2356 WORD half_ver1, half_ver2;
2358 /* single_out_ver2 confirms that half -> single conversion is consistent across platforms */
2359 FLOAT single_out_ver1, single_out_ver2;
2360 } testdata[] = {
2361 { 80000.0f, 0x7c00, 0x7ce2, 65536.0f, 80000.0f },
2362 { 65503.0f, 0x7bff, 0x7bff, 65504.0f, 65504.0f },
2363 { 65504.0f, 0x7bff, 0x7bff, 65504.0f, 65504.0f },
2364 { 65520.0f, 0x7bff, 0x7c00, 65504.0f, 65536.0f },
2365 { 65521.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2366 { 65534.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2367 { 65535.0f, 0x7c00, 0x7c00, 65535.0f, 65536.0f },
2368 { 65536.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2369 { -80000.0f, 0xfc00, 0xfce2, -65536.0f, -80000.0f },
2370 { -65503.0f, 0xfbff, 0xfbff, -65504.0f, -65504.0f },
2371 { -65504.0f, 0xfbff, 0xfbff, -65504.0f, -65504.0f },
2372 { -65520.0f, 0xfbff, 0xfc00, -65504.0f, -65536.0f },
2373 { -65521.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2374 { -65534.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2375 { -65535.0f, 0xfc00, 0xfc00, -65535.0f, -65536.0f },
2376 { -65536.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2377 { 1.0f/z, 0x7c00, 0x7fff, 65536.0f, 131008.0f },
2378 { -1.0f/z, 0xffff, 0xffff, -131008.0f, -131008.0f },
2379 { nan, 0x7fff, 0xffff, 131008.0f, -131008.0f },
2380 { nnan, 0xffff, 0xffff, -131008.0f, -131008.0f },
2381 { 0.0f, 0x0, 0x0, 0.0f, 0.0f },
2382 { -0.0f, 0x8000, 0x8000, 0.0f, 0.0f },
2383 { 2.9809595e-08f, 0x0, 0x0, 0.0f, 0.0f },
2384 { -2.9809595e-08f, 0x8000, 0x8000, -0.0f, -0.0f },
2385 { 2.9809598e-08f, 0x1, 0x0, 5.96046e-08f, 5.96046e-08f },
2386 { -2.9809598e-08f, 0x8001, 0x8000, -5.96046e-08f, -5.96046e-08f },
2387 { 8.9406967e-08f, 0x2, 0x1, 1.19209e-07f, 5.96046e-008 }
2390 /* exception on NULL out or in parameter */
2391 out = D3DXFloat32To16Array(&half, &single, 0);
2392 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2394 out = D3DXFloat16To32Array(&single, &half, 0);
2395 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2397 for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
2399 out = D3DXFloat32To16Array(&half, &testdata[i].single_in, 1);
2400 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2401 ok(half.value == testdata[i].half_ver1 || half.value == testdata[i].half_ver2,
2402 "Got %x, expected %x or %x for index %d.\n", half.value, testdata[i].half_ver1,
2403 testdata[i].half_ver2, i);
2405 out = D3DXFloat16To32Array(&single, (D3DXFLOAT16 *)&testdata[i].half_ver1, 1);
2406 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2407 ok(relative_error(single, testdata[i].single_out_ver1) < admitted_error,
2408 "Got %g, expected %g for index %d.\n", single, testdata[i].single_out_ver1, i);
2410 out = D3DXFloat16To32Array(&single, (D3DXFLOAT16 *)&testdata[i].half_ver2, 1);
2411 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2412 ok(relative_error(single, testdata[i].single_out_ver2) < admitted_error,
2413 "Got %g, expected %g for index %d.\n", single, testdata[i].single_out_ver2, i);
2417 static void test_D3DXSHAdd(void)
2419 UINT i, k;
2420 FLOAT *ret = (FLOAT *)0xdeadbeef;
2421 const FLOAT in1[50] =
2423 1.11f, 1.12f, 1.13f, 1.14f, 1.15f, 1.16f, 1.17f, 1.18f,
2424 1.19f, 1.20f, 1.21f, 1.22f, 1.23f, 1.24f, 1.25f, 1.26f,
2425 1.27f, 1.28f, 1.29f, 1.30f, 1.31f, 1.32f, 1.33f, 1.34f,
2426 1.35f, 1.36f, 1.37f, 1.38f, 1.39f, 1.40f, 1.41f, 1.42f,
2427 1.43f, 1.44f, 1.45f, 1.46f, 1.47f, 1.48f, 1.49f, 1.50f,
2428 1.51f, 1.52f, 1.53f, 1.54f, 1.55f, 1.56f, 1.57f, 1.58f,
2429 1.59f, 1.60f,
2431 const FLOAT in2[50] =
2433 2.11f, 2.12f, 2.13f, 2.14f, 2.15f, 2.16f, 2.17f, 2.18f,
2434 2.19f, 2.20f, 2.21f, 2.22f, 2.23f, 2.24f, 2.25f, 2.26f,
2435 2.27f, 2.28f, 2.29f, 2.30f, 2.31f, 2.32f, 2.33f, 2.34f,
2436 2.35f, 2.36f, 2.37f, 2.38f, 2.39f, 2.40f, 2.41f, 2.42f,
2437 2.43f, 2.44f, 2.45f, 2.46f, 2.47f, 2.48f, 2.49f, 2.50f,
2438 2.51f, 2.52f, 2.53f, 2.54f, 2.55f, 2.56f, 2.57f, 2.58f,
2439 2.59f, 2.60f,
2441 FLOAT out[50] = {0.0f};
2444 * Order is not limited by D3DXSH_MINORDER and D3DXSH_MAXORDER!
2445 * All values will work, test from 0-7 [D3DXSH_MINORDER = 2, D3DXSH_MAXORDER = 6]
2446 * Exceptions will show up when out, in1 or in2 is NULL
2448 for (k = 0; k <= D3DXSH_MAXORDER + 1; k++)
2450 UINT count = k * k;
2452 ret = D3DXSHAdd(&out[0], k, &in1[0], &in2[0]);
2453 ok(ret == out, "%u: D3DXSHAdd() failed, got %p, expected %p\n", k, out, ret);
2455 for (i = 0; i < count; ++i)
2457 ok(relative_error(in1[i] + in2[i], out[i]) < admitted_error,
2458 "%u-%u: D3DXSHAdd() failed, got %f, expected %f\n", k, i, out[i], in1[i] + in2[i]);
2460 ok(relative_error(out[count], 0.0f) < admitted_error, "%u-%u: D3DXSHAdd() failed, got %f, expected 0.0\n", k, k * k, out[count]);
2464 static void test_D3DXSHDot(void)
2466 unsigned int i;
2467 FLOAT a[49], b[49], got;
2468 const FLOAT expected[] =
2469 { 0.5f, 0.5f, 25.0f, 262.5f, 1428.0f, 5362.0f, 15873.0f, 39812.0f, };
2471 for (i = 0; i < 49; i++)
2473 a[i] = i + 1.0f;
2474 b[i] = i + 0.5f;
2477 /* D3DXSHDot computes by using order * order elements */
2478 for (i = 0; i <= D3DXSH_MAXORDER + 1; i++)
2480 got = D3DXSHDot(i, a, b);
2481 ok(relative_error(got, expected[i]) < admitted_error, "order %d: expected %f, received %f\n", i, expected[i], got);
2484 return;
2487 static void test_D3DXSHEvalConeLight(void)
2489 D3DXVECTOR3 dir;
2490 FLOAT bout[49], expected, gout[49], rout[49];
2491 const FLOAT table[] = {
2492 /* Red colour */
2493 1.604815f, -3.131381f, 7.202175f, -2.870432f, 6.759296f, -16.959688f,
2494 32.303082f, -15.546381f, -0.588878f, -5.902123f, 40.084042f, -77.423569f,
2495 137.556320f, -70.971603f, -3.492171f, 7.683092f, -2.129311f, -35.971344f,
2496 183.086548f, -312.414948f, 535.091064f, -286.380371f, -15.950727f, 46.825714f,
2497 -12.127637f, 11.289261f, -12.417809f, -155.039566f, 681.182556f, -1079.733643f,
2498 1807.650513f, -989.755798f, -59.345467f, 201.822815f, -70.726486f, 7.206529f,
2500 3.101155f, -3.128710f, 7.196033f, -2.867984f, -0.224708f, 0.563814f,
2501 -1.073895f, 0.516829f, 0.019577f, 2.059788f, -13.988971f, 27.020128f,
2502 -48.005917f, 24.768450f, 1.218736f, -2.681329f, -0.088639f, -1.497410f,
2503 7.621501f, -13.005165f, 22.274696f, -11.921401f, -0.663995f, 1.949254f,
2504 -0.504848f, 4.168484f, -4.585193f, -57.247314f, 251.522095f, -398.684387f,
2505 667.462891f, -365.460693f, -21.912912f, 74.521721f, -26.115280f, 2.660963f,
2506 /* Green colour */
2507 2.454422f, -4.789170f, 11.015091f, -4.390072f, 10.337747f, -25.938347f,
2508 49.404713f, -23.776817f, -0.900637f, -9.026776f, 61.305000f, -118.412514f,
2509 210.380249f, -108.544792f, -5.340967f, 11.750610f, -3.256593f, -55.014996f,
2510 280.014709f, -477.811066f, 818.374512f, -437.993469f, -24.395227f, 71.615799f,
2511 -18.548151f, 17.265928f, -18.991943f, -237.119324f, 1041.808594f, -1651.357300f,
2512 2764.642090f, -1513.744141f, -90.763657f, 308.670197f, -108.169922f, 11.021750f,
2514 4.742942f, -4.785086f, 11.005697f, -4.386329f, -0.343672f, 0.862303f,
2515 -1.642427f, 0.790444f, 0.029941f, 3.150264f, -21.394896f, 41.324898f,
2516 -73.420807f, 37.881153f, 1.863950f, -4.100857f, -0.135565f, -2.290156f,
2517 11.656413f, -19.890251f, 34.067181f, -18.232729f, -1.015521f, 2.981212f,
2518 -0.772120f, 6.375328f, -7.012648f, -87.554710f, 384.680817f, -609.752563f,
2519 1020.825500f, -558.939819f, -33.513863f, 113.974388f, -39.941013f, 4.069707f,
2520 /* Blue colour */
2521 3.304030f, -6.446959f, 14.828006f, -5.909713f, 13.916198f, -34.917004f,
2522 66.506340f, -32.007256f, -1.212396f, -12.151429f, 82.525963f, -159.401459f,
2523 283.204193f, -146.117996f, -7.189764f, 15.818130f, -4.383876f, -74.058655f,
2524 376.942871f, -643.207214f, 1101.658081f, -589.606628f, -32.839729f, 96.405884f,
2525 -24.968664f, 23.242596f, -25.566080f, -319.199097f, 1402.434692f, -2222.980957f,
2526 3721.633545f, -2037.732544f, -122.181847f, 415.517578f, -145.613358f, 14.836972f,
2528 6.384730f, -6.441462f, 14.815362f, -5.904673f, -0.462635f, 1.160793f,
2529 -2.210959f, 1.064060f, 0.040305f, 4.240739f, -28.800821f, 55.629673f,
2530 -98.835709f, 50.993862f, 2.509163f, -5.520384f, -0.182491f, -3.082903f,
2531 15.691326f, -26.775339f, 45.859665f, -24.544060f, -1.367048f, 4.013170f,
2532 -1.039392f, 8.582172f, -9.440103f, -117.862114f, 517.839600f, -820.820740f,
2533 1374.188232f, -752.419067f, -45.114819f, 153.427063f, -53.766754f, 5.478452f, };
2534 struct
2536 FLOAT *red_received, *green_received, *blue_received;
2537 const FLOAT *red_expected, *green_expected, *blue_expected;
2538 FLOAT radius, roffset, goffset, boffset;
2539 } test[] = {
2540 { rout, gout, bout, table, &table[72], &table[144], 0.5f, 1.01f, 1.02f, 1.03f, },
2541 { rout, gout, bout, &table[36], &table[108], &table[180], 1.6f, 1.01f, 1.02f, 1.03f, },
2542 { rout, rout, rout, &table[144], &table[144], &table[144], 0.5f, 1.03f, 1.03f, 1.03f, },
2543 { rout, rout, bout, &table[72], &table[72], &table[144], 0.5, 1.02f, 1.02f, 1.03f, },
2544 { rout, gout, gout, table, &table[144], &table[144], 0.5f, 1.01f, 1.03f, 1.03f, },
2545 { rout, gout, rout, &table[144], &table[72], &table[144], 0.5f, 1.03f, 1.02f, 1.03f, },
2546 /* D3DXSHEvalConeLight accepts NULL green or blue colour. */
2547 { rout, NULL, bout, table, NULL, &table[144], 0.5f, 1.01f, 0.0f, 1.03f, },
2548 { rout, gout, NULL, table, &table[72], NULL, 0.5f, 1.01f, 1.02f, 0.0f, },
2549 { rout, NULL, NULL, table, NULL, NULL, 0.5f, 1.01f, 0.0f, 0.0f, }, };
2550 HRESULT hr;
2551 unsigned int j, l, order;
2553 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
2555 for (l = 0; l < sizeof(test) / sizeof(test[0]); l++)
2557 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2559 for (j = 0; j < 49; j++)
2561 test[l].red_received[j] = 1.01f + j;
2562 if (test[l].green_received)
2563 test[l].green_received[j] = 1.02f + j;
2564 if (test[l].blue_received)
2565 test[l].blue_received[j] = 1.03f + j;
2568 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);
2569 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2571 for (j = 0; j < 49; j++)
2573 if (j >= order * order)
2574 expected = j + test[l].roffset;
2575 else
2576 expected = test[l].red_expected[j];
2577 ok(relative_error(expected, test[l].red_received[j]) < admitted_error,
2578 "Red: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].red_received[j]);
2580 if (test[l].green_received)
2582 if (j >= order * order)
2583 expected = j + test[l].goffset;
2584 else
2585 expected = test[l].green_expected[j];
2586 ok(relative_error(expected, test[l].green_received[j]) < admitted_error,
2587 "Green: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].green_received[j]);
2590 if (test[l].blue_received)
2592 if (j >= order * order)
2593 expected = j + test[l].boffset;
2594 else
2595 expected = test[l].blue_expected[j];
2596 ok(relative_error(expected, test[l].blue_received[j]) < admitted_error,
2597 "Blue: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].blue_received[j]);
2603 /* Cone light with radius <= 0.0f behaves as a directional light */
2604 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2606 FLOAT blue[49], green[49], red[49];
2608 for (j = 0; j < 49; j++)
2610 rout[j] = 1.01f + j;
2611 gout[j] = 1.02f + j;
2612 bout[j] = 1.03f + j;
2613 red[j] = 1.01f + j;
2614 green[j] = 1.02f + j;
2615 blue[j] = 1.03f + j;
2618 hr = D3DXSHEvalConeLight(order, &dir, -0.1f, 1.7f, 2.6f, 3.5f, rout, gout, bout);
2619 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2620 D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red, green, blue);
2622 for (j = 0; j < 49; j++)
2624 expected = red[j];
2625 ok(relative_error(expected, rout[j]) < admitted_error,
2626 "Red: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, rout[j]);
2628 expected = green[j];
2629 ok(relative_error(expected, gout[j]) < admitted_error,
2630 "Green: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, gout[j]);
2632 expected = blue[j];
2633 ok(relative_error(expected, bout[j]) < admitted_error,
2634 "Blue: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, bout[j]);
2638 /* D3DXSHEvalConeLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
2639 hr = D3DXSHEvalConeLight(7, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2640 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2641 hr = D3DXSHEvalConeLight(0, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2642 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2643 hr = D3DXSHEvalConeLight(1, &dir, 0.5f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2644 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2647 static void test_D3DXSHEvalDirection(void)
2649 unsigned int i, order;
2650 D3DXVECTOR3 d;
2651 FLOAT a[49], expected[49], *received_ptr;
2652 const FLOAT table[36] =
2653 { 0.282095f, -0.977205f, 1.465808f, -0.488603f, 2.185097f, -6.555291f,
2654 8.200181f, -3.277646f, -1.638823f, 1.180087f, 17.343668f, -40.220032f,
2655 47.020218f, -20.110016f, -13.007751f, 6.490479f, -15.020058f, 10.620785f,
2656 117.325661f, -240.856750f, 271.657288f, -120.428375f, -87.994247f, 58.414314f,
2657 -4.380850f, 24.942520f, -149.447693f, 78.278130f, 747.791748f, -1427.687866f,
2658 1574.619141, -713.843933f, -560.843811f, 430.529724, -43.588909, -26.911665, };
2660 d.x = 1.0; d.y = 2.0f; d.z = 3.0f;
2662 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
2664 for (i = 0; i < 49; i++)
2665 a[i] = 1.5f + i;
2667 received_ptr = D3DXSHEvalDirection(a, order, &d);
2668 ok(received_ptr == a, "Expected %p, received %p\n", a, received_ptr);
2670 for (i = 0; i < 49; i++)
2672 /* if the order is < D3DXSH_MINORDER or order > D3DXSH_MAXORDER or the index of the element is greater than order * order - 1, D3DXSHEvalDirection does not modify the output */
2673 if ( (order < D3DXSH_MINORDER) || (order > D3DXSH_MAXORDER) || (i >= order * order) )
2674 expected[i] = 1.5f + i;
2675 else
2676 expected[i] = table[i];
2678 ok(relative_error(a[i], expected[i]) < admitted_error, "order %u, index %u: expected %f, received %f\n", order, i, expected[i], a[i]);
2683 static void test_D3DXSHEvalDirectionalLight(void)
2685 D3DXVECTOR3 dir;
2686 FLOAT *blue_out, bout[49], expected, gout[49], *green_out, *red_out, rout[49];
2687 static const FLOAT table[] = {
2688 /* Red colour */
2689 2.008781f, -4.175174f, 9.602900f, -3.827243f, 1.417963f, -2.947181f,
2690 6.778517f, -2.701583f, 7.249108f, -18.188671f, 34.643921f, -16.672949f,
2691 -0.631551f, 1.417963f, -2.947181f, 6.778517f, -2.701583f, 7.249108f,
2692 -18.188671f, 34.643921f, -16.672949f, -0.631551f, -7.794341f, 52.934967f,
2693 -102.245529f, 181.656815f, -93.725060f, -4.611760f, 10.146287f, 1.555186f,
2694 -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f, 37.996559f,
2695 -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f, 199.236496f,
2696 -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f, 360.268829f,
2697 -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f, -23.864176f,
2698 1.555186f, -3.232392f, 7.434503f, -2.963026f, 7.950634f, -19.948866f,
2699 37.996559f, -18.286459f, -0.692669f, -8.548632f, 58.057705f, -112.140251f,
2700 199.236496f, -102.795227f, -5.058059f, 11.128186f, -4.189955f, -70.782669f,
2701 360.268829f, -614.755005f, 1052.926270f, -563.525391f, -31.387066f, 92.141365f,
2702 -23.864176f, 34.868664f, -38.354366f, -478.864166f, 2103.939941f, -3334.927734f,
2703 5583.213867f, -3057.017090f, -183.297836f, 623.361633f, -218.449921f, 22.258503f,
2704 /* Green colour */
2705 3.072254f, -6.385560f, 14.686787f, -5.853429f, 2.168650f, -4.507453f,
2706 10.367143f, -4.131832f, 11.086870f, -27.817965f, 52.984818f, -25.499800f,
2707 -0.965902f, 2.168650f, -4.507453f, 10.367143f, -4.131832f, 11.086870f,
2708 -27.817965f, 52.984818f, -25.499800f, -0.965902f, -11.920755f, 80.959351f,
2709 -156.375488f, 277.828033f, -143.344193f, -7.053278f, 15.517849f, 2.378519f,
2710 -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f, 58.112385f,
2711 -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f, 304.714630f,
2712 -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f, 550.999390f,
2713 -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f, -36.498150f,
2714 2.378519f, -4.943659f, 11.370415f, -4.531687f, 12.159794f, -30.510029f,
2715 58.112385f, -27.967525f, -1.059376f, -13.074378f, 88.794136f, -171.508621f,
2716 304.714630f, -157.216217f, -7.735855f, 17.019577f, -6.408166f, -108.255844f,
2717 550.999390f, -940.213501f, 1610.357788f, -861.862305f, -48.003746f, 140.922089f,
2718 -36.498150f, 53.328545f, -58.659618f, -732.380493f, 3217.790283f, -5100.477539f,
2719 8539.033203f, -4675.437500f, -280.337860f, 953.376587f, -334.099884f, 34.042416f,
2720 /* Blue colour */
2721 4.135726f, -8.595945f, 19.770674f, -7.879617f, 2.919336f, -6.067726f,
2722 13.955770f, -5.562082f, 14.924634f, -37.447262f, 71.325722f, -34.326656f,
2723 -1.300252f, 2.919336f, -6.067726f, 13.955770f, -5.562082f, 14.924634f,
2724 -37.447262f, 71.325722f, -34.326656f, -1.300252f, -16.047173f, 108.983749f,
2725 -210.505493f, 373.999298f, -192.963348f, -9.494799f, 20.889414f, 3.201853f,
2726 -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f, 78.228210f,
2727 -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f, 410.192780f,
2728 -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f, 741.729919f,
2729 -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f, -49.132126f,
2730 3.201853f, -6.654925f, 15.306328f, -6.100348f, 16.368954f, -41.071194f,
2731 78.228210f, -37.648590f, -1.426083f, -17.600124f, 119.530563f, -230.876984f,
2732 410.192780f, -211.637222f, -10.413651f, 22.910971f, -8.626378f, -145.729019f,
2733 741.729919f, -1265.671997f, 2167.789307f, -1160.199219f, -64.620430f, 189.702820f,
2734 -49.132126f, 71.788422f, -78.964867f, -985.896790f, 4331.640625f, -6866.027344f,
2735 11494.852539f, -6293.858398f, -377.377899f, 1283.391479f, -449.749817f, 45.826328f, };
2736 struct
2738 FLOAT *red_in, *green_in, *blue_in;
2739 const FLOAT *red_out, *green_out, *blue_out;
2740 FLOAT roffset, goffset, boffset;
2741 } test[] =
2742 { { rout, gout, bout, table, &table[90], &table[180], 1.01f, 1.02f, 1.03f, },
2743 { rout, rout, rout, &table[180], &table[180], &table[180], 1.03f, 1.03f, 1.03f, },
2744 { rout, rout, bout, &table[90], &table[90], &table[180], 1.02f, 1.02f, 1.03f, },
2745 { rout, gout, gout, table, &table[180], &table[180], 1.01f, 1.03f, 1.03f, },
2746 { rout, gout, rout, &table[180], &table[90], &table[180], 1.03f, 1.02f, 1.03f, },
2747 /* D3DXSHEvalDirectionaLight accepts NULL green or blue colour. */
2748 { rout, NULL, bout, table, NULL, &table[180], 1.01f, 0.0f, 1.03f, },
2749 { rout, gout, NULL, table, &table[90], NULL, 1.01f, 1.02f, 0.0f, },
2750 { rout, NULL, NULL, table, NULL, NULL, 1.01f, 0.0f, 0.0f, }, };
2751 HRESULT hr;
2752 unsigned int j, l, order, startindex;
2754 dir.x = 1.1f; dir.y= 1.2f; dir.z = 2.76f;
2756 for (l = 0; l < sizeof( test ) / sizeof( test[0] ); l++)
2758 startindex = 0;
2760 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
2762 red_out = test[l].red_in;
2763 green_out = test[l].green_in;
2764 blue_out = test[l].blue_in;
2766 for (j = 0; j < 49; j++)
2768 red_out[j] = 1.01f + j;
2769 if ( green_out )
2770 green_out[j] = 1.02f + j;
2771 if ( blue_out )
2772 blue_out[j] = 1.03f + j;
2775 hr = D3DXSHEvalDirectionalLight(order, &dir, 1.7f, 2.6f, 3.5f, red_out, green_out, blue_out);
2776 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2778 for (j = 0; j < 49; j++)
2780 if ( j >= order * order )
2781 expected = j + test[l].roffset;
2782 else
2783 expected = test[l].red_out[startindex + j];
2784 ok(relative_error(expected, red_out[j]) < admitted_error,
2785 "Red: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, red_out[j]);
2787 if ( green_out )
2789 if ( j >= order * order )
2790 expected = j + test[l].goffset;
2791 else
2792 expected = test[l].green_out[startindex + j];
2793 ok(relative_error(expected, green_out[j]) < admitted_error,
2794 "Green: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, green_out[j]);
2797 if ( blue_out )
2799 if ( j >= order * order )
2800 expected = j + test[l].boffset;
2801 else
2802 expected = test[l].blue_out[startindex + j];
2803 ok(relative_error(expected, blue_out[j]) < admitted_error,
2804 "Blue: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, blue_out[j]);
2808 startindex += order * order;
2812 /* D3DXSHEvalDirectionalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set*/
2813 hr = D3DXSHEvalDirectionalLight(7, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2814 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2815 hr = D3DXSHEvalDirectionalLight(0, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2816 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2817 hr = D3DXSHEvalDirectionalLight(1, &dir, 1.0f, 2.0f, 3.0f, rout, gout, bout);
2818 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2821 static void test_D3DXSHEvalHemisphereLight(void)
2823 D3DXCOLOR bottom, top;
2824 D3DXVECTOR3 dir;
2825 FLOAT bout[49], expected, gout[49], rout[49];
2826 const FLOAT table[] = {
2827 /* Red colour */
2828 23.422981f, 15.859521f, -36.476898f, 14.537894f,
2829 /* Green colour */
2830 19.966694f, 6.096982f, -14.023058f, 5.588900f,
2831 /* Blue colour */
2832 24.566214f, 8.546826f, -19.657701f, 7.834591f, };
2833 struct
2835 FLOAT *red_received, *green_received, *blue_received;
2836 const FLOAT *red_expected, *green_expected, *blue_expected;
2837 const FLOAT roffset, goffset, boffset;
2838 } test[] = {
2839 { rout, gout, bout, table, &table[4], &table[8], 1.01f, 1.02f, 1.03f, },
2840 { rout, rout, rout, &table[8], &table[8], &table[8], 1.03f, 1.03f, 1.03f, },
2841 { rout, rout, bout, &table[4], &table[4], &table[8], 1.02f, 1.02f, 1.03f, },
2842 { rout, gout, gout, table, &table[8], &table[8], 1.01f, 1.03f, 1.03f, },
2843 { rout, gout, rout, &table[8], &table[4], &table[8], 1.03f, 1.02f, 1.03f, },
2844 /* D3DXSHEvalHemisphereLight accepts NULL green or blue colour. */
2845 { rout, NULL, bout, table, NULL, &table[8], 1.01f, 1.02f, 1.03f, },
2846 { rout, gout, NULL, table, &table[4], NULL, 1.01f, 1.02f, 1.03f, },
2847 { rout, NULL, NULL, table, NULL, NULL, 1.01f, 1.02f, 1.03f, }, };
2848 HRESULT hr;
2849 unsigned int j, l, order;
2851 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
2852 top.r = 0.1f; top.g = 2.1f; top.b = 2.3f; top.a = 4.3f;
2853 bottom.r = 8.71f; bottom.g = 5.41f; bottom.b = 6.94f; bottom.a = 8.43f;
2855 for (l = 0; l < sizeof(test) / sizeof(test[0]); l++)
2856 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER + 1; order++)
2858 for (j = 0; j < 49; j++)
2860 test[l].red_received[j] = 1.01f + j;
2861 if (test[l].green_received)
2862 test[l].green_received[j] = 1.02f + j;
2863 if (test[l].blue_received)
2864 test[l].blue_received[j] = 1.03f + j;
2867 hr = D3DXSHEvalHemisphereLight(order, &dir, top, bottom, test[l].red_received, test[l].green_received, test[l].blue_received);
2868 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
2870 for (j = 0; j < 49; j++)
2872 if (j < 4)
2873 expected = test[l].red_expected[j];
2874 else if (j < order * order)
2875 expected = 0.0f;
2876 else
2877 expected = test[l].roffset + j;
2878 ok(relative_error(test[l].red_received[j], expected) < admitted_error,
2879 "Red: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].red_received[j]);
2881 if (test[l].green_received)
2883 if (j < 4)
2884 expected = test[l].green_expected[j];
2885 else if (j < order * order)
2886 expected = 0.0f;
2887 else
2888 expected = test[l].goffset + j;
2889 ok(relative_error(expected, test[l].green_received[j]) < admitted_error,
2890 "Green: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].green_received[j]);
2893 if (test[l].blue_received)
2895 if (j < 4)
2896 expected = test[l].blue_expected[j];
2897 else if (j < order * order)
2898 expected = 0.0f;
2899 else
2900 expected = test[l].boffset + j;
2901 ok(relative_error(expected, test[l].blue_received[j]) < admitted_error,
2902 "Blue: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].blue_received[j]);
2908 static void test_D3DXSHEvalSphericalLight(void)
2910 D3DXVECTOR3 dir;
2911 FLOAT bout[49], expected, gout[49], rout[49];
2912 const FLOAT table[] = {
2913 /* Red colour */
2914 3.01317239f, -0.97724032f, 2.24765277f, -0.89580363f, 0.0f, 0.0f,
2915 0.0f, 0.0f, 0.0f, 0.06292814f, -0.42737406f, 0.61921263f,
2916 -0.30450898f, 0.56761158f, 0.03723336f, -0.08191673f, 0.0f, 0.0f,
2917 0.0f, 0.0f, 0.0f, -0.0f, 0.0f, 0.0f,
2918 0.0f, 0.01249927f, -0.01374878f, -0.14810932f, 0.43434596f, -0.24598616f,
2919 -0.15175794f, -0.22548729f, -0.03784076f, 0.19280137f, -0.07830712f, 0.00797894f,
2921 0.40251964f, -0.24365333f, 0.56040263f, -0.22334887f, 0.16204689f, -0.40659040f,
2922 0.44600141f, -0.37270784f, -0.01411773f, -0.04319951f, 0.29338786f, -0.42508304f,
2923 0.20904225f, -0.38965943f, -0.02556031f, 0.05623499f, -0.00468823f, -0.07920021f,
2924 0.33171222f, -0.30782884f, 0.00052908f, -0.28217643f, -0.02889918f, 0.10309891f,
2925 -0.02670213f, 0.00724340f, -0.00796750f, -0.08583023f, 0.25170606f, -0.14255044f,
2926 -0.08794463f, -0.13067122f, -0.02192894f, 0.11172954f, -0.04537944f, 0.00462384f,
2928 1.95445275f, -0.85659367f, 1.97016549f, -0.78521085f, 0.23103346f, -0.57968396f,
2929 0.63587302f, -0.53137696f, -0.02012792f, 0.02111043f, -0.14337072f, 0.20772660f,
2930 -0.10215330f, 0.19041604f, 0.01249063f, -0.02748052f, 0.00633162f, 0.10696279f,
2931 -0.44798949f, 0.41573414f, -0.00071454f, 0.38108963f, 0.03902940f, -0.13923886f,
2932 0.03606220f, -0.00447360f, 0.00492081f, 0.05300967f, -0.15545636f, 0.08804068f,
2933 0.05431554f, 0.08070395f, 0.01354355f, -0.06900536f, 0.02802683f, -0.00285574f,
2934 /* Green colour */
2935 4.60838127f, -1.49460280f, 3.43758631f, -1.37005258f, 0.0f, 0.0f,
2936 0.0f, 0.0f, 0.0f, 0.09624302f, -0.65363091f, 0.94703102f,
2937 -0.46571958f, 0.86811179f, 0.05694513f, -0.12528442f, -0.0f, 0.0f,
2938 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
2939 0.0f, 0.01911653f, -0.02102755f, -0.22652012f, 0.66429377f, -0.37621412f,
2940 -0.23210037f, -0.34486291f, -0.05787410f, 0.29487267f, -0.11976383f, 0.01220309f,
2942 0.61561823f, -0.37264627f, 0.85708636f, -0.34159240f, 0.24783641f, -0.62184411f,
2943 0.68211979f, -0.57002378f, -0.02159182f, -0.06606984f, 0.44871080f, -0.65012693f,
2944 0.31971166f, -0.59594971f, -0.03909224f, 0.08600645f, -0.00717023f, -0.12112973f,
2945 0.50732452f, -0.47079703f, 0.00080918f, -0.43156394f, -0.04419874f, 0.15768069f,
2946 -0.04083854f, 0.01107814f, -0.01218559f, -0.13126975f, 0.38496217f, -0.21801829f,
2947 -0.13450353f, -0.19985008f, -0.03353838f, 0.17088045f, -0.06940385f, 0.00707176f,
2949 2.98916292f, -1.31008446f, 3.01319408f, -1.20091069f, 0.35334525f, -0.88657540f,
2950 0.97251165f, -0.81269407f, -0.03078388f, 0.03228654f, -0.21927285f, 0.31769949f,
2951 -0.15623444f, 0.29122451f, 0.01910332f, -0.04202903f, 0.00968366f, 0.16359015f,
2952 -0.68516040f, 0.63582867f, -0.00109283f, 0.58284295f, 0.05969203f, -0.21295355f,
2953 0.05515395f, -0.00684198f, 0.00752595f, 0.08107361f, -0.23775679f, 0.13465045f,
2954 0.08307083f, 0.12342957f, 0.02071366f, -0.10553761f, 0.04286456f, -0.00436760f,
2955 /* Blue colour */
2956 6.20359039f, -2.01196527f, 4.62752008f, -1.84430146f, 0.0f, 0.0f,
2957 0.0f, 0.0f, 0.0f, 0.12955792f, -0.87988776f, 1.27484941f,
2958 -0.62693024f, 1.16861200f, 0.07665691f, -0.16865209f, 0.0f, 0.0f,
2959 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
2960 0.0f, 0.02573379f, -0.02830632f, -0.30493096f, 0.89424169f, -0.50644207f,
2961 -0.31244281f, -0.46423855f, -0.07790744f, 0.39694402f, -0.16122055f, 0.01642723f,
2963 0.82871687f, -0.50163919f, 1.15377009f, -0.45983589f, 0.33362597f, -0.83709794f,
2964 0.91823828f, -0.76733971f, -0.02906591f, -0.08894017f, 0.60403383f, -0.87517095f,
2965 0.43038112f, -0.80224001f, -0.05262417f, 0.11577792f, -0.00965224f, -0.16305926f,
2966 0.68293691f, -0.63376528f, 0.00108928f, -0.58095151f, -0.05949831f, 0.21226248f,
2967 -0.05497497f, 0.01491288f, -0.01640368f, -0.17670928f, 0.51821834f, -0.29348618f,
2968 -0.18106246f, -0.26902896f, -0.04514782f, 0.23003140f, -0.09342826f, 0.00951968f,
2970 4.02387333f, -1.76357520f, 4.05622292f, -1.61661065f, 0.47565711f, -1.19346702f,
2971 1.30915034f, -1.09401131f, -0.04143983f, 0.04346266f, -0.29517499f, 0.42767239f,
2972 -0.21031560f, 0.39203301f, 0.02571601f, -0.05657754f, 0.01303570f, 0.22021750f,
2973 -0.92233127f, 0.85592318f, -0.00147112f, 0.78459626f, 0.08035465f, -0.28666824f,
2974 0.07424571f, -0.00921036f, 0.01013109f, 0.10913756f, -0.32005721f, 0.18126021f,
2975 0.11182612f, 0.16615519f, 0.02788378f, -0.14206986f, 0.05770230f, -0.00587946f, };
2976 struct
2978 FLOAT *red_received, *green_received, *blue_received;
2979 const FLOAT *red_expected, *green_expected, *blue_expected;
2980 FLOAT radius, roffset, goffset, boffset;
2981 } test[] = {
2982 { rout, gout, bout, table, &table[108], &table[216], 17.4f, 1.01f, 1.02f, 1.03f, },
2983 { rout, gout, bout, &table[36], &table[144], &table[252], 1.6f, 1.01f, 1.02f, 1.03f, },
2984 { rout, gout, bout, &table[72], &table[180], &table[288], -3.0f, 1.01f, 1.02f, 1.03f, },
2985 { rout, rout, rout, &table[216], &table[216], &table[216], 17.4f, 1.03f, 1.03f, 1.03f, },
2986 { rout, rout, bout, &table[108], &table[108], &table[216], 17.4, 1.02f, 1.02f, 1.03f, },
2987 { rout, gout, gout, table, &table[216], &table[216], 17.4f, 1.01f, 1.03f, 1.03f, },
2988 { rout, gout, rout, &table[216], &table[108], &table[216], 17.4f, 1.03f, 1.02f, 1.03f, },
2989 /* D3DXSHEvalSphericalLight accepts NULL green or blue colour. */
2990 { rout, NULL, bout, table, NULL, &table[216], 17.4f, 1.01f, 0.0f, 1.03f, },
2991 { rout, gout, NULL, table, &table[108], NULL, 17.4f, 1.01f, 1.02f, 0.0f, },
2992 { rout, NULL, NULL, table, NULL, NULL, 17.4f, 1.01f, 0.0f, 0.0f, }, };
2993 HRESULT hr;
2994 unsigned int j, l, order;
2996 dir.x = 1.1f; dir.y = 1.2f; dir.z = 2.76f;
2998 for (l = 0; l < sizeof(test) / sizeof(test[0]); l++)
3000 for (order = D3DXSH_MINORDER; order <= D3DXSH_MAXORDER; order++)
3002 for (j = 0; j < 49; j++)
3004 test[l].red_received[j] = 1.01f + j;
3005 if (test[l].green_received)
3006 test[l].green_received[j] = 1.02f + j;
3007 if (test[l].blue_received)
3008 test[l].blue_received[j] = 1.03f + j;
3011 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);
3012 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3014 for (j = 0; j < 49; j++)
3016 if (j >= order * order)
3017 expected = j + test[l].roffset;
3018 else
3019 expected = test[l].red_expected[j];
3020 ok(relative_error(expected, test[l].red_received[j]) < 0.0005f,
3021 "Red: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].red_received[j]);
3023 if (test[l].green_received)
3025 if (j >= order * order)
3026 expected = j + test[l].goffset;
3027 else
3028 expected = test[l].green_expected[j];
3029 ok(relative_error(expected, test[l].green_received[j]) < 0.0005f,
3030 "Green: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].green_received[j]);
3033 if (test[l].blue_received)
3035 if (j >= order * order)
3036 expected = j + test[l].boffset;
3037 else
3038 expected = test[l].blue_expected[j];
3039 ok(relative_error(expected, test[l].blue_received[j]) < 0.0005f,
3040 "Blue: case %u, order %u: expected[%u] = %f, received %f\n", l, order, j, expected, test[l].blue_received[j]);
3046 /* D3DXSHEvalSphericalLight accepts order < D3DXSH_MINORDER or order > D3DXSH_MAXORDER. But tests in native windows show that the colour outputs are not set */
3047 hr = D3DXSHEvalSphericalLight(7, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3048 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3049 hr = D3DXSHEvalSphericalLight(0, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3050 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3051 hr = D3DXSHEvalSphericalLight(1, &dir, 17.4f, 1.0f, 2.0f, 3.0f, rout, gout, bout);
3052 ok(hr == D3D_OK, "Expected %#x, got %#x\n", D3D_OK, hr);
3055 static void test_D3DXSHMultiply2(void)
3057 unsigned int i;
3058 FLOAT a[20], b[20], c[20];
3059 /* D3DXSHMultiply2 only modifies the first 4 elements of the array */
3060 const FLOAT expected[20] =
3061 { 3.418594f, 1.698211f, 1.703853f, 1.709494f, 4.0f, 5.0f,
3062 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
3063 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
3065 for (i = 0; i < 20; i++)
3067 a[i] = 1.0f + i / 100.0f;
3068 b[i] = 3.0f - i / 100.0f;
3069 c[i] = i;
3072 D3DXSHMultiply2(c, a, b);
3073 for (i = 0; i < 20; i++)
3074 ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]);
3077 static void test_D3DXSHMultiply3(void)
3079 unsigned int i;
3080 FLOAT a[20], b[20], c[20];
3081 /* D3DXSHMultiply3 only modifies the first 9 elements of the array */
3082 const FLOAT expected[20] =
3083 { 7.813913f, 2.256058f, 5.9484005f, 4.970894f, 2.899858f, 3.598946f,
3084 1.726572f, 5.573538f, 0.622063f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
3085 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
3087 for (i = 0; i < 20; i++)
3089 a[i] = 1.0f + i / 100.0f;
3090 b[i] = 3.0f - i / 100.0f;
3091 c[i] = i;
3094 D3DXSHMultiply3(c, a, b);
3095 for (i = 0; i < 20; i++)
3096 ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]);
3099 static void test_D3DXSHMultiply4(void)
3101 unsigned int i;
3102 FLOAT a[20], b[20], c[20];
3103 /* D3DXSHMultiply4 only modifies the first 16 elements of the array */
3104 const FLOAT expected[] =
3105 { /* c, a, b */
3106 14.182599f, 2.615703f, 12.828601f, 9.820596f, 3.039696f, 4.530442f,
3107 5.820584f, 12.249846f, 2.194346f, 3.900152f, 5.416609f, 5.601813f,
3108 0.959982f, 7.037550f, 3.625230f, 0.463601f, 16.0f, 17.0f, 18.0f, 19.0f,
3109 /* c, c, b */
3110 -211441.265625f, -2529.157715f, -10023.393555f, -441.277191f, -163.994385f,
3111 -526.305115f, 29636.187500f, -3931.830811f, -13577.111328f, -3978.973877f,
3112 -10330.341797f, -13779.787109f, -16685.109375f, -44981.375000f, -73269.742188f,
3113 -95237.335938f, 16.0f, 17.0f, 18.0f, 19.0f,
3114 /* c, c, c */
3115 0.236682f, -0.717649f, -0.180500f, -0.077124f, 0.144831f, 0.573286f,
3116 -0.337959f, 0.055694f, -0.442100f, 0.147702f, -0.055157f, 0.084337f,
3117 0.179877f, 0.009099f, 0.232200f, 0.074142f, 1.6f, 1.7f, 1.8f, 1.9f, };
3119 for (i = 0; i < 20; i++)
3121 a[i] = 1.0f + i / 100.0f;
3122 b[i] = 3.0f - i / 100.0f;
3123 c[i] = i;
3126 D3DXSHMultiply4(c, a, b);
3127 for (i = 0; i < 20; i++)
3128 ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]);
3130 for (i = 0; i < 20; i++)
3132 b[i] = 3.0f - i / 100.0f;
3133 c[i] = i;
3136 D3DXSHMultiply4(c, c, b);
3137 for (i = 0; i < 20; i++)
3138 ok(relative_error(c[i], expected[20 + i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[20 + i], c[i]);
3140 for (i = 0; i < 20; i++)
3141 c[i] = 0.1f * i;
3143 D3DXSHMultiply4(c, c, c);
3144 for (i = 0; i < 20; i++)
3145 ok(relative_error(c[i], expected[40 + i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[40 + i], c[i]);
3148 static void test_D3DXSHRotate(void)
3150 D3DXMATRIX m[4];
3151 FLOAT expected, in[49], out[49], *out_temp, *received_ptr;
3152 static const FLOAT table[]=
3153 { /* Rotation around X-axis Pi/2 */
3154 1.01f, -3.01f, 2.01f, 4.01f, -8.01f, -6.01f,
3155 -11.307890f, 5.01f, -1.565839f, 1.093598f, -11.01f, 19.833414f,
3156 -15.268191f, -19.004118f, -3.364889f, -9.562627f, 12.099654f, -0.272131f,
3157 30.241013f, 26.919991f, 39.236877f, -22.632446f, 6.707388f, -11.768282f,
3158 3.443672f, -6.07445f, 11.61839f, 1.527561f, 37.89633f, -56.9012f,
3159 47.42289f, 50.39153f, 10.61819f, 25.50101f, 0.049241f, 16.98330f,
3161 1.01f, -3.01f, -3.01f, 4.01f, -8.01f, -6.01f, -11.307889f, -8.01f, 14.297919f,
3162 /* Rotation around X-axis -Pi/2 */
3163 1.01f, 3.01f, -2.01f, 4.01f, 8.01f, -6.01f,
3164 -11.307890f, -5.01f, -1.565839f, -1.093598f, -11.01f, -19.833414f,
3165 15.268191f, -19.004118f, 3.364889f, -9.562627f, -12.099654f, -0.272131f,
3166 -30.241013f, 26.919991f, 39.236877f, 22.632446f, 6.707388f, 11.768282f,
3167 3.443672f, 6.07445f, 11.61839f, -1.527561f, 37.89633f, 56.9012f,
3168 -47.42289f, 50.39153f, -10.61819f, 25.50101f, -0.049248f, 16.98330f,
3170 1.01f, 3.01f, -3.01f, 4.01f, 8.01f, -6.01f, -11.307890f, -8.01f, 14.297919f,
3171 /* Yaw Pi/3, Pitch Pi/4, Roll Pi/5 */
3172 1.01f, 4.944899f, 1.442301f, 1.627281f, 0.219220f, 10.540824f,
3173 -9.136903f, 2.763750f, -7.30904f, -5.875721f, 5.303124f, -8.682154f,
3174 -25.683384f, 1.680279f, -18.808388f, 7.653656f, 16.939133f, -17.328018f,
3175 14.629795f, -54.467102f, -12.231035f, -4.089857f, -9.444222f, 3.056035f,
3176 0.179257f, -10.041875f, 23.090092f, -23.188709f, 11.727098f, -65.183090f,
3177 48.671577f, -15.073209f, 38.793171f, -26.039536f, 6.192769f, -17.672247f,
3179 1.01f, 4.944899f, -0.891142f, 4.607695f, 0.219218f, 10.773325f,
3180 -8.204769f, 13.563829f, -12.007767f,
3181 /* Rotation around Z-axis Pi/6 */
3182 1.01f, 3.745711f, 3.01f, 2.467762f, 10.307889f, 9.209813f,
3183 7.01f, 3.931864f, 0.166212f, 16.01f, 18.504042f, 17.405966f,
3184 13.01f, 6.128016f, -2.029941f, -10.01f, 13.154292f, 24.01f,
3185 29.432245f, 28.334167f, 21.01f, 9.056221f, -4.958143f, -18.01f,
3186 -27.236094f, -4.520332f, 16.814543f, 34.01f, 43.092495f, 41.994423f,
3187 31.01f, 12.716471f, -8.618400f, -28.01f, -40.896347f, -44.190571,
3189 1.01f, 3.745711f, 3.01f, 1.599906f, 10.307889f, 9.209813f,
3190 7.01f, 2.331957f, -4.421894f, };
3191 unsigned int i, j, l, order;
3193 D3DXMatrixRotationX(&m[0], -D3DX_PI / 2.0f);
3194 D3DXMatrixRotationX(&m[1], D3DX_PI / 2.0f);
3195 D3DXMatrixRotationYawPitchRoll(&m[2], D3DX_PI / 3.0f, D3DX_PI / 4.0f, D3DX_PI / 5.0f);
3196 D3DXMatrixRotationZ(&m[3], D3DX_PI / 6.0f);
3198 for (l = 0; l < 2; l++)
3200 if (l == 0)
3201 out_temp = out;
3202 else
3203 out_temp = in;
3205 for (j = 0; j < 4; j++)
3207 for (order = 0; order <= D3DXSH_MAXORDER; order++)
3209 for (i = 0; i < 49; i++)
3211 out[i] = ( i + 1.0f ) * ( i + 1.0f );
3212 in[i] = i + 1.01f;
3215 received_ptr = D3DXSHRotate(out_temp, order, &m[j], in);
3216 ok(received_ptr == out_temp, "Order %u, expected %p, received %p\n", order, out, received_ptr);
3218 for (i = 0; i < 49; i++)
3220 if ((i > 0) && ((i >= order * order) || (order > D3DXSH_MAXORDER)))
3222 if (l == 0)
3223 expected = ( i + 1.0f ) * ( i + 1.0f );
3224 else
3225 expected = i + 1.01f;
3227 else if ((l == 0) || (order > 3))
3228 expected = table[45 * j + i];
3229 else
3230 expected = table[45 * j + 36 +i];
3231 ok(relative_error(out_temp[i], expected) < admitted_error,
3232 "Order %u index %u, expected %f, received %f\n", order, i, expected, out_temp[i]);
3239 static void test_D3DXSHRotateZ(void)
3241 unsigned int end, i, j, l, order, square;
3242 FLOAT expected, in[49], out[49], *out_temp, *received_ptr;
3243 const FLOAT angle[] = { D3DX_PI / 3.0f, -D3DX_PI / 3.0f, 4.0f * D3DX_PI / 3.0f, }, table[] =
3244 { /* Angle = D3DX_PI / 3.0f */
3245 1.01f, 4.477762f, 3.010000f, 0.264289f, 5.297888f, 9.941864f,
3246 7.010000f, -1.199813f, -8.843789f, -10.010002f, 7.494040f, 18.138016f,
3247 13.010000, -3.395966f, -17.039942f, -16.009998f, -30.164297f, -18.010004f,
3248 10.422242f, 29.066219f, 21.010000f, -6.324171f, -27.968145f, -24.009998f,
3249 2.226099f, -18.180565, -43.824551f, -28.010004f, 14.082493f, 42.726471f,
3250 31.010000f, -9.984426f, -41.628399f, -34.009995f, 5.886358f, 40.530331f,
3252 1.01f, 4.477762f, 0.0f, -5.816784f, 5.297888f, 6.936864f,
3253 0.0f, -9.011250f, -2.294052f, -10.010002f, 12.999042f, 12.133017f,
3254 0.0f, -15.761250f, -5.628748f, 0.0f, -30.164297f, 0.0f,
3255 19.927244f, 19.061220f, 0.0f, -24.761251f, -8.628748f, 0.0f,
3256 -13.061530f, -18.180565f, -30.319553f, 0.0f, 28.587496f, 27.721474f,
3257 0.0f, -36.011253f, -12.378746f, 0.0f, -13.128758f, -23.617250f,
3259 1.010000f, 3.977762f, 3.977762f, 1.114195f, 7.245791f, 10.559759f,
3260 10.559759f, -0.995160f, -0.467341f, 0.467339f, 12.765371f, 18.515701f,
3261 18.515701f, -1.797287f, 0.493916f, -0.493916f, -21.412342f, 21.412338f,
3262 9.221072f, 23.671757f, 23.671757f, 3.850195f, -20.468727f, 20.468723f,
3263 -10.662103f, -36.516628f, -12.061245f, 12.061240f, 22.556875f, 38.999908f,
3264 38.999908f, -0.034875f, -10.427902f, 10.427900f, -36.838284f, -27.652803f,
3265 /* Angle = -D3DX_PI / 3.0f */
3266 1.01f, -2.467762f, 3.010000f, 3.745711f, -10.307890f, -3.931864f,
3267 7.010000f, 9.209813f, -0.166214f, -10.010002f, -18.504044f, -6.128017f,
3268 13.010000f, 17.405966f, 2.029938f, -16.009998f, 13.154303f, -18.010004f,
3269 -29.432247f, -9.056221f, 21.010000f, 28.334169f, 4.958139f, -24.010002f,
3270 -27.236092f, 44.190582f, 16.814558f, -28.009996f, -43.092499f, -12.716474f,
3271 31.010000f, 41.994423f, 8.618393f, -34.010002f, -40.896347f, -4.520310f,
3273 1.01f, -2.467762f, 0.0f, -3.205718f, -10.307890f, -6.936864f,
3274 0.0f, -9.011250f, -4.463446f, -10.009998f, -12.999042f, -12.133017f,
3275 0.0f, -15.761250f, -5.628748f, 0.0f, 13.154303f, 0.0f,
3276 -19.927244f, -19.061220f, 0.0f, -24.761251f, -8.628748f, 0.0f,
3277 -5.695983f, 44.190582f, 30.319553f, 0.0f, -28.587496f, -27.721474f,
3278 0.0f, -36.011253f, -12.378746f, 0.0f, -13.128758f, -57.405258f,
3280 1.010000f, -2.967762f, -2.967762f, -0.609195f, -7.498291f, -10.686009f,
3281 -10.686009f, -11.836716f, 5.390780f, -5.390779f, -10.303651f, -17.284842f,
3282 -17.284842f, -17.565643f, 4.114273f, -4.114273f, 23.716436f, -23.716433f,
3283 -8.069025f, -23.095732f, -23.095732f, -18.535847f, -11.271107f, 11.271104f,
3284 -2.072484f, 30.149330f, 15.244893f, -15.244888f, -20.965050f, -38.203999f,
3285 -38.203999f, -37.258266f, 5.426677f, -5.426679f, -23.396751f, -9.903559f,
3286 /* Angle = 4.0f * D3DX_PI / 3.0f */
3287 1.01f, -4.477762f, 3.010000f, -0.264289f, 5.297887f, -9.941864f,
3288 7.010000f, 1.199814f, -8.843788f, 10.010004f, 7.494038f, -18.138016f,
3289 13.010000f, 3.395967f, -17.039940f, 16.009996f, -30.164293f, 18.010006f,
3290 10.422239f, -29.066219f, 21.010000f, 6.324172f, -27.968143f, 24.009993f,
3291 2.226105f, 18.180552f, -43.824543f, 28.010008f, 14.082489f, -42.726471f,
3292 31.010000f, 9.984427f, -41.628399f, 34.009987f, 5.886366f, -40.530327f,
3294 1.01f, -4.477762f, 0.0f, -1.938928f, 5.297887f, -6.936864f,
3295 0.0f, -3.003751f, -2.294051f, 10.010004f, 12.999040f, -12.133017f,
3296 0.0f, -5.253751f, -5.628747f, 0.0f, -30.164293f, 0.0f,
3297 19.927242f, -19.061220f, 0.0f, -8.253753f, -8.628746f, 0.0f,
3298 -13.061535f, 18.180552f, -30.319553f, 0.0f, 28.587492f, -27.721474f,
3299 0.0f, -12.003753f, -12.378742f, 0.0f, -13.128765f, -7.872400f,
3301 1.010000f, -3.977762f, -3.977762f, 2.863566f, 6.371104f, -10.122416f,
3302 -10.122416f, 10.578746f, -7.769295f, -7.769290f, 16.883686f, -20.574858f,
3303 -20.574858f, 24.909130f, -5.726166f, -5.726164f, -18.796221f, -18.796211f,
3304 29.325350f, -33.723892f, -33.723892f, 42.258442f, -4.851232f, -4.851226f,
3305 -2.533393f, 32.452259f, -46.545670f, -46.545654f, 51.860325f, -53.651630f,
3306 -53.651630f, 71.738174f, 4.440616f, 4.440629f, 25.884174f, -10.748116f, };
3308 for (l = 0; l < 3; l++)
3310 if (l == 0)
3311 out_temp = out;
3312 else
3313 out_temp = &in[l - 1];
3315 if (l < 2)
3316 end = 49;
3317 else
3318 end = 48;
3320 for (j = 0; j < 3; j++)
3322 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
3324 for (i = 0; i < 49; i++)
3326 out[i] = ( i + 1.0f ) * ( i + 1.0f );
3327 in[i] = i + 1.01f;
3330 received_ptr = D3DXSHRotateZ(out_temp, order, angle[j], in);
3331 ok(received_ptr == out_temp, "angle %f, order %u, expected %p, received %p\n", angle[j], order, out_temp, received_ptr);
3333 for (i = 0; i < end; i++)
3335 /* order = 0 or order = 1 behaves like order = D3DXSH_MINORDER */
3336 square = (order <= D3DXSH_MINORDER) ? D3DXSH_MINORDER * D3DXSH_MINORDER : order * order;
3337 if (i >= square || ((order >= D3DXSH_MAXORDER) && (i >= D3DXSH_MAXORDER * D3DXSH_MAXORDER)))
3338 if (l > 0)
3339 expected = i + l + 0.01f;
3340 else
3341 expected = ( i + 1.0f ) * ( i + 1.0f );
3342 else
3343 expected = table[36 * (l + 3 * j) + i];
3344 ok(relative_error(expected, out_temp[i]) < admitted_error, "angle %f, order %u index %u, expected %f, received %f\n", angle[j], order, i, expected, out_temp[i]);
3351 static void test_D3DXSHScale(void)
3353 unsigned int i, order;
3354 FLOAT a[49], b[49], expected, *received_array;
3356 for (i = 0; i < 49; i++)
3358 a[i] = i;
3359 b[i] = i;
3362 for (order = 0; order <= D3DXSH_MAXORDER + 1; order++)
3364 received_array = D3DXSHScale(b, order, a, 5.0f);
3365 ok(received_array == b, "Expected %p, received %p\n", b, received_array);
3367 for (i = 0; i < 49; i++)
3369 if (i < order * order)
3370 expected = 5.0f * a[i];
3371 /* D3DXSHScale does not modify the elements of the array after the order * order-th element */
3372 else
3373 expected = a[i];
3374 ok(relative_error(b[i], expected) < admitted_error, "order %d, element %d, expected %f, received %f\n", order, i, expected, b[i]);
3379 START_TEST(math)
3381 D3DXColorTest();
3382 D3DXFresnelTest();
3383 D3DXMatrixTest();
3384 D3DXPlaneTest();
3385 D3DXQuaternionTest();
3386 D3DXVector2Test();
3387 D3DXVector3Test();
3388 D3DXVector4Test();
3389 test_matrix_stack();
3390 test_Matrix_AffineTransformation2D();
3391 test_Matrix_Decompose();
3392 test_Matrix_Transformation2D();
3393 test_D3DXVec_Array();
3394 test_D3DXFloat_Array();
3395 test_D3DXSHAdd();
3396 test_D3DXSHDot();
3397 test_D3DXSHEvalConeLight();
3398 test_D3DXSHEvalDirection();
3399 test_D3DXSHEvalDirectionalLight();
3400 test_D3DXSHEvalHemisphereLight();
3401 test_D3DXSHEvalSphericalLight();
3402 test_D3DXSHMultiply2();
3403 test_D3DXSHMultiply3();
3404 test_D3DXSHMultiply4();
3405 test_D3DXSHRotate();
3406 test_D3DXSHRotateZ();
3407 test_D3DXSHScale();