2 * Copyright 2008 David Adam
3 * Copyright 2008 Philip Nilsson
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/test.h"
25 #define admitted_error 0.0001f
27 #define relative_error(exp, out) ((exp == out) ? 0.0f : (fabs(out - exp) / fabs(exp)))
29 static inline BOOL
compare_matrix(const D3DXMATRIX
*m1
, const D3DXMATRIX
*m2
)
33 for (i
= 0; i
< 4; ++i
)
35 for (j
= 0; j
< 4; ++j
)
37 if (fabs(U(*m1
).m
[i
][j
] - U(*m2
).m
[i
][j
]) > admitted_error
)
45 #define expect_mat(expectedmat, gotmat) \
47 const D3DXMATRIX *__m1 = (expectedmat); \
48 const D3DXMATRIX *__m2 = (gotmat); \
49 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" \
50 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
51 U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
52 U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
53 U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
54 U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
55 U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
56 U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
57 U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
58 U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
61 #define compare_rotation(exp, got) \
62 ok(fabs(exp.w - got.w) < admitted_error && \
63 fabs(exp.x - got.x) < admitted_error && \
64 fabs(exp.y - got.y) < admitted_error && \
65 fabs(exp.z - got.z) < admitted_error, \
66 "Expected rotation = (%f, %f, %f, %f), \
67 got rotation = (%f, %f, %f, %f)\n", \
68 exp.w, exp.x, exp.y, exp.z, got.w, got.x, got.y, got.z)
70 #define compare_scale(exp, got) \
71 ok(fabs(exp.x - got.x) < admitted_error && \
72 fabs(exp.y - got.y) < admitted_error && \
73 fabs(exp.z - got.z) < admitted_error, \
74 "Expected scale = (%f, %f, %f), \
75 got scale = (%f, %f, %f)\n", \
76 exp.x, exp.y, exp.z, got.x, got.y, got.z)
78 #define compare_translation(exp, got) \
79 ok(fabs(exp.x - got.x) < admitted_error && \
80 fabs(exp.y - got.y) < admitted_error && \
81 fabs(exp.z - got.z) < admitted_error, \
82 "Expected translation = (%f, %f, %f), \
83 got translation = (%f, %f, %f)\n", \
84 exp.x, exp.y, exp.z, got.x, got.y, got.z)
86 #define compare_vectors(exp, out) \
87 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
88 ok(relative_error(exp[i].x, out[i].x) < admitted_error && \
89 relative_error(exp[i].y, out[i].y) < admitted_error && \
90 relative_error(exp[i].z, out[i].z) < admitted_error && \
91 relative_error(exp[i].w, out[i].w) < admitted_error, \
92 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
93 out[i].x, out[i].y, out[i].z, out[i].w, \
94 exp[i].x, exp[i].y, exp[i].z, exp[i].w, \
98 #define compare_planes(exp, out) \
99 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
100 ok(relative_error(exp[i].a, out[i].a) < admitted_error && \
101 relative_error(exp[i].b, out[i].b) < admitted_error && \
102 relative_error(exp[i].c, out[i].c) < admitted_error && \
103 relative_error(exp[i].d, out[i].d) < admitted_error, \
104 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
105 out[i].a, out[i].b, out[i].c, out[i].d, \
106 exp[i].a, exp[i].b, exp[i].c, exp[i].d, \
110 /* The mathematical properties are checked in the d3dx8 testsuite.
113 * That the functions work.
114 * That the stride functionality works.
115 * That nothing is written where it should not be.
117 * These tests should check:
118 * That inp_vec is not modified.
119 * That the input and output arrays can be the same (MSDN
120 * says they can, and some testing with a native DLL
124 static void test_Matrix_AffineTransformation2D(void)
126 D3DXMATRIX exp_mat
, got_mat
;
127 D3DXVECTOR2 center
, position
;
136 angle
= D3DX_PI
/3.0f
;
140 U(exp_mat
).m
[0][0] = 10.0f
;
141 U(exp_mat
).m
[1][0] = -17.320507f
;
142 U(exp_mat
).m
[2][0] = 0.0f
;
143 U(exp_mat
).m
[3][0] = -1.035898f
;
144 U(exp_mat
).m
[0][1] = 17.320507f
;
145 U(exp_mat
).m
[1][1] = 10.0f
;
146 U(exp_mat
).m
[2][1] = 0.0f
;
147 U(exp_mat
).m
[3][1] = 6.401924f
;
148 U(exp_mat
).m
[0][2] = 0.0f
;
149 U(exp_mat
).m
[1][2] = 0.0f
;
150 U(exp_mat
).m
[2][2] = 20.0f
;
151 U(exp_mat
).m
[3][2] = 0.0f
;
152 U(exp_mat
).m
[0][3] = 0.0f
;
153 U(exp_mat
).m
[1][3] = 0.0f
;
154 U(exp_mat
).m
[2][3] = 0.0f
;
155 U(exp_mat
).m
[3][3] = 1.0f
;
157 D3DXMatrixAffineTransformation2D(&got_mat
, scale
, ¢er
, angle
, &position
);
159 expect_mat(&exp_mat
, &got_mat
);
166 angle
= D3DX_PI
/3.0f
;
170 U(exp_mat
).m
[0][0] = 10.0f
;
171 U(exp_mat
).m
[1][0] = -17.320507f
;
172 U(exp_mat
).m
[2][0] = 0.0f
;
173 U(exp_mat
).m
[3][0] = 4.964102f
;
174 U(exp_mat
).m
[0][1] = 17.320507f
;
175 U(exp_mat
).m
[1][1] = 10.0f
;
176 U(exp_mat
).m
[2][1] = 0.0f
;
177 U(exp_mat
).m
[3][1] = -0.598076f
;
178 U(exp_mat
).m
[0][2] = 0.0f
;
179 U(exp_mat
).m
[1][2] = 0.0f
;
180 U(exp_mat
).m
[2][2] = 20.0f
;
181 U(exp_mat
).m
[3][2] = 0.0f
;
182 U(exp_mat
).m
[0][3] = 0.0f
;
183 U(exp_mat
).m
[1][3] = 0.0f
;
184 U(exp_mat
).m
[2][3] = 0.0f
;
185 U(exp_mat
).m
[3][3] = 1.0f
;
187 D3DXMatrixAffineTransformation2D(&got_mat
, scale
, ¢er
, angle
, NULL
);
189 expect_mat(&exp_mat
, &got_mat
);
196 angle
= D3DX_PI
/3.0f
;
200 U(exp_mat
).m
[0][0] = 10.0f
;
201 U(exp_mat
).m
[1][0] = -17.320507f
;
202 U(exp_mat
).m
[2][0] = 0.0f
;
203 U(exp_mat
).m
[3][0] = -6.0f
;
204 U(exp_mat
).m
[0][1] = 17.320507f
;
205 U(exp_mat
).m
[1][1] = 10.0f
;
206 U(exp_mat
).m
[2][1] = 0.0f
;
207 U(exp_mat
).m
[3][1] = 7.0f
;
208 U(exp_mat
).m
[0][2] = 0.0f
;
209 U(exp_mat
).m
[1][2] = 0.0f
;
210 U(exp_mat
).m
[2][2] = 20.0f
;
211 U(exp_mat
).m
[3][2] = 0.0f
;
212 U(exp_mat
).m
[0][3] = 0.0f
;
213 U(exp_mat
).m
[1][3] = 0.0f
;
214 U(exp_mat
).m
[2][3] = 0.0f
;
215 U(exp_mat
).m
[3][3] = 1.0f
;
217 D3DXMatrixAffineTransformation2D(&got_mat
, scale
, NULL
, angle
, &position
);
219 expect_mat(&exp_mat
, &got_mat
);
223 angle
= 5.0f
* D3DX_PI
/4.0f
;
227 U(exp_mat
).m
[0][0] = 14.142133f
;
228 U(exp_mat
).m
[1][0] = -14.142133f
;
229 U(exp_mat
).m
[2][0] = 0.0f
;
230 U(exp_mat
).m
[3][0] = 0.0f
;
231 U(exp_mat
).m
[0][1] = 14.142133;
232 U(exp_mat
).m
[1][1] = 14.142133f
;
233 U(exp_mat
).m
[2][1] = 0.0f
;
234 U(exp_mat
).m
[3][1] = 0.0f
;
235 U(exp_mat
).m
[0][2] = 0.0f
;
236 U(exp_mat
).m
[1][2] = 0.0f
;
237 U(exp_mat
).m
[2][2] = -20.0f
;
238 U(exp_mat
).m
[3][2] = 0.0f
;
239 U(exp_mat
).m
[0][3] = 0.0f
;
240 U(exp_mat
).m
[1][3] = 0.0f
;
241 U(exp_mat
).m
[2][3] = 0.0f
;
242 U(exp_mat
).m
[3][3] = 1.0f
;
244 D3DXMatrixAffineTransformation2D(&got_mat
, scale
, NULL
, angle
, NULL
);
246 expect_mat(&exp_mat
, &got_mat
);
249 static void test_Matrix_Decompose(void)
252 D3DXQUATERNION exp_rotation
, got_rotation
;
253 D3DXVECTOR3 exp_scale
, got_scale
, exp_translation
, got_translation
;
258 U(pm
).m
[0][0] = -0.9238790f
;
259 U(pm
).m
[1][0] = -0.2705984f
;
260 U(pm
).m
[2][0] = 0.2705984f
;
261 U(pm
).m
[3][0] = -5.0f
;
262 U(pm
).m
[0][1] = 0.2705984f
;
263 U(pm
).m
[1][1] = 0.03806049f
;
264 U(pm
).m
[2][1] = 0.9619395f
;
265 U(pm
).m
[3][1] = 0.0f
;
266 U(pm
).m
[0][2] = -0.2705984f
;
267 U(pm
).m
[1][2] = 0.9619395f
;
268 U(pm
).m
[2][2] = 0.03806049f
;
269 U(pm
).m
[3][2] = 10.0f
;
270 U(pm
).m
[0][3] = 0.0f
;
271 U(pm
).m
[1][3] = 0.0f
;
272 U(pm
).m
[2][3] = 0.0f
;
273 U(pm
).m
[3][3] = 1.0f
;
279 exp_rotation
.w
= 0.195091f
;
280 exp_rotation
.x
= 0.0f
;
281 exp_rotation
.y
= 0.693520f
;
282 exp_rotation
.z
= 0.693520f
;
284 exp_translation
.x
= -5.0f
;
285 exp_translation
.y
= 0.0f
;
286 exp_translation
.z
= 10.0f
;
288 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
290 compare_scale(exp_scale
, got_scale
);
291 compare_rotation(exp_rotation
, got_rotation
);
292 compare_translation(exp_translation
, got_translation
);
296 U(pm
).m
[0][0] = -2.255813f
;
297 U(pm
).m
[1][0] = 1.302324f
;
298 U(pm
).m
[2][0] = 1.488373f
;
299 U(pm
).m
[3][0] = 1.0f
;
300 U(pm
).m
[0][1] = 1.302327f
;
301 U(pm
).m
[1][1] = -0.7209296f
;
302 U(pm
).m
[2][1] = 2.60465f
;
303 U(pm
).m
[3][1] = 2.0f
;
304 U(pm
).m
[0][2] = 1.488371f
;
305 U(pm
).m
[1][2] = 2.604651f
;
306 U(pm
).m
[2][2] = -0.02325551f
;
307 U(pm
).m
[3][2] = 3.0f
;
308 U(pm
).m
[0][3] = 0.0f
;
309 U(pm
).m
[1][3] = 0.0f
;
310 U(pm
).m
[2][3] = 0.0f
;
311 U(pm
).m
[3][3] = 1.0f
;
317 exp_rotation
.w
= 0.0;
318 exp_rotation
.x
= 0.352180f
;
319 exp_rotation
.y
= 0.616316f
;
320 exp_rotation
.z
= 0.704361f
;
322 exp_translation
.x
= 1.0f
;
323 exp_translation
.y
= 2.0f
;
324 exp_translation
.z
= 3.0f
;
326 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
328 compare_scale(exp_scale
, got_scale
);
329 compare_rotation(exp_rotation
, got_rotation
);
330 compare_translation(exp_translation
, got_translation
);
334 U(pm
).m
[0][0] = 2.427051f
;
335 U(pm
).m
[1][0] = 0.0f
;
336 U(pm
).m
[2][0] = 1.763355f
;
337 U(pm
).m
[3][0] = 5.0f
;
338 U(pm
).m
[0][1] = 0.0f
;
339 U(pm
).m
[1][1] = 3.0f
;
340 U(pm
).m
[2][1] = 0.0f
;
341 U(pm
).m
[3][1] = 5.0f
;
342 U(pm
).m
[0][2] = -1.763355f
;
343 U(pm
).m
[1][2] = 0.0f
;
344 U(pm
).m
[2][2] = 2.427051f
;
345 U(pm
).m
[3][2] = 5.0f
;
346 U(pm
).m
[0][3] = 0.0f
;
347 U(pm
).m
[1][3] = 0.0f
;
348 U(pm
).m
[2][3] = 0.0f
;
349 U(pm
).m
[3][3] = 1.0f
;
355 exp_rotation
.w
= 0.951057f
;
356 exp_rotation
.x
= 0.0f
;
357 exp_rotation
.y
= 0.309017f
;
358 exp_rotation
.z
= 0.0f
;
360 exp_translation
.x
= 5.0f
;
361 exp_translation
.y
= 5.0f
;
362 exp_translation
.z
= 5.0f
;
364 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
366 compare_scale(exp_scale
, got_scale
);
367 compare_rotation(exp_rotation
, got_rotation
);
368 compare_translation(exp_translation
, got_translation
);
372 U(pm
).m
[0][0] = -0.9238790f
;
373 U(pm
).m
[1][0] = -0.2705984f
;
374 U(pm
).m
[2][0] = 0.2705984f
;
375 U(pm
).m
[3][0] = -5.0f
;
376 U(pm
).m
[0][1] = 0.2705984f
;
377 U(pm
).m
[1][1] = 0.03806049f
;
378 U(pm
).m
[2][1] = 0.9619395f
;
379 U(pm
).m
[3][1] = 0.0f
;
380 U(pm
).m
[0][2] = -0.2705984f
;
381 U(pm
).m
[1][2] = 0.9619395f
;
382 U(pm
).m
[2][2] = 0.03806049f
;
383 U(pm
).m
[3][2] = 10.0f
;
384 U(pm
).m
[0][3] = 0.0f
;
385 U(pm
).m
[1][3] = 0.0f
;
386 U(pm
).m
[2][3] = 0.0f
;
387 U(pm
).m
[3][3] = 1.0f
;
393 exp_rotation
.w
= 0.195091f
;
394 exp_rotation
.x
= 0.0f
;
395 exp_rotation
.y
= 0.693520f
;
396 exp_rotation
.z
= 0.693520f
;
398 exp_translation
.x
= -5.0f
;
399 exp_translation
.y
= 0.0f
;
400 exp_translation
.z
= 10.0f
;
402 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
404 compare_scale(exp_scale
, got_scale
);
405 compare_rotation(exp_rotation
, got_rotation
);
406 compare_translation(exp_translation
, got_translation
);
410 U(pm
).m
[0][0] = -0.9238790f
;
411 U(pm
).m
[1][0] = -0.5411968f
;
412 U(pm
).m
[2][0] = 0.8117952f
;
413 U(pm
).m
[3][0] = -5.0f
;
414 U(pm
).m
[0][1] = 0.2705984f
;
415 U(pm
).m
[1][1] = 0.07612098f
;
416 U(pm
).m
[2][1] = 2.8858185f
;
417 U(pm
).m
[3][1] = 0.0f
;
418 U(pm
).m
[0][2] = -0.2705984f
;
419 U(pm
).m
[1][2] = 1.9238790f
;
420 U(pm
).m
[2][2] = 0.11418147f
;
421 U(pm
).m
[3][2] = 10.0f
;
422 U(pm
).m
[0][3] = 0.0f
;
423 U(pm
).m
[1][3] = 0.0f
;
424 U(pm
).m
[2][3] = 0.0f
;
425 U(pm
).m
[3][3] = 1.0f
;
431 exp_rotation
.w
= 0.195091f
;
432 exp_rotation
.x
= 0.0f
;
433 exp_rotation
.y
= 0.693520f
;
434 exp_rotation
.z
= 0.693520f
;
436 exp_translation
.x
= -5.0f
;
437 exp_translation
.y
= 0.0f
;
438 exp_translation
.z
= 10.0f
;
440 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
442 compare_scale(exp_scale
, got_scale
);
443 compare_rotation(exp_rotation
, got_rotation
);
444 compare_translation(exp_translation
, got_translation
);
448 U(pm
).m
[0][0] = 0.7156004f
;
449 U(pm
).m
[1][0] = -0.5098283f
;
450 U(pm
).m
[2][0] = -0.4774843f
;
451 U(pm
).m
[3][0] = -5.0f
;
452 U(pm
).m
[0][1] = -0.6612288f
;
453 U(pm
).m
[1][1] = -0.7147621f
;
454 U(pm
).m
[2][1] = -0.2277977f
;
455 U(pm
).m
[3][1] = 0.0f
;
456 U(pm
).m
[0][2] = -0.2251499f
;
457 U(pm
).m
[1][2] = 0.4787385f
;
458 U(pm
).m
[2][2] = -0.8485972f
;
459 U(pm
).m
[3][2] = 10.0f
;
460 U(pm
).m
[0][3] = 0.0f
;
461 U(pm
).m
[1][3] = 0.0f
;
462 U(pm
).m
[2][3] = 0.0f
;
463 U(pm
).m
[3][3] = 1.0f
;
469 exp_rotation
.w
= 0.195091f
;
470 exp_rotation
.x
= 0.905395f
;
471 exp_rotation
.y
= -0.323355f
;
472 exp_rotation
.z
= -0.194013f
;
474 exp_translation
.x
= -5.0f
;
475 exp_translation
.y
= 0.0f
;
476 exp_translation
.z
= 10.0f
;
478 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
480 compare_scale(exp_scale
, got_scale
);
481 compare_rotation(exp_rotation
, got_rotation
);
482 compare_translation(exp_translation
, got_translation
);
486 U(pm
).m
[0][0] = 0.06554436f
;
487 U(pm
).m
[1][0] = -0.6873012f
;
488 U(pm
).m
[2][0] = 0.7234092f
;
489 U(pm
).m
[3][0] = -5.0f
;
490 U(pm
).m
[0][1] = -0.9617381f
;
491 U(pm
).m
[1][1] = -0.2367795f
;
492 U(pm
).m
[2][1] = -0.1378230f
;
493 U(pm
).m
[3][1] = 0.0f
;
494 U(pm
).m
[0][2] = 0.2660144f
;
495 U(pm
).m
[1][2] = -0.6866967f
;
496 U(pm
).m
[2][2] = -0.6765233f
;
497 U(pm
).m
[3][2] = 10.0f
;
498 U(pm
).m
[0][3] = 0.0f
;
499 U(pm
).m
[1][3] = 0.0f
;
500 U(pm
).m
[2][3] = 0.0f
;
501 U(pm
).m
[3][3] = 1.0f
;
507 exp_rotation
.w
= -0.195091f
;
508 exp_rotation
.x
= 0.703358f
;
509 exp_rotation
.y
= -0.586131f
;
510 exp_rotation
.z
= 0.351679f
;
512 exp_translation
.x
= -5.0f
;
513 exp_translation
.y
= 0.0f
;
514 exp_translation
.z
= 10.0f
;
516 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
518 compare_scale(exp_scale
, got_scale
);
519 compare_rotation(exp_rotation
, got_rotation
);
520 compare_translation(exp_translation
, got_translation
);
524 U(pm
).m
[0][0] = 7.121047f
;
525 U(pm
).m
[1][0] = -5.883487f
;
526 U(pm
).m
[2][0] = 11.81843f
;
527 U(pm
).m
[3][0] = -5.0f
;
528 U(pm
).m
[0][1] = 5.883487f
;
529 U(pm
).m
[1][1] = -10.60660f
;
530 U(pm
).m
[2][1] = -8.825232f
;
531 U(pm
).m
[3][1] = 0.0f
;
532 U(pm
).m
[0][2] = 11.81843f
;
533 U(pm
).m
[1][2] = 8.8252320f
;
534 U(pm
).m
[2][2] = -2.727645f
;
535 U(pm
).m
[3][2] = 2.0f
;
536 U(pm
).m
[0][3] = 0.0f
;
537 U(pm
).m
[1][3] = 0.0f
;
538 U(pm
).m
[2][3] = 0.0f
;
539 U(pm
).m
[3][3] = 1.0f
;
545 exp_rotation
.w
= 0.382684f
;
546 exp_rotation
.x
= 0.768714f
;
547 exp_rotation
.y
= 0.0f
;
548 exp_rotation
.z
= 0.512476f
;
550 exp_translation
.x
= -5.0f
;
551 exp_translation
.y
= 0.0f
;
552 exp_translation
.z
= 2.0f
;
554 D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
556 compare_scale(exp_scale
, got_scale
);
557 compare_rotation(exp_rotation
, got_rotation
);
558 compare_translation(exp_translation
, got_translation
);
562 U(pm
).m
[0][0] = 0.0f
;
563 U(pm
).m
[1][0] = 4.0f
;
564 U(pm
).m
[2][0] = 5.0f
;
565 U(pm
).m
[3][0] = -5.0f
;
566 U(pm
).m
[0][1] = 0.0f
;
567 U(pm
).m
[1][1] = -10.60660f
;
568 U(pm
).m
[2][1] = -8.825232f
;
569 U(pm
).m
[3][1] = 6.0f
;
570 U(pm
).m
[0][2] = 0.0f
;
571 U(pm
).m
[1][2] = 8.8252320f
;
572 U(pm
).m
[2][2] = 2.727645;
573 U(pm
).m
[3][2] = 3.0f
;
574 U(pm
).m
[0][3] = 0.0f
;
575 U(pm
).m
[1][3] = 0.0f
;
576 U(pm
).m
[2][3] = 0.0f
;
577 U(pm
).m
[3][3] = 1.0f
;
579 hr
= D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, &pm
);
580 ok(hr
== D3DERR_INVALIDCALL
, "Expected D3DERR_INVALIDCALL, got %x\n", hr
);
584 hr
= D3DXMatrixDecompose(&got_scale
, &got_rotation
, &got_translation
, NULL
);
585 ok(hr
== D3DERR_INVALIDCALL
, "Expected D3DERR_INVALIDCALL, got %x\n", hr
);
588 static void test_Matrix_Transformation2D(void)
590 D3DXMATRIX exp_mat
, got_mat
;
591 D3DXVECTOR2 rot_center
, sca
, sca_center
, trans
;
601 sca_center
.y
= -5.0f
;
608 sca_rot
= 5.0f
*D3DX_PI
/4.0f
;
610 U(exp_mat
).m
[0][0] = -4.245192f
;
611 U(exp_mat
).m
[1][0] = -0.147116f
;
612 U(exp_mat
).m
[2][0] = 0.0f
;
613 U(exp_mat
).m
[3][0] = 45.265373f
;
614 U(exp_mat
).m
[0][1] = 7.647113f
;
615 U(exp_mat
).m
[1][1] = 8.745192f
;
616 U(exp_mat
).m
[2][1] = 0.0f
;
617 U(exp_mat
).m
[3][1] = -13.401899f
;
618 U(exp_mat
).m
[0][2] = 0.0f
;
619 U(exp_mat
).m
[1][2] = 0.0f
;
620 U(exp_mat
).m
[2][2] = 0.0f
;
621 U(exp_mat
).m
[3][2] = 0.0f
;
622 U(exp_mat
).m
[0][3] = 0.0f
;
623 U(exp_mat
).m
[1][3] = 0.0f
;
624 U(exp_mat
).m
[2][3] = 0.0f
;
625 U(exp_mat
).m
[3][3] = 1.0f
;
627 D3DXMatrixTransformation2D(&got_mat
, &sca_center
, sca_rot
, &sca
, &rot_center
, rot
, &trans
);
629 expect_mat(&exp_mat
, &got_mat
);
634 sca_center
.y
= -5.0f
;
641 sca_rot
= 5.0f
*D3DX_PI
/4.0f
;
643 U(exp_mat
).m
[0][0] = 0.0f
;
644 U(exp_mat
).m
[1][0] = 0.0f
;
645 U(exp_mat
).m
[2][0] = 0.0f
;
646 U(exp_mat
).m
[3][0] = 2.830127f
;
647 U(exp_mat
).m
[0][1] = 0.0f
;
648 U(exp_mat
).m
[1][1] = 0.0f
;
649 U(exp_mat
).m
[2][1] = 0.0f
;
650 U(exp_mat
).m
[3][1] = 12.294229f
;
651 U(exp_mat
).m
[0][2] = 0.0f
;
652 U(exp_mat
).m
[1][2] = 0.0f
;
653 U(exp_mat
).m
[2][2] = 0.0f
;
654 U(exp_mat
).m
[3][2] = 0.0f
;
655 U(exp_mat
).m
[0][3] = 0.0f
;
656 U(exp_mat
).m
[1][3] = 0.0f
;
657 U(exp_mat
).m
[2][3] = 0.0f
;
658 U(exp_mat
).m
[3][3] = 1.0f
;
660 D3DXMatrixTransformation2D(&got_mat
, &sca_center
, sca_rot
, NULL
, NULL
, rot
, &trans
);
662 expect_mat(&exp_mat
, &got_mat
);
665 static void test_D3DXVec_Array(void)
668 D3DVIEWPORT9 viewport
;
669 D3DXMATRIX mat
, projection
, view
, world
;
670 D3DXVECTOR4 inp_vec
[ARRAY_SIZE
];
671 D3DXVECTOR4 out_vec
[ARRAY_SIZE
+ 2];
672 D3DXVECTOR4 exp_vec
[ARRAY_SIZE
+ 2];
673 D3DXPLANE inp_plane
[ARRAY_SIZE
];
674 D3DXPLANE out_plane
[ARRAY_SIZE
+ 2];
675 D3DXPLANE exp_plane
[ARRAY_SIZE
+ 2];
677 viewport
.Width
= 800; viewport
.MinZ
= 0.2f
; viewport
.X
= 10;
678 viewport
.Height
= 680; viewport
.MaxZ
= 0.9f
; viewport
.Y
= 5;
680 for (i
= 0; i
< ARRAY_SIZE
+ 2; ++i
) {
681 out_vec
[i
].x
= out_vec
[i
].y
= out_vec
[i
].z
= out_vec
[i
].w
= 0.0f
;
682 exp_vec
[i
].x
= exp_vec
[i
].y
= exp_vec
[i
].z
= exp_vec
[i
].w
= 0.0f
;
683 out_plane
[i
].a
= out_plane
[i
].b
= out_plane
[i
].c
= out_plane
[i
].d
= 0.0f
;
684 exp_plane
[i
].a
= exp_plane
[i
].b
= exp_plane
[i
].c
= exp_plane
[i
].d
= 0.0f
;
687 for (i
= 0; i
< ARRAY_SIZE
; ++i
) {
688 inp_plane
[i
].a
= inp_plane
[i
].c
= inp_vec
[i
].x
= inp_vec
[i
].z
= i
;
689 inp_plane
[i
].b
= inp_plane
[i
].d
= inp_vec
[i
].y
= inp_vec
[i
].w
= ARRAY_SIZE
- i
;
692 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
;
693 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
;
694 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
;
695 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
;
697 D3DXMatrixPerspectiveFovLH(&projection
,D3DX_PI
/4.0f
,20.0f
/17.0f
,1.0f
,1000.0f
);
699 U(view
).m
[0][1] = 5.0f
; U(view
).m
[0][2] = 7.0f
; U(view
).m
[0][3] = 8.0f
;
700 U(view
).m
[1][0] = 11.0f
; U(view
).m
[1][2] = 16.0f
; U(view
).m
[1][3] = 33.0f
;
701 U(view
).m
[2][0] = 19.0f
; U(view
).m
[2][1] = -21.0f
; U(view
).m
[2][3] = 43.0f
;
702 U(view
).m
[3][0] = 2.0f
; U(view
).m
[3][1] = 3.0f
; U(view
).m
[3][2] = -4.0f
;
703 U(view
).m
[0][0] = 10.0f
; U(view
).m
[1][1] = 20.0f
; U(view
).m
[2][2] = 30.0f
;
704 U(view
).m
[3][3] = -40.0f
;
706 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;
707 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
;
708 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
;
709 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
;
711 /* D3DXVec2TransformCoordArray */
712 exp_vec
[1].x
= 0.678571f
; exp_vec
[1].y
= 0.785714f
;
713 exp_vec
[2].x
= 0.653846f
; exp_vec
[2].y
= 0.769231f
;
714 exp_vec
[3].x
= 0.625f
; exp_vec
[3].y
= 0.75f
;
715 exp_vec
[4].x
= 0.590909f
; exp_vec
[4].y
= 8.0f
/11.0f
;
716 exp_vec
[5].x
= 0.55f
; exp_vec
[5].y
= 0.7f
;
717 D3DXVec2TransformCoordArray((D3DXVECTOR2
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (D3DXVECTOR2
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
718 compare_vectors(exp_vec
, out_vec
);
720 /* D3DXVec2TransformNormalArray */
721 exp_vec
[1].x
= 25.0f
; exp_vec
[1].y
= 30.0f
;
722 exp_vec
[2].x
= 21.0f
; exp_vec
[2].y
= 26.0f
;
723 exp_vec
[3].x
= 17.0f
; exp_vec
[3].y
= 22.0f
;
724 exp_vec
[4].x
= 13.0f
; exp_vec
[4].y
= 18.0f
;
725 exp_vec
[5].x
= 9.0f
; exp_vec
[5].y
= 14.0f
;
726 D3DXVec2TransformNormalArray((D3DXVECTOR2
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (D3DXVECTOR2
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
727 compare_vectors(exp_vec
, out_vec
);
729 /* D3DXVec3TransformCoordArray */
730 exp_vec
[1].x
= 0.678571f
; exp_vec
[1].y
= 0.785714f
; exp_vec
[1].z
= 0.892857f
;
731 exp_vec
[2].x
= 0.671875f
; exp_vec
[2].y
= 0.78125f
; exp_vec
[2].z
= 0.890625f
;
732 exp_vec
[3].x
= 6.0f
/9.0f
; exp_vec
[3].y
= 7.0f
/9.0f
; exp_vec
[3].z
= 8.0f
/9.0f
;
733 exp_vec
[4].x
= 0.6625f
; exp_vec
[4].y
= 0.775f
; exp_vec
[4].z
= 0.8875f
;
734 exp_vec
[5].x
= 0.659091f
; exp_vec
[5].y
= 0.772727f
; exp_vec
[5].z
= 0.886364f
;
735 D3DXVec3TransformCoordArray((D3DXVECTOR3
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (D3DXVECTOR3
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
736 compare_vectors(exp_vec
, out_vec
);
738 /* D3DXVec3TransformNormalArray */
739 exp_vec
[1].x
= 25.0f
; exp_vec
[1].y
= 30.0f
; exp_vec
[1].z
= 35.0f
;
740 exp_vec
[2].x
= 30.0f
; exp_vec
[2].y
= 36.0f
; exp_vec
[2].z
= 42.0f
;
741 exp_vec
[3].x
= 35.0f
; exp_vec
[3].y
= 42.0f
; exp_vec
[3].z
= 49.0f
;
742 exp_vec
[4].x
= 40.0f
; exp_vec
[4].y
= 48.0f
; exp_vec
[4].z
= 56.0f
;
743 exp_vec
[5].x
= 45.0f
; exp_vec
[5].y
= 54.0f
; exp_vec
[5].z
= 63.0f
;
744 D3DXVec3TransformNormalArray((D3DXVECTOR3
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (D3DXVECTOR3
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
745 compare_vectors(exp_vec
, out_vec
);
747 /* D3DXVec3ProjectArray */
748 exp_vec
[1].x
= 1089.554199f
; exp_vec
[1].y
= -226.590622f
; exp_vec
[1].z
= 0.215273f
;
749 exp_vec
[2].x
= 1068.903320f
; exp_vec
[2].y
= 103.085129f
; exp_vec
[2].z
= 0.183050f
;
750 exp_vec
[3].x
= 1051.778931f
; exp_vec
[3].y
= 376.462250f
; exp_vec
[3].z
= 0.156329f
;
751 exp_vec
[4].x
= 1037.348877f
; exp_vec
[4].y
= 606.827393f
; exp_vec
[4].z
= 0.133813f
;
752 exp_vec
[5].x
= 1025.023560f
; exp_vec
[5].y
= 803.591248f
; exp_vec
[5].z
= 0.114581f
;
753 D3DXVec3ProjectArray((D3DXVECTOR3
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (CONST D3DXVECTOR3
*)inp_vec
, sizeof(D3DXVECTOR4
), &viewport
, &projection
, &view
, &world
, ARRAY_SIZE
);
754 compare_vectors(exp_vec
, out_vec
);
756 /* D3DXVec3UnprojectArray */
757 exp_vec
[1].x
= -6.124031f
; exp_vec
[1].y
= 3.225360f
; exp_vec
[1].z
= 0.620571f
;
758 exp_vec
[2].x
= -3.807109f
; exp_vec
[2].y
= 2.046579f
; exp_vec
[2].z
= 0.446894f
;
759 exp_vec
[3].x
= -2.922839f
; exp_vec
[3].y
= 1.596689f
; exp_vec
[3].z
= 0.380609f
;
760 exp_vec
[4].x
= -2.456225f
; exp_vec
[4].y
= 1.359290f
; exp_vec
[4].z
= 0.345632f
;
761 exp_vec
[5].x
= -2.167897f
; exp_vec
[5].y
= 1.212597f
; exp_vec
[5].z
= 0.324019f
;
762 D3DXVec3UnprojectArray((D3DXVECTOR3
*)(out_vec
+ 1), sizeof(D3DXVECTOR4
), (CONST D3DXVECTOR3
*)inp_vec
, sizeof(D3DXVECTOR4
), &viewport
, &projection
, &view
, &world
, ARRAY_SIZE
);
763 compare_vectors(exp_vec
, out_vec
);
765 /* D3DXVec2TransformArray */
766 exp_vec
[1].x
= 38.0f
; exp_vec
[1].y
= 44.0f
; exp_vec
[1].z
= 50.0f
; exp_vec
[1].w
= 56.0f
;
767 exp_vec
[2].x
= 34.0f
; exp_vec
[2].y
= 40.0f
; exp_vec
[2].z
= 46.0f
; exp_vec
[2].w
= 52.0f
;
768 exp_vec
[3].x
= 30.0f
; exp_vec
[3].y
= 36.0f
; exp_vec
[3].z
= 42.0f
; exp_vec
[3].w
= 48.0f
;
769 exp_vec
[4].x
= 26.0f
; exp_vec
[4].y
= 32.0f
; exp_vec
[4].z
= 38.0f
; exp_vec
[4].w
= 44.0f
;
770 exp_vec
[5].x
= 22.0f
; exp_vec
[5].y
= 28.0f
; exp_vec
[5].z
= 34.0f
; exp_vec
[5].w
= 40.0f
;
771 D3DXVec2TransformArray(out_vec
+ 1, sizeof(D3DXVECTOR4
), (D3DXVECTOR2
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
772 compare_vectors(exp_vec
, out_vec
);
774 /* D3DXVec3TransformArray */
775 exp_vec
[1].x
= 38.0f
; exp_vec
[1].y
= 44.0f
; exp_vec
[1].z
= 50.0f
; exp_vec
[1].w
= 56.0f
;
776 exp_vec
[2].x
= 43.0f
; exp_vec
[2].y
= 50.0f
; exp_vec
[2].z
= 57.0f
; exp_vec
[2].w
= 64.0f
;
777 exp_vec
[3].x
= 48.0f
; exp_vec
[3].y
= 56.0f
; exp_vec
[3].z
= 64.0f
; exp_vec
[3].w
= 72.0f
;
778 exp_vec
[4].x
= 53.0f
; exp_vec
[4].y
= 62.0f
; exp_vec
[4].z
= 71.0f
; exp_vec
[4].w
= 80.0f
;
779 exp_vec
[5].x
= 58.0f
; exp_vec
[5].y
= 68.0f
; exp_vec
[5].z
= 78.0f
; exp_vec
[5].w
= 88.0f
;
780 D3DXVec3TransformArray(out_vec
+ 1, sizeof(D3DXVECTOR4
), (D3DXVECTOR3
*)inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
781 compare_vectors(exp_vec
, out_vec
);
783 /* D3DXVec4TransformArray */
784 exp_vec
[1].x
= 90.0f
; exp_vec
[1].y
= 100.0f
; exp_vec
[1].z
= 110.0f
; exp_vec
[1].w
= 120.0f
;
785 exp_vec
[2].x
= 82.0f
; exp_vec
[2].y
= 92.0f
; exp_vec
[2].z
= 102.0f
; exp_vec
[2].w
= 112.0f
;
786 exp_vec
[3].x
= 74.0f
; exp_vec
[3].y
= 84.0f
; exp_vec
[3].z
= 94.0f
; exp_vec
[3].w
= 104.0f
;
787 exp_vec
[4].x
= 66.0f
; exp_vec
[4].y
= 76.0f
; exp_vec
[4].z
= 86.0f
; exp_vec
[4].w
= 96.0f
;
788 exp_vec
[5].x
= 58.0f
; exp_vec
[5].y
= 68.0f
; exp_vec
[5].z
= 78.0f
; exp_vec
[5].w
= 88.0f
;
789 D3DXVec4TransformArray(out_vec
+ 1, sizeof(D3DXVECTOR4
), inp_vec
, sizeof(D3DXVECTOR4
), &mat
, ARRAY_SIZE
);
790 compare_vectors(exp_vec
, out_vec
);
792 /* D3DXPlaneTransformArray */
793 exp_plane
[1].a
= 90.0f
; exp_plane
[1].b
= 100.0f
; exp_plane
[1].c
= 110.0f
; exp_plane
[1].d
= 120.0f
;
794 exp_plane
[2].a
= 82.0f
; exp_plane
[2].b
= 92.0f
; exp_plane
[2].c
= 102.0f
; exp_plane
[2].d
= 112.0f
;
795 exp_plane
[3].a
= 74.0f
; exp_plane
[3].b
= 84.0f
; exp_plane
[3].c
= 94.0f
; exp_plane
[3].d
= 104.0f
;
796 exp_plane
[4].a
= 66.0f
; exp_plane
[4].b
= 76.0f
; exp_plane
[4].c
= 86.0f
; exp_plane
[4].d
= 96.0f
;
797 exp_plane
[5].a
= 58.0f
; exp_plane
[5].b
= 68.0f
; exp_plane
[5].c
= 78.0f
; exp_plane
[5].d
= 88.0f
;
798 D3DXPlaneTransformArray(out_plane
+ 1, sizeof(D3DXPLANE
), inp_plane
, sizeof(D3DXPLANE
), &mat
, ARRAY_SIZE
);
799 compare_planes(exp_plane
, out_plane
);
804 test_Matrix_AffineTransformation2D();
805 test_Matrix_Decompose();
806 test_Matrix_Transformation2D();
807 test_D3DXVec_Array();