d3dx9/tests: Check a relative error instead of an absolute error.
[wine/hacks.git] / dlls / d3dx9_36 / tests / math.c
blob4eb7bcb610deebb880921c2fede3937398c36113
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"
25 #define ARRAY_SIZE 5
27 #define admitted_error 0.0001f
29 #define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1 - out/ exp) ))
31 #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);
33 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
35 int i, j;
37 for (i = 0; i < 4; ++i)
39 for (j = 0; j < 4; ++j)
41 if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
42 return FALSE;
46 return TRUE;
49 #define expect_mat(expectedmat, gotmat) \
50 do { \
51 const D3DXMATRIX *__m1 = (expectedmat); \
52 const D3DXMATRIX *__m2 = (gotmat); \
53 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" \
54 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
55 U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
56 U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
57 U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
58 U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
59 U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
60 U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
61 U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
62 U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
63 } while(0)
65 #define compare_rotation(exp, got) \
66 ok(relative_error(exp.w, got.w) < admitted_error && \
67 relative_error(exp.x, got.x) < admitted_error && \
68 relative_error(exp.y, got.y) < admitted_error && \
69 relative_error(exp.z, got.z) < admitted_error, \
70 "Expected rotation = (%f, %f, %f, %f), \
71 got rotation = (%f, %f, %f, %f)\n", \
72 exp.w, exp.x, exp.y, exp.z, got.w, got.x, got.y, got.z)
74 #define compare_scale(exp, got) \
75 ok(relative_error(exp.x, got.x) < admitted_error && \
76 relative_error(exp.y, got.y) < admitted_error && \
77 relative_error(exp.z, got.z) < admitted_error, \
78 "Expected scale = (%f, %f, %f), \
79 got scale = (%f, %f, %f)\n", \
80 exp.x, exp.y, exp.z, got.x, got.y, got.z)
82 #define compare_translation(exp, got) \
83 ok(relative_error(exp.x, got.x) < admitted_error && \
84 relative_error(exp.y, got.y) < admitted_error && \
85 relative_error(exp.z, got.z) < admitted_error, \
86 "Expected translation = (%f, %f, %f), \
87 got translation = (%f, %f, %f)\n", \
88 exp.x, exp.y, exp.z, got.x, got.y, got.z)
90 #define compare_vectors(exp, out) \
91 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
92 ok(relative_error(exp[i].x, out[i].x) < admitted_error && \
93 relative_error(exp[i].y, out[i].y) < admitted_error && \
94 relative_error(exp[i].z, out[i].z) < admitted_error && \
95 relative_error(exp[i].w, out[i].w) < admitted_error, \
96 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
97 out[i].x, out[i].y, out[i].z, out[i].w, \
98 exp[i].x, exp[i].y, exp[i].z, exp[i].w, \
99 i); \
102 #define compare_planes(exp, out) \
103 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
104 ok(relative_error(exp[i].a, out[i].a) < admitted_error && \
105 relative_error(exp[i].b, out[i].b) < admitted_error && \
106 relative_error(exp[i].c, out[i].c) < admitted_error && \
107 relative_error(exp[i].d, out[i].d) < admitted_error, \
108 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
109 out[i].a, out[i].b, out[i].c, out[i].d, \
110 exp[i].a, exp[i].b, exp[i].c, exp[i].d, \
111 i); \
114 #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);
116 #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);
118 #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);
120 #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);
123 static void D3DXColorTest(void)
125 D3DXCOLOR color, color1, color2, expected, got;
126 LPD3DXCOLOR funcpointer;
127 FLOAT scale;
129 color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
130 color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
131 color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
133 scale = 0.3f;
135 /*_______________D3DXColorAdd________________*/
136 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
137 D3DXColorAdd(&got,&color1,&color2);
138 expect_color(expected,got);
139 /* Test the NULL case */
140 funcpointer = D3DXColorAdd(&got,NULL,&color2);
141 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
142 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
143 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
144 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
145 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
147 /*_______________D3DXColorAdjustContrast______*/
148 expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
149 D3DXColorAdjustContrast(&got,&color,scale);
150 expect_color(expected,got);
152 /*_______________D3DXColorAdjustSaturation______*/
153 expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
154 D3DXColorAdjustSaturation(&got,&color,scale);
155 expect_color(expected,got);
157 /*_______________D3DXColorLerp________________*/
158 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
159 D3DXColorLerp(&got,&color,&color1,scale);
160 expect_color(expected,got);
161 /* Test the NULL case */
162 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
163 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
164 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
165 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
166 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
167 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
169 /*_______________D3DXColorModulate________________*/
170 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
171 D3DXColorModulate(&got,&color1,&color2);
172 expect_color(expected,got);
173 /* Test the NULL case */
174 funcpointer = D3DXColorModulate(&got,NULL,&color2);
175 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
176 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
177 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
178 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
179 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
181 /*_______________D3DXColorNegative________________*/
182 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
183 D3DXColorNegative(&got,&color);
184 expect_color(got,expected);
185 /* Test the greater than 1 case */
186 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
187 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
188 D3DXColorNegative(&got,&color1);
189 expect_color(got,expected);
190 /* Test the negative case */
191 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
192 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
193 D3DXColorNegative(&got,&color1);
194 expect_color(got,expected);
195 /* Test the NULL case */
196 funcpointer = D3DXColorNegative(&got,NULL);
197 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
198 funcpointer = D3DXColorNegative(NULL,NULL);
199 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
201 /*_______________D3DXColorScale________________*/
202 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
203 D3DXColorScale(&got,&color,scale);
204 expect_color(expected,got);
205 /* Test the NULL case */
206 funcpointer = D3DXColorScale(&got,NULL,scale);
207 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
208 funcpointer = D3DXColorScale(NULL,NULL,scale);
209 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
211 /*_______________D3DXColorSubtract_______________*/
212 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
213 D3DXColorSubtract(&got,&color,&color2);
214 expect_color(expected,got);
215 /* Test the NULL case */
216 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
217 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
218 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
219 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
220 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
221 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
224 static void D3DXFresnelTest(void)
226 FLOAT expected, got;
228 expected = 0.089187;
229 got = D3DXFresnelTerm(0.5f,1.5);
230 ok(relative_error(got, expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
233 static void D3DXMatrixTest(void)
235 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
236 LPD3DXMATRIX funcpointer;
237 D3DXPLANE plane;
238 D3DXQUATERNION q, r;
239 D3DXVECTOR3 at, axis, eye, last, scaling;
240 D3DXVECTOR4 light;
241 BOOL expected, got;
242 FLOAT angle, determinant, expectedfloat, gotfloat;
244 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
245 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
246 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
247 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
248 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
249 U(mat).m[3][3] = -40.0f;
251 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
252 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
253 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
254 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
255 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
256 U(mat2).m[3][3] = -1.0f;
258 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
260 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
261 r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
263 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
264 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
265 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
266 last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
267 scaling.x = 0.03f; scaling.y =0.05f; scaling.z = 0.06f;
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);
280 /* Test the NULL case */
281 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;
282 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;
283 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;
284 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;
285 D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
286 expect_mat(&expectedmat, &gotmat);
288 /*____________D3DXMatrixfDeterminant_____________*/
289 expectedfloat = -147888.0f;
290 gotfloat = D3DXMatrixDeterminant(&mat);
291 ok(relative_error(gotfloat, expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
293 /*____________D3DXMatrixInverse______________*/
294 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;
295 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;
296 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;
297 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;
298 expectedfloat = -147888.0f;
299 D3DXMatrixInverse(&gotmat,&determinant,&mat);
300 expect_mat(&expectedmat, &gotmat);
301 ok(relative_error( determinant, expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
302 funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
303 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
305 /*____________D3DXMatrixIsIdentity______________*/
306 expected = FALSE;
307 memset(&mat3, 0, sizeof(mat3));
308 got = D3DXMatrixIsIdentity(&mat3);
309 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
310 D3DXMatrixIdentity(&mat3);
311 expected = TRUE;
312 got = D3DXMatrixIsIdentity(&mat3);
313 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
314 U(mat3).m[0][0] = 0.000009f;
315 expected = FALSE;
316 got = D3DXMatrixIsIdentity(&mat3);
317 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
318 /* Test the NULL case */
319 expected = FALSE;
320 got = D3DXMatrixIsIdentity(NULL);
321 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
323 /*____________D3DXMatrixLookatLH_______________*/
324 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;
325 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;
326 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;
327 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;
328 D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
329 expect_mat(&expectedmat, &gotmat);
331 /*____________D3DXMatrixLookatRH_______________*/
332 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;
333 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;
334 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;
335 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;
336 D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
337 expect_mat(&expectedmat, &gotmat);
339 /*____________D3DXMatrixMultiply______________*/
340 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;
341 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;
342 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;
343 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;
344 D3DXMatrixMultiply(&gotmat,&mat,&mat2);
345 expect_mat(&expectedmat, &gotmat);
347 /*____________D3DXMatrixMultiplyTranspose____*/
348 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;
349 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;
350 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;
351 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;
352 D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
353 expect_mat(&expectedmat, &gotmat);
355 /*____________D3DXMatrixOrthoLH_______________*/
356 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;
357 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;
358 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;
359 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;
360 D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
361 expect_mat(&expectedmat, &gotmat);
363 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
364 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;
365 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;
366 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;
367 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;
368 D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
369 expect_mat(&expectedmat, &gotmat);
371 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
372 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;
373 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;
374 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;
375 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;
376 D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
377 expect_mat(&expectedmat, &gotmat);
379 /*____________D3DXMatrixOrthoRH_______________*/
380 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;
381 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;
382 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;
383 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;
384 D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
385 expect_mat(&expectedmat, &gotmat);
387 /*____________D3DXMatrixPerspectiveFovLH_______________*/
388 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;
389 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;
390 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;
391 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;
392 D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
393 expect_mat(&expectedmat, &gotmat);
395 /*____________D3DXMatrixPerspectiveFovRH_______________*/
396 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;
397 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;
398 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;
399 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;
400 D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
401 expect_mat(&expectedmat, &gotmat);
403 /*____________D3DXMatrixPerspectiveLH_______________*/
404 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;
405 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;
406 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;
407 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;
408 D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
409 expect_mat(&expectedmat, &gotmat);
411 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
412 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;
413 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;
414 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;
415 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;
416 D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
417 expect_mat(&expectedmat, &gotmat);
419 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
420 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;
421 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;
422 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;
423 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;
424 D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
425 expect_mat(&expectedmat, &gotmat);
427 /*____________D3DXMatrixPerspectiveRH_______________*/
428 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;
429 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;
430 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;
431 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;
432 D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
433 expect_mat(&expectedmat, &gotmat);
435 /*____________D3DXMatrixReflect______________*/
436 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;
437 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;
438 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;
439 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;
440 D3DXMatrixReflect(&gotmat,&plane);
441 expect_mat(&expectedmat, &gotmat);
443 /*____________D3DXMatrixRotationAxis_____*/
444 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;
445 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;
446 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;
447 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;
448 D3DXMatrixRotationAxis(&gotmat,&axis,angle);
449 expect_mat(&expectedmat, &gotmat);
451 /*____________D3DXMatrixRotationQuaternion______________*/
452 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;
453 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;
454 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;
455 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;
456 D3DXMatrixRotationQuaternion(&gotmat,&q);
457 expect_mat(&expectedmat, &gotmat);
459 /*____________D3DXMatrixRotationX______________*/
460 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;
461 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;
462 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;
463 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;
464 D3DXMatrixRotationX(&gotmat,angle);
465 expect_mat(&expectedmat, &gotmat);
467 /*____________D3DXMatrixRotationY______________*/
468 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;
469 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;
470 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;
471 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;
472 D3DXMatrixRotationY(&gotmat,angle);
473 expect_mat(&expectedmat, &gotmat);
475 /*____________D3DXMatrixRotationYawPitchRoll____*/
476 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;
477 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;
478 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;
479 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;
480 D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
481 expect_mat(&expectedmat, &gotmat);
483 /*____________D3DXMatrixRotationZ______________*/
484 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;
485 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;
486 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;
487 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;
488 D3DXMatrixRotationZ(&gotmat,angle);
489 expect_mat(&expectedmat, &gotmat);
491 /*____________D3DXMatrixScaling______________*/
492 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;
493 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;
494 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;
495 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;
496 D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
497 expect_mat(&expectedmat, &gotmat);
499 /*____________D3DXMatrixShadow______________*/
500 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;
501 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;
502 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;
503 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;
504 D3DXMatrixShadow(&gotmat,&light,&plane);
505 expect_mat(&expectedmat, &gotmat);
507 /*____________D3DXMatrixTransformation______________*/
508 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;
509 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;
510 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;
511 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;
512 D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
513 expect_mat(&expectedmat, &gotmat);
515 /*____________D3DXMatrixTranslation______________*/
516 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;
517 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;
518 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;
519 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;
520 D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
521 expect_mat(&expectedmat, &gotmat);
523 /*____________D3DXMatrixTranspose______________*/
524 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;
525 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;
526 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;
527 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;
528 D3DXMatrixTranspose(&gotmat,&mat);
529 expect_mat(&expectedmat, &gotmat);
532 static void D3DXPlaneTest(void)
534 D3DXMATRIX mat;
535 D3DXPLANE expectedplane, gotplane, nulplane, plane;
536 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
537 LPD3DXVECTOR3 funcpointer;
538 D3DXVECTOR4 vec;
539 FLOAT expected, got;
541 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
542 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
543 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
544 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
545 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
546 U(mat).m[3][3] = -40.0f;
548 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
550 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
552 /*_______________D3DXPlaneDot________________*/
553 expected = 42.0f;
554 got = D3DXPlaneDot(&plane,&vec),
555 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
556 expected = 0.0f;
557 got = D3DXPlaneDot(NULL,&vec),
558 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
559 expected = 0.0f;
560 got = D3DXPlaneDot(NULL,NULL),
561 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
563 /*_______________D3DXPlaneDotCoord________________*/
564 expected = -28.0f;
565 got = D3DXPlaneDotCoord(&plane,&vec),
566 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
567 expected = 0.0f;
568 got = D3DXPlaneDotCoord(NULL,&vec),
569 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
570 expected = 0.0f;
571 got = D3DXPlaneDotCoord(NULL,NULL),
572 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
574 /*_______________D3DXPlaneDotNormal______________*/
575 expected = -35.0f;
576 got = D3DXPlaneDotNormal(&plane,&vec),
577 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
578 expected = 0.0f;
579 got = D3DXPlaneDotNormal(NULL,&vec),
580 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
581 expected = 0.0f;
582 got = D3DXPlaneDotNormal(NULL,NULL),
583 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
585 /*_______________D3DXPlaneFromPointNormal_______*/
586 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
587 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
588 expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
589 D3DXPlaneFromPointNormal(&gotplane,&vec1,&vec2);
590 expect_plane(expectedplane, gotplane);
592 /*_______________D3DXPlaneFromPoints_______*/
593 vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
594 vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
595 vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
596 expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
597 D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
598 expect_plane(expectedplane, gotplane);
600 /*_______________D3DXPlaneIntersectLine___________*/
601 vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
602 vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
603 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
604 D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
605 expect_vec3(expectedvec, gotvec);
606 /* Test a parallel line */
607 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
608 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
609 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
610 funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
611 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
613 /*_______________D3DXPlaneNormalize______________*/
614 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);
615 D3DXPlaneNormalize(&gotplane, &plane);
616 expect_plane(expectedplane, gotplane);
617 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
618 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
619 D3DXPlaneNormalize(&gotplane, &nulplane);
620 expect_plane(expectedplane, gotplane);
621 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 4.3f;
622 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
623 D3DXPlaneNormalize(&gotplane, &nulplane);
624 expect_plane(expectedplane, gotplane);
626 /*_______________D3DXPlaneTransform____________*/
627 expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
628 D3DXPlaneTransform(&gotplane,&plane,&mat);
629 expect_plane(expectedplane, gotplane);
632 static void D3DXQuaternionTest(void)
634 D3DXMATRIX mat;
635 D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
636 LPD3DXQUATERNION funcpointer;
637 D3DXVECTOR3 axis, expectedvec;
638 FLOAT angle, expected, got, scale, scale2;
639 BOOL expectedbool, gotbool;
641 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
642 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
643 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
644 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
645 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
646 smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
647 smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallr.w = 0.8f;
649 scale = 0.3f;
650 scale2 = 0.78f;
652 /*_______________D3DXQuaternionBaryCentric________________________*/
653 expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
654 D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
655 expect_vec4(expectedquat,gotquat);
657 /*_______________D3DXQuaternionConjugate________________*/
658 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
659 D3DXQuaternionConjugate(&gotquat,&q);
660 expect_vec4(expectedquat,gotquat);
661 /* Test the NULL case */
662 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
663 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
664 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
665 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
667 /*_______________D3DXQuaternionDot______________________*/
668 expected = 55.0f;
669 got = D3DXQuaternionDot(&q,&r);
670 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
671 /* Tests the case NULL */
672 expected=0.0f;
673 got = D3DXQuaternionDot(NULL,&r);
674 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
675 expected=0.0f;
676 got = D3DXQuaternionDot(NULL,NULL);
677 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
679 /*_______________D3DXQuaternionExp______________________________*/
680 expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
681 D3DXQuaternionExp(&gotquat,&q);
682 expect_vec4(expectedquat,gotquat);
683 /* Test the null quaternion */
684 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
685 D3DXQuaternionExp(&gotquat,&nul);
686 expect_vec4(expectedquat,gotquat);
687 /* Test the case where the norm of the quaternion is <1 */
688 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
689 expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
690 D3DXQuaternionExp(&gotquat,&Nq1);
691 expect_vec4(expectedquat,gotquat);
693 /*_______________D3DXQuaternionIdentity________________*/
694 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
695 D3DXQuaternionIdentity(&gotquat);
696 expect_vec4(expectedquat,gotquat);
697 /* Test the NULL case */
698 funcpointer = D3DXQuaternionIdentity(NULL);
699 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
701 /*_______________D3DXQuaternionInverse________________________*/
702 expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
703 D3DXQuaternionInverse(&gotquat,&q);
704 expect_vec4(expectedquat,gotquat);
706 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 10.0f;
707 D3DXQuaternionInverse(&gotquat,&gotquat);
708 expect_vec4(expectedquat,gotquat);
711 /*_______________D3DXQuaternionIsIdentity________________*/
712 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
713 expectedbool = TRUE;
714 gotbool = D3DXQuaternionIsIdentity(&s);
715 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
716 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
717 expectedbool = FALSE;
718 gotbool = D3DXQuaternionIsIdentity(&q);
719 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
720 /* Test the NULL case */
721 gotbool = D3DXQuaternionIsIdentity(NULL);
722 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
724 /*_______________D3DXQuaternionLength__________________________*/
725 expected = 11.0f;
726 got = D3DXQuaternionLength(&q);
727 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
728 /* Tests the case NULL */
729 expected=0.0f;
730 got = D3DXQuaternionLength(NULL);
731 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
733 /*_______________D3DXQuaternionLengthSq________________________*/
734 expected = 121.0f;
735 got = D3DXQuaternionLengthSq(&q);
736 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
737 /* Tests the case NULL */
738 expected=0.0f;
739 got = D3DXQuaternionLengthSq(NULL);
740 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
742 /*_______________D3DXQuaternionLn______________________________*/
743 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
744 D3DXQuaternionLn(&gotquat,&q);
745 expect_vec4(expectedquat,gotquat);
746 expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
747 D3DXQuaternionLn(&gotquat,&r);
748 expect_vec4(expectedquat,gotquat);
749 Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
750 expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
751 D3DXQuaternionLn(&gotquat,&Nq);
752 expect_vec4(expectedquat,gotquat);
753 /* Test the cas where the norm of the quaternion is <1 */
754 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
755 expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
756 D3DXQuaternionLn(&gotquat,&Nq1);
757 todo_wine{ expect_vec4(expectedquat,gotquat) };
759 /*_______________D3DXQuaternionMultiply________________________*/
760 expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
761 D3DXQuaternionMultiply(&gotquat,&q,&r);
762 expect_vec4(expectedquat,gotquat);
764 /*_______________D3DXQuaternionNormalize________________________*/
765 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
766 D3DXQuaternionNormalize(&gotquat,&q);
767 expect_vec4(expectedquat,gotquat);
769 /*_______________D3DXQuaternionRotationAxis___________________*/
770 axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
771 angle = D3DX_PI/3.0f;
772 expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
773 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
774 expect_vec4(expectedquat,gotquat);
775 /* Test the nul quaternion */
776 axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
777 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
778 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
779 expect_vec4(expectedquat,gotquat);
781 /*_______________D3DXQuaternionRotationMatrix___________________*/
782 /* test when the trace is >0 */
783 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
784 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
785 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
786 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
787 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
788 U(mat).m[3][3] = 48.0f;
789 expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
790 D3DXQuaternionRotationMatrix(&gotquat,&mat);
791 expect_vec4(expectedquat,gotquat);
792 /* test the case when the greater element is (2,2) */
793 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
794 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
795 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
796 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
797 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
798 U(mat).m[3][3] = 48.0f;
799 expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
800 D3DXQuaternionRotationMatrix(&gotquat,&mat);
801 expect_vec4(expectedquat,gotquat);
802 /* test the case when the greater element is (1,1) */
803 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
804 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
805 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
806 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
807 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
808 U(mat).m[3][3] = 48.0f;
809 expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
810 D3DXQuaternionRotationMatrix(&gotquat,&mat);
811 expect_vec4(expectedquat,gotquat);
812 /* test the case when the trace is near 0 in a matrix which is not a rotation */
813 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
814 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
815 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
816 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
817 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
818 U(mat).m[3][3] = 48.0f;
819 expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
820 D3DXQuaternionRotationMatrix(&gotquat,&mat);
821 expect_vec4(expectedquat,gotquat);
822 /* test the case when the trace is 0.49 in a matrix which is not a rotation */
823 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
824 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
825 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
826 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
827 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
828 U(mat).m[3][3] = 48.0f;
829 expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
830 D3DXQuaternionRotationMatrix(&gotquat,&mat);
831 expect_vec4(expectedquat,gotquat);
832 /* test the case when the trace is 0.51 in a matrix which is not a rotation */
833 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
834 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
835 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
836 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
837 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
838 U(mat).m[3][3] = 48.0f;
839 expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
840 D3DXQuaternionRotationMatrix(&gotquat,&mat);
841 expect_vec4(expectedquat,gotquat);
842 /* test the case when the trace is 0.99 in a matrix which is not a rotation */
843 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
844 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
845 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
846 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
847 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
848 U(mat).m[3][3] = 48.0f;
849 expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
850 D3DXQuaternionRotationMatrix(&gotquat,&mat);
851 expect_vec4(expectedquat,gotquat);
852 /* test the case when the trace is 1.0 in a matrix which is not a rotation */
853 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
854 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
855 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
856 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
857 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
858 U(mat).m[3][3] = 48.0f;
859 expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
860 D3DXQuaternionRotationMatrix(&gotquat,&mat);
861 expect_vec4(expectedquat,gotquat);
862 /* test the case when the trace is 1.01 in a matrix which is not a rotation */
863 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
864 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
865 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
866 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
867 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
868 U(mat).m[3][3] = 48.0f;
869 expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
870 D3DXQuaternionRotationMatrix(&gotquat,&mat);
871 expect_vec4(expectedquat,gotquat);
872 /* test the case when the trace is 1.5 in a matrix which is not a rotation */
873 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
874 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
875 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
876 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
877 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
878 U(mat).m[3][3] = 48.0f;
879 expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
880 D3DXQuaternionRotationMatrix(&gotquat,&mat);
881 expect_vec4(expectedquat,gotquat);
882 /* test the case when the trace is 1.7 in a matrix which is not a rotation */
883 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
884 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
885 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
886 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
887 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
888 U(mat).m[3][3] = 48.0f;
889 expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
890 D3DXQuaternionRotationMatrix(&gotquat,&mat);
891 expect_vec4(expectedquat,gotquat);
892 /* test the case when the trace is 1.99 in a matrix which is not a rotation */
893 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
894 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
895 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
896 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
897 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
898 U(mat).m[3][3] = 48.0f;
899 expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
900 D3DXQuaternionRotationMatrix(&gotquat,&mat);
901 expect_vec4(expectedquat,gotquat);
902 /* test the case when the trace is 2.0 in a matrix which is not a rotation */
903 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
904 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
905 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
906 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
907 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
908 U(mat).m[3][3] = 48.0f;
909 expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
910 D3DXQuaternionRotationMatrix(&gotquat,&mat);
911 expect_vec4(expectedquat,gotquat);
913 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
914 expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
915 D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
916 expect_vec4(expectedquat,gotquat);
918 /*_______________D3DXQuaternionSlerp________________________*/
919 expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
920 D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
921 expect_vec4(expectedquat,gotquat);
922 expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
923 D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
924 expect_vec4(expectedquat,gotquat);
925 expectedquat.x = 0.239485f; expectedquat.y = 0.346580f; expectedquat.z = 0.453676f; expectedquat.w = 0.560772f;
926 D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
927 expect_vec4(expectedquat,gotquat);
929 /*_______________D3DXQuaternionSquad________________________*/
930 expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
931 D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
932 expect_vec4(expectedquat,gotquat);
934 /*_______________D3DXQuaternionToAxisAngle__________________*/
935 Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
936 expectedvec.x = 1.0f/22.0f; expectedvec.y = 2.0f/22.0f; expectedvec.z = 4.0f/22.0f;
937 expected = 2.197869f;
938 D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
939 expect_vec3(expectedvec,axis);
940 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
941 /* Test if |w|>1.0f */
942 expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f;
943 expected = 0.0f;
944 D3DXQuaternionToAxisAngle(&q,&axis,&angle);
945 expect_vec3(expectedvec,axis);
946 /* Test the null quaternion */
947 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
948 expected = 3.141593f;
949 D3DXQuaternionToAxisAngle(&nul,&axis,&angle);
950 expect_vec3(expectedvec,axis);
951 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
954 static void D3DXVector2Test(void)
956 D3DXVECTOR2 expectedvec, gotvec, nul, u, v, w, x;
957 LPD3DXVECTOR2 funcpointer;
958 D3DXVECTOR4 expectedtrans, gottrans;
959 D3DXMATRIX mat;
960 FLOAT coeff1, coeff2, expected, got, scale;
962 nul.x = 0.0f; nul.y = 0.0f;
963 u.x = 3.0f; u.y = 4.0f;
964 v.x = -7.0f; v.y = 9.0f;
965 w.x = 4.0f; w.y = -3.0f;
966 x.x = 2.0f; x.y = -11.0f;
968 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;
969 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;
970 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;
971 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;
973 coeff1 = 2.0f; coeff2 = 5.0f;
974 scale = -6.5f;
976 /*_______________D3DXVec2Add__________________________*/
977 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
978 D3DXVec2Add(&gotvec,&u,&v);
979 expect_vec(expectedvec,gotvec);
980 /* Tests the case NULL */
981 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
982 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
983 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
984 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
986 /*_______________D3DXVec2BaryCentric___________________*/
987 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
988 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
989 expect_vec(expectedvec,gotvec);
991 /*_______________D3DXVec2CatmullRom____________________*/
992 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
993 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
994 expect_vec(expectedvec,gotvec);
996 /*_______________D3DXVec2CCW__________________________*/
997 expected = 55.0f;
998 got = D3DXVec2CCW(&u,&v);
999 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1000 /* Tests the case NULL */
1001 expected=0.0f;
1002 got = D3DXVec2CCW(NULL,&v);
1003 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1004 expected=0.0f;
1005 got = D3DXVec2CCW(NULL,NULL);
1006 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1008 /*_______________D3DXVec2Dot__________________________*/
1009 expected = 15.0f;
1010 got = D3DXVec2Dot(&u,&v);
1011 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1012 /* Tests the case NULL */
1013 expected=0.0f;
1014 got = D3DXVec2Dot(NULL,&v);
1015 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1016 expected=0.0f;
1017 got = D3DXVec2Dot(NULL,NULL);
1018 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1020 /*_______________D3DXVec2Hermite__________________________*/
1021 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
1022 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
1023 expect_vec(expectedvec,gotvec);
1025 /*_______________D3DXVec2Length__________________________*/
1026 expected = 5.0f;
1027 got = D3DXVec2Length(&u);
1028 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1029 /* Tests the case NULL */
1030 expected=0.0f;
1031 got = D3DXVec2Length(NULL);
1032 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1034 /*_______________D3DXVec2LengthSq________________________*/
1035 expected = 25.0f;
1036 got = D3DXVec2LengthSq(&u);
1037 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1038 /* Tests the case NULL */
1039 expected=0.0f;
1040 got = D3DXVec2LengthSq(NULL);
1041 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1043 /*_______________D3DXVec2Lerp__________________________*/
1044 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
1045 D3DXVec2Lerp(&gotvec,&u,&v,scale);
1046 expect_vec(expectedvec,gotvec);
1047 /* Tests the case NULL */
1048 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
1049 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1050 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1051 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1053 /*_______________D3DXVec2Maximize__________________________*/
1054 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1055 D3DXVec2Maximize(&gotvec,&u,&v);
1056 expect_vec(expectedvec,gotvec);
1057 /* Tests the case NULL */
1058 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1059 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1060 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1061 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1063 /*_______________D3DXVec2Minimize__________________________*/
1064 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1065 D3DXVec2Minimize(&gotvec,&u,&v);
1066 expect_vec(expectedvec,gotvec);
1067 /* Tests the case NULL */
1068 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1069 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1070 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1071 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1073 /*_______________D3DXVec2Normalize_________________________*/
1074 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1075 D3DXVec2Normalize(&gotvec,&u);
1076 expect_vec(expectedvec,gotvec);
1077 /* Test the nul vector */
1078 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1079 D3DXVec2Normalize(&gotvec,&nul);
1080 expect_vec(expectedvec,gotvec);
1082 /*_______________D3DXVec2Scale____________________________*/
1083 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1084 D3DXVec2Scale(&gotvec,&u,scale);
1085 expect_vec(expectedvec,gotvec);
1086 /* Tests the case NULL */
1087 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
1088 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1089 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
1090 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1092 /*_______________D3DXVec2Subtract__________________________*/
1093 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
1094 D3DXVec2Subtract(&gotvec,&u,&v);
1095 expect_vec(expectedvec,gotvec);
1096 /* Tests the case NULL */
1097 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
1098 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1099 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
1100 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1102 /*_______________D3DXVec2Transform_______________________*/
1103 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
1104 D3DXVec2Transform(&gottrans,&u,&mat);
1105 expect_vec4(expectedtrans,gottrans);
1107 /*_______________D3DXVec2TransformCoord_______________________*/
1108 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
1109 D3DXVec2TransformCoord(&gotvec,&u,&mat);
1110 expect_vec(expectedvec,gotvec);
1112 /*_______________D3DXVec2TransformNormal______________________*/
1113 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1114 D3DXVec2TransformNormal(&gotvec,&u,&mat);
1115 expect_vec(expectedvec,gotvec);
1118 static void D3DXVector3Test(void)
1120 D3DVIEWPORT9 viewport;
1121 D3DXVECTOR3 expectedvec, gotvec, nul, u, v, w, x;
1122 LPD3DXVECTOR3 funcpointer;
1123 D3DXVECTOR4 expectedtrans, gottrans;
1124 D3DXMATRIX mat, projection, view, world;
1125 FLOAT coeff1, coeff2, expected, got, scale;
1127 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
1128 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
1129 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
1130 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
1131 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
1133 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1134 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
1136 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;
1137 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;
1138 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;
1139 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;
1141 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
1142 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
1143 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
1144 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
1145 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
1146 U(view).m[3][3] = -40.0f;
1148 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;
1149 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;
1150 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;
1151 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;
1153 coeff1 = 2.0f; coeff2 = 5.0f;
1154 scale = -6.5f;
1156 /*_______________D3DXVec3Add__________________________*/
1157 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
1158 D3DXVec3Add(&gotvec,&u,&v);
1159 expect_vec3(expectedvec,gotvec);
1160 /* Tests the case NULL */
1161 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
1162 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1163 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
1164 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1166 /*_______________D3DXVec3BaryCentric___________________*/
1167 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1168 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1170 expect_vec3(expectedvec,gotvec);
1172 /*_______________D3DXVec3CatmullRom____________________*/
1173 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
1174 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1175 expect_vec3(expectedvec,gotvec);
1177 /*_______________D3DXVec3Cross________________________*/
1178 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
1179 D3DXVec3Cross(&gotvec,&u,&v);
1180 expect_vec3(expectedvec,gotvec);
1181 /* Tests the case NULL */
1182 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
1183 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1184 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
1185 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1187 /*_______________D3DXVec3Dot__________________________*/
1188 expected = -8.0f;
1189 got = D3DXVec3Dot(&u,&v);
1190 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1191 /* Tests the case NULL */
1192 expected=0.0f;
1193 got = D3DXVec3Dot(NULL,&v);
1194 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1195 expected=0.0f;
1196 got = D3DXVec3Dot(NULL,NULL);
1197 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1199 /*_______________D3DXVec3Hermite__________________________*/
1200 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
1201 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
1202 expect_vec3(expectedvec,gotvec);
1204 /*_______________D3DXVec3Length__________________________*/
1205 expected = 11.0f;
1206 got = D3DXVec3Length(&u);
1207 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1208 /* Tests the case NULL */
1209 expected=0.0f;
1210 got = D3DXVec3Length(NULL);
1211 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1213 /*_______________D3DXVec3LengthSq________________________*/
1214 expected = 121.0f;
1215 got = D3DXVec3LengthSq(&u);
1216 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1217 /* Tests the case NULL */
1218 expected=0.0f;
1219 got = D3DXVec3LengthSq(NULL);
1220 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1222 /*_______________D3DXVec3Lerp__________________________*/
1223 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
1224 D3DXVec3Lerp(&gotvec,&u,&v,scale);
1225 expect_vec3(expectedvec,gotvec);
1226 /* Tests the case NULL */
1227 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
1228 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1229 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
1230 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1232 /*_______________D3DXVec3Maximize__________________________*/
1233 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
1234 D3DXVec3Maximize(&gotvec,&u,&v);
1235 expect_vec3(expectedvec,gotvec);
1236 /* Tests the case NULL */
1237 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
1238 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1239 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
1240 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1242 /*_______________D3DXVec3Minimize__________________________*/
1243 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
1244 D3DXVec3Minimize(&gotvec,&u,&v);
1245 expect_vec3(expectedvec,gotvec);
1246 /* Tests the case NULL */
1247 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
1248 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1249 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
1250 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1252 /*_______________D3DXVec3Normalize_________________________*/
1253 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
1254 D3DXVec3Normalize(&gotvec,&u);
1255 expect_vec3(expectedvec,gotvec);
1256 /* Test the nul vector */
1257 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1258 D3DXVec3Normalize(&gotvec,&nul);
1259 expect_vec3(expectedvec,gotvec);
1261 /*_______________D3DXVec3Project_________________________*/
1262 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
1263 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1264 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
1265 expect_vec3(expectedvec,gotvec);
1267 /*_______________D3DXVec3Scale____________________________*/
1268 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
1269 D3DXVec3Scale(&gotvec,&u,scale);
1270 expect_vec3(expectedvec,gotvec);
1271 /* Tests the case NULL */
1272 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
1273 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1274 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
1275 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1277 /*_______________D3DXVec3Subtract_______________________*/
1278 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1279 D3DXVec3Subtract(&gotvec,&u,&v);
1280 expect_vec3(expectedvec,gotvec);
1281 /* Tests the case NULL */
1282 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1283 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1284 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1285 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1287 /*_______________D3DXVec3Transform_______________________*/
1288 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1289 D3DXVec3Transform(&gottrans,&u,&mat);
1290 expect_vec4(expectedtrans,gottrans);
1292 /*_______________D3DXVec3TransformCoord_______________________*/
1293 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1294 D3DXVec3TransformCoord(&gotvec,&u,&mat);
1295 expect_vec3(expectedvec,gotvec);
1297 /*_______________D3DXVec3TransformNormal______________________*/
1298 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1299 D3DXVec3TransformNormal(&gotvec,&u,&mat);
1300 expect_vec3(expectedvec,gotvec);
1302 /*_______________D3DXVec3Unproject_________________________*/
1303 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1304 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1305 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1306 expect_vec3(expectedvec,gotvec);
1309 static void D3DXVector4Test(void)
1311 D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x;
1312 LPD3DXVECTOR4 funcpointer;
1313 D3DXVECTOR4 expectedtrans, gottrans;
1314 D3DXMATRIX mat;
1315 FLOAT coeff1, coeff2, expected, got, scale;
1317 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
1318 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1319 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1320 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1321 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1323 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;
1324 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;
1325 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;
1326 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;
1328 coeff1 = 2.0f; coeff2 = 5.0;
1329 scale = -6.5f;
1331 /*_______________D3DXVec4Add__________________________*/
1332 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1333 D3DXVec4Add(&gotvec,&u,&v);
1334 expect_vec4(expectedvec,gotvec);
1335 /* Tests the case NULL */
1336 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1337 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1338 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1339 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1341 /*_______________D3DXVec4BaryCentric____________________*/
1342 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
1343 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1344 expect_vec4(expectedvec,gotvec);
1346 /*_______________D3DXVec4CatmullRom____________________*/
1347 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1348 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1349 expect_vec4(expectedvec,gotvec);
1351 /*_______________D3DXVec4Cross_________________________*/
1352 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1353 D3DXVec4Cross(&gotvec,&u,&v,&w);
1354 expect_vec4(expectedvec,gotvec);
1356 /*_______________D3DXVec4Dot__________________________*/
1357 expected = 55.0f;
1358 got = D3DXVec4Dot(&u,&v);
1359 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1360 /* Tests the case NULL */
1361 expected=0.0f;
1362 got = D3DXVec4Dot(NULL,&v);
1363 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1364 expected=0.0f;
1365 got = D3DXVec4Dot(NULL,NULL);
1366 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1368 /*_______________D3DXVec4Hermite_________________________*/
1369 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1370 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1371 expect_vec4(expectedvec,gotvec);
1373 /*_______________D3DXVec4Length__________________________*/
1374 expected = 11.0f;
1375 got = D3DXVec4Length(&u);
1376 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1377 /* Tests the case NULL */
1378 expected=0.0f;
1379 got = D3DXVec4Length(NULL);
1380 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1382 /*_______________D3DXVec4LengthSq________________________*/
1383 expected = 121.0f;
1384 got = D3DXVec4LengthSq(&u);
1385 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1386 /* Tests the case NULL */
1387 expected=0.0f;
1388 got = D3DXVec4LengthSq(NULL);
1389 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1391 /*_______________D3DXVec4Lerp__________________________*/
1392 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1393 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1394 expect_vec4(expectedvec,gotvec);
1395 /* Tests the case NULL */
1396 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1397 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1398 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1399 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1401 /*_______________D3DXVec4Maximize__________________________*/
1402 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1403 D3DXVec4Maximize(&gotvec,&u,&v);
1404 expect_vec4(expectedvec,gotvec);
1405 /* Tests the case NULL */
1406 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1407 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1408 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1409 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1411 /*_______________D3DXVec4Minimize__________________________*/
1412 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1413 D3DXVec4Minimize(&gotvec,&u,&v);
1414 expect_vec4(expectedvec,gotvec);
1415 /* Tests the case NULL */
1416 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1417 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1418 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1419 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1421 /*_______________D3DXVec4Normalize_________________________*/
1422 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1423 D3DXVec4Normalize(&gotvec,&u);
1424 expect_vec4(expectedvec,gotvec);
1426 /*_______________D3DXVec4Scale____________________________*/
1427 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1428 D3DXVec4Scale(&gotvec,&u,scale);
1429 expect_vec4(expectedvec,gotvec);
1430 /* Tests the case NULL */
1431 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1432 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1433 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1434 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1436 /*_______________D3DXVec4Subtract__________________________*/
1437 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1438 D3DXVec4Subtract(&gotvec,&u,&v);
1439 expect_vec4(expectedvec,gotvec);
1440 /* Tests the case NULL */
1441 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1442 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1443 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1444 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1446 /*_______________D3DXVec4Transform_______________________*/
1447 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1448 D3DXVec4Transform(&gottrans,&u,&mat);
1449 expect_vec4(expectedtrans,gottrans);
1452 static void test_matrix_stack(void)
1454 ID3DXMatrixStack *stack;
1455 ULONG refcount;
1456 HRESULT hr;
1458 const D3DXMATRIX mat1 = {{{
1459 1.0f, 2.0f, 3.0f, 4.0f,
1460 5.0f, 6.0f, 7.0f, 8.0f,
1461 9.0f, 10.0f, 11.0f, 12.0f,
1462 13.0f, 14.0f, 15.0f, 16.0f
1463 }}};
1465 const D3DXMATRIX mat2 = {{{
1466 17.0f, 18.0f, 19.0f, 20.0f,
1467 21.0f, 22.0f, 23.0f, 24.0f,
1468 25.0f, 26.0f, 27.0f, 28.0f,
1469 29.0f, 30.0f, 31.0f, 32.0f
1470 }}};
1472 hr = D3DXCreateMatrixStack(0, &stack);
1473 ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1474 if (FAILED(hr)) return;
1476 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1477 "The top of an empty matrix stack should be an identity matrix\n");
1479 hr = ID3DXMatrixStack_Pop(stack);
1480 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1482 hr = ID3DXMatrixStack_Push(stack);
1483 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1484 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1486 hr = ID3DXMatrixStack_Push(stack);
1487 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1489 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1490 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1491 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1493 hr = ID3DXMatrixStack_Push(stack);
1494 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1495 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1497 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1498 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1499 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1501 hr = ID3DXMatrixStack_Push(stack);
1502 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1503 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1505 hr = ID3DXMatrixStack_LoadIdentity(stack);
1506 ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
1507 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1509 hr = ID3DXMatrixStack_Pop(stack);
1510 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1511 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1513 hr = ID3DXMatrixStack_Pop(stack);
1514 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1515 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1517 hr = ID3DXMatrixStack_Pop(stack);
1518 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1519 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1521 hr = ID3DXMatrixStack_Pop(stack);
1522 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1523 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1525 refcount = ID3DXMatrixStack_Release(stack);
1526 ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1529 static void test_Matrix_AffineTransformation2D(void)
1531 D3DXMATRIX exp_mat, got_mat;
1532 D3DXVECTOR2 center, position;
1533 FLOAT angle, scale;
1535 center.x = 3.0f;
1536 center.y = 4.0f;
1538 position.x = -6.0f;
1539 position.y = 7.0f;
1541 angle = D3DX_PI/3.0f;
1543 scale = 20.0f;
1545 U(exp_mat).m[0][0] = 10.0f;
1546 U(exp_mat).m[1][0] = -17.320507f;
1547 U(exp_mat).m[2][0] = 0.0f;
1548 U(exp_mat).m[3][0] = -1.035898f;
1549 U(exp_mat).m[0][1] = 17.320507f;
1550 U(exp_mat).m[1][1] = 10.0f;
1551 U(exp_mat).m[2][1] = 0.0f;
1552 U(exp_mat).m[3][1] = 6.401924f;
1553 U(exp_mat).m[0][2] = 0.0f;
1554 U(exp_mat).m[1][2] = 0.0f;
1555 U(exp_mat).m[2][2] = 1.0f;
1556 U(exp_mat).m[3][2] = 0.0f;
1557 U(exp_mat).m[0][3] = 0.0f;
1558 U(exp_mat).m[1][3] = 0.0f;
1559 U(exp_mat).m[2][3] = 0.0f;
1560 U(exp_mat).m[3][3] = 1.0f;
1562 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, &position);
1564 expect_mat(&exp_mat, &got_mat);
1566 /*______________*/
1568 center.x = 3.0f;
1569 center.y = 4.0f;
1571 angle = D3DX_PI/3.0f;
1573 scale = 20.0f;
1575 U(exp_mat).m[0][0] = 10.0f;
1576 U(exp_mat).m[1][0] = -17.320507f;
1577 U(exp_mat).m[2][0] = 0.0f;
1578 U(exp_mat).m[3][0] = 4.964102f;
1579 U(exp_mat).m[0][1] = 17.320507f;
1580 U(exp_mat).m[1][1] = 10.0f;
1581 U(exp_mat).m[2][1] = 0.0f;
1582 U(exp_mat).m[3][1] = -0.598076f;
1583 U(exp_mat).m[0][2] = 0.0f;
1584 U(exp_mat).m[1][2] = 0.0f;
1585 U(exp_mat).m[2][2] = 1.0f;
1586 U(exp_mat).m[3][2] = 0.0f;
1587 U(exp_mat).m[0][3] = 0.0f;
1588 U(exp_mat).m[1][3] = 0.0f;
1589 U(exp_mat).m[2][3] = 0.0f;
1590 U(exp_mat).m[3][3] = 1.0f;
1592 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, NULL);
1594 expect_mat(&exp_mat, &got_mat);
1596 /*______________*/
1598 position.x = -6.0f;
1599 position.y = 7.0f;
1601 angle = D3DX_PI/3.0f;
1603 scale = 20.0f;
1605 U(exp_mat).m[0][0] = 10.0f;
1606 U(exp_mat).m[1][0] = -17.320507f;
1607 U(exp_mat).m[2][0] = 0.0f;
1608 U(exp_mat).m[3][0] = -6.0f;
1609 U(exp_mat).m[0][1] = 17.320507f;
1610 U(exp_mat).m[1][1] = 10.0f;
1611 U(exp_mat).m[2][1] = 0.0f;
1612 U(exp_mat).m[3][1] = 7.0f;
1613 U(exp_mat).m[0][2] = 0.0f;
1614 U(exp_mat).m[1][2] = 0.0f;
1615 U(exp_mat).m[2][2] = 1.0f;
1616 U(exp_mat).m[3][2] = 0.0f;
1617 U(exp_mat).m[0][3] = 0.0f;
1618 U(exp_mat).m[1][3] = 0.0f;
1619 U(exp_mat).m[2][3] = 0.0f;
1620 U(exp_mat).m[3][3] = 1.0f;
1622 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, &position);
1624 expect_mat(&exp_mat, &got_mat);
1626 /*______________*/
1628 angle = 5.0f * D3DX_PI/4.0f;
1630 scale = -20.0f;
1632 U(exp_mat).m[0][0] = 14.142133f;
1633 U(exp_mat).m[1][0] = -14.142133f;
1634 U(exp_mat).m[2][0] = 0.0f;
1635 U(exp_mat).m[3][0] = 0.0f;
1636 U(exp_mat).m[0][1] = 14.142133;
1637 U(exp_mat).m[1][1] = 14.142133f;
1638 U(exp_mat).m[2][1] = 0.0f;
1639 U(exp_mat).m[3][1] = 0.0f;
1640 U(exp_mat).m[0][2] = 0.0f;
1641 U(exp_mat).m[1][2] = 0.0f;
1642 U(exp_mat).m[2][2] = 1.0f;
1643 U(exp_mat).m[3][2] = 0.0f;
1644 U(exp_mat).m[0][3] = 0.0f;
1645 U(exp_mat).m[1][3] = 0.0f;
1646 U(exp_mat).m[2][3] = 0.0f;
1647 U(exp_mat).m[3][3] = 1.0f;
1649 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, NULL);
1651 expect_mat(&exp_mat, &got_mat);
1654 static void test_Matrix_Decompose(void)
1656 D3DXMATRIX pm;
1657 D3DXQUATERNION exp_rotation, got_rotation;
1658 D3DXVECTOR3 exp_scale, got_scale, exp_translation, got_translation;
1659 HRESULT hr;
1661 /*___________*/
1663 U(pm).m[0][0] = -0.9238790f;
1664 U(pm).m[1][0] = -0.2705984f;
1665 U(pm).m[2][0] = 0.2705984f;
1666 U(pm).m[3][0] = -5.0f;
1667 U(pm).m[0][1] = 0.2705984f;
1668 U(pm).m[1][1] = 0.03806049f;
1669 U(pm).m[2][1] = 0.9619395f;
1670 U(pm).m[3][1] = 0.0f;
1671 U(pm).m[0][2] = -0.2705984f;
1672 U(pm).m[1][2] = 0.9619395f;
1673 U(pm).m[2][2] = 0.03806049f;
1674 U(pm).m[3][2] = 10.0f;
1675 U(pm).m[0][3] = 0.0f;
1676 U(pm).m[1][3] = 0.0f;
1677 U(pm).m[2][3] = 0.0f;
1678 U(pm).m[3][3] = 1.0f;
1680 exp_scale.x = 1.0f;
1681 exp_scale.y = 1.0f;
1682 exp_scale.z = 1.0f;
1684 exp_rotation.w = 0.195091f;
1685 exp_rotation.x = 0.0f;
1686 exp_rotation.y = 0.693520f;
1687 exp_rotation.z = 0.693520f;
1689 exp_translation.x = -5.0f;
1690 exp_translation.y = 0.0f;
1691 exp_translation.z = 10.0f;
1693 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1695 compare_scale(exp_scale, got_scale);
1696 compare_rotation(exp_rotation, got_rotation);
1697 compare_translation(exp_translation, got_translation);
1699 /*_________*/
1701 U(pm).m[0][0] = -2.255813f;
1702 U(pm).m[1][0] = 1.302324f;
1703 U(pm).m[2][0] = 1.488373f;
1704 U(pm).m[3][0] = 1.0f;
1705 U(pm).m[0][1] = 1.302327f;
1706 U(pm).m[1][1] = -0.7209296f;
1707 U(pm).m[2][1] = 2.60465f;
1708 U(pm).m[3][1] = 2.0f;
1709 U(pm).m[0][2] = 1.488371f;
1710 U(pm).m[1][2] = 2.604651f;
1711 U(pm).m[2][2] = -0.02325551f;
1712 U(pm).m[3][2] = 3.0f;
1713 U(pm).m[0][3] = 0.0f;
1714 U(pm).m[1][3] = 0.0f;
1715 U(pm).m[2][3] = 0.0f;
1716 U(pm).m[3][3] = 1.0f;
1718 exp_scale.x = 3.0f;
1719 exp_scale.y = 3.0f;
1720 exp_scale.z = 3.0f;
1722 exp_rotation.w = 0.0;
1723 exp_rotation.x = 0.352180f;
1724 exp_rotation.y = 0.616316f;
1725 exp_rotation.z = 0.704361f;
1727 exp_translation.x = 1.0f;
1728 exp_translation.y = 2.0f;
1729 exp_translation.z = 3.0f;
1731 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1733 compare_scale(exp_scale, got_scale);
1734 compare_rotation(exp_rotation, got_rotation);
1735 compare_translation(exp_translation, got_translation);
1737 /*_____________*/
1739 U(pm).m[0][0] = 2.427051f;
1740 U(pm).m[1][0] = 0.0f;
1741 U(pm).m[2][0] = 1.763355f;
1742 U(pm).m[3][0] = 5.0f;
1743 U(pm).m[0][1] = 0.0f;
1744 U(pm).m[1][1] = 3.0f;
1745 U(pm).m[2][1] = 0.0f;
1746 U(pm).m[3][1] = 5.0f;
1747 U(pm).m[0][2] = -1.763355f;
1748 U(pm).m[1][2] = 0.0f;
1749 U(pm).m[2][2] = 2.427051f;
1750 U(pm).m[3][2] = 5.0f;
1751 U(pm).m[0][3] = 0.0f;
1752 U(pm).m[1][3] = 0.0f;
1753 U(pm).m[2][3] = 0.0f;
1754 U(pm).m[3][3] = 1.0f;
1756 exp_scale.x = 3.0f;
1757 exp_scale.y = 3.0f;
1758 exp_scale.z = 3.0f;
1760 exp_rotation.w = 0.951057f;
1761 exp_rotation.x = 0.0f;
1762 exp_rotation.y = 0.309017f;
1763 exp_rotation.z = 0.0f;
1765 exp_translation.x = 5.0f;
1766 exp_translation.y = 5.0f;
1767 exp_translation.z = 5.0f;
1769 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1771 compare_scale(exp_scale, got_scale);
1772 compare_rotation(exp_rotation, got_rotation);
1773 compare_translation(exp_translation, got_translation);
1775 /*_____________*/
1777 U(pm).m[0][0] = -0.9238790f;
1778 U(pm).m[1][0] = -0.2705984f;
1779 U(pm).m[2][0] = 0.2705984f;
1780 U(pm).m[3][0] = -5.0f;
1781 U(pm).m[0][1] = 0.2705984f;
1782 U(pm).m[1][1] = 0.03806049f;
1783 U(pm).m[2][1] = 0.9619395f;
1784 U(pm).m[3][1] = 0.0f;
1785 U(pm).m[0][2] = -0.2705984f;
1786 U(pm).m[1][2] = 0.9619395f;
1787 U(pm).m[2][2] = 0.03806049f;
1788 U(pm).m[3][2] = 10.0f;
1789 U(pm).m[0][3] = 0.0f;
1790 U(pm).m[1][3] = 0.0f;
1791 U(pm).m[2][3] = 0.0f;
1792 U(pm).m[3][3] = 1.0f;
1794 exp_scale.x = 1.0f;
1795 exp_scale.y = 1.0f;
1796 exp_scale.z = 1.0f;
1798 exp_rotation.w = 0.195091f;
1799 exp_rotation.x = 0.0f;
1800 exp_rotation.y = 0.693520f;
1801 exp_rotation.z = 0.693520f;
1803 exp_translation.x = -5.0f;
1804 exp_translation.y = 0.0f;
1805 exp_translation.z = 10.0f;
1807 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1809 compare_scale(exp_scale, got_scale);
1810 compare_rotation(exp_rotation, got_rotation);
1811 compare_translation(exp_translation, got_translation);
1813 /*__________*/
1815 U(pm).m[0][0] = -0.9238790f;
1816 U(pm).m[1][0] = -0.5411968f;
1817 U(pm).m[2][0] = 0.8117952f;
1818 U(pm).m[3][0] = -5.0f;
1819 U(pm).m[0][1] = 0.2705984f;
1820 U(pm).m[1][1] = 0.07612098f;
1821 U(pm).m[2][1] = 2.8858185f;
1822 U(pm).m[3][1] = 0.0f;
1823 U(pm).m[0][2] = -0.2705984f;
1824 U(pm).m[1][2] = 1.9238790f;
1825 U(pm).m[2][2] = 0.11418147f;
1826 U(pm).m[3][2] = 10.0f;
1827 U(pm).m[0][3] = 0.0f;
1828 U(pm).m[1][3] = 0.0f;
1829 U(pm).m[2][3] = 0.0f;
1830 U(pm).m[3][3] = 1.0f;
1832 exp_scale.x = 1.0f;
1833 exp_scale.y = 2.0f;
1834 exp_scale.z = 3.0f;
1836 exp_rotation.w = 0.195091f;
1837 exp_rotation.x = 0.0f;
1838 exp_rotation.y = 0.693520f;
1839 exp_rotation.z = 0.693520f;
1841 exp_translation.x = -5.0f;
1842 exp_translation.y = 0.0f;
1843 exp_translation.z = 10.0f;
1845 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1847 compare_scale(exp_scale, got_scale);
1848 compare_rotation(exp_rotation, got_rotation);
1849 compare_translation(exp_translation, got_translation);
1851 /*__________*/
1853 U(pm).m[0][0] = 0.7156004f;
1854 U(pm).m[1][0] = -0.5098283f;
1855 U(pm).m[2][0] = -0.4774843f;
1856 U(pm).m[3][0] = -5.0f;
1857 U(pm).m[0][1] = -0.6612288f;
1858 U(pm).m[1][1] = -0.7147621f;
1859 U(pm).m[2][1] = -0.2277977f;
1860 U(pm).m[3][1] = 0.0f;
1861 U(pm).m[0][2] = -0.2251499f;
1862 U(pm).m[1][2] = 0.4787385f;
1863 U(pm).m[2][2] = -0.8485972f;
1864 U(pm).m[3][2] = 10.0f;
1865 U(pm).m[0][3] = 0.0f;
1866 U(pm).m[1][3] = 0.0f;
1867 U(pm).m[2][3] = 0.0f;
1868 U(pm).m[3][3] = 1.0f;
1870 exp_scale.x = 1.0f;
1871 exp_scale.y = 1.0f;
1872 exp_scale.z = 1.0f;
1874 exp_rotation.w = 0.195091f;
1875 exp_rotation.x = 0.905395f;
1876 exp_rotation.y = -0.323355f;
1877 exp_rotation.z = -0.194013f;
1879 exp_translation.x = -5.0f;
1880 exp_translation.y = 0.0f;
1881 exp_translation.z = 10.0f;
1883 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1885 compare_scale(exp_scale, got_scale);
1886 compare_rotation(exp_rotation, got_rotation);
1887 compare_translation(exp_translation, got_translation);
1889 /*_____________*/
1891 U(pm).m[0][0] = 0.06554436f;
1892 U(pm).m[1][0] = -0.6873012f;
1893 U(pm).m[2][0] = 0.7234092f;
1894 U(pm).m[3][0] = -5.0f;
1895 U(pm).m[0][1] = -0.9617381f;
1896 U(pm).m[1][1] = -0.2367795f;
1897 U(pm).m[2][1] = -0.1378230f;
1898 U(pm).m[3][1] = 0.0f;
1899 U(pm).m[0][2] = 0.2660144f;
1900 U(pm).m[1][2] = -0.6866967f;
1901 U(pm).m[2][2] = -0.6765233f;
1902 U(pm).m[3][2] = 10.0f;
1903 U(pm).m[0][3] = 0.0f;
1904 U(pm).m[1][3] = 0.0f;
1905 U(pm).m[2][3] = 0.0f;
1906 U(pm).m[3][3] = 1.0f;
1908 exp_scale.x = 1.0f;
1909 exp_scale.y = 1.0f;
1910 exp_scale.z = 1.0f;
1912 exp_rotation.w = -0.195091f;
1913 exp_rotation.x = 0.703358f;
1914 exp_rotation.y = -0.586131f;
1915 exp_rotation.z = 0.351679f;
1917 exp_translation.x = -5.0f;
1918 exp_translation.y = 0.0f;
1919 exp_translation.z = 10.0f;
1921 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1923 compare_scale(exp_scale, got_scale);
1924 compare_rotation(exp_rotation, got_rotation);
1925 compare_translation(exp_translation, got_translation);
1927 /*_________*/
1929 U(pm).m[0][0] = 7.121047f;
1930 U(pm).m[1][0] = -5.883487f;
1931 U(pm).m[2][0] = 11.81843f;
1932 U(pm).m[3][0] = -5.0f;
1933 U(pm).m[0][1] = 5.883487f;
1934 U(pm).m[1][1] = -10.60660f;
1935 U(pm).m[2][1] = -8.825232f;
1936 U(pm).m[3][1] = 0.0f;
1937 U(pm).m[0][2] = 11.81843f;
1938 U(pm).m[1][2] = 8.8252320f;
1939 U(pm).m[2][2] = -2.727645f;
1940 U(pm).m[3][2] = 2.0f;
1941 U(pm).m[0][3] = 0.0f;
1942 U(pm).m[1][3] = 0.0f;
1943 U(pm).m[2][3] = 0.0f;
1944 U(pm).m[3][3] = 1.0f;
1946 exp_scale.x = 15.0f;
1947 exp_scale.y = 15.0f;
1948 exp_scale.z = 15.0f;
1950 exp_rotation.w = 0.382684f;
1951 exp_rotation.x = 0.768714f;
1952 exp_rotation.y = 0.0f;
1953 exp_rotation.z = 0.512476f;
1955 exp_translation.x = -5.0f;
1956 exp_translation.y = 0.0f;
1957 exp_translation.z = 2.0f;
1959 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1961 compare_scale(exp_scale, got_scale);
1962 compare_rotation(exp_rotation, got_rotation);
1963 compare_translation(exp_translation, got_translation);
1965 /*__________*/
1967 U(pm).m[0][0] = 0.0f;
1968 U(pm).m[1][0] = 4.0f;
1969 U(pm).m[2][0] = 5.0f;
1970 U(pm).m[3][0] = -5.0f;
1971 U(pm).m[0][1] = 0.0f;
1972 U(pm).m[1][1] = -10.60660f;
1973 U(pm).m[2][1] = -8.825232f;
1974 U(pm).m[3][1] = 6.0f;
1975 U(pm).m[0][2] = 0.0f;
1976 U(pm).m[1][2] = 8.8252320f;
1977 U(pm).m[2][2] = 2.727645;
1978 U(pm).m[3][2] = 3.0f;
1979 U(pm).m[0][3] = 0.0f;
1980 U(pm).m[1][3] = 0.0f;
1981 U(pm).m[2][3] = 0.0f;
1982 U(pm).m[3][3] = 1.0f;
1984 hr = D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1985 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
1988 static void test_Matrix_Transformation2D(void)
1990 D3DXMATRIX exp_mat, got_mat;
1991 D3DXVECTOR2 rot_center, sca, sca_center, trans;
1992 FLOAT rot, sca_rot;
1994 rot_center.x = 3.0f;
1995 rot_center.y = 4.0f;
1997 sca.x = 12.0f;
1998 sca.y = -3.0f;
2000 sca_center.x = 9.0f;
2001 sca_center.y = -5.0f;
2003 trans.x = -6.0f;
2004 trans.y = 7.0f;
2006 rot = D3DX_PI/3.0f;
2008 sca_rot = 5.0f*D3DX_PI/4.0f;
2010 U(exp_mat).m[0][0] = -4.245192f;
2011 U(exp_mat).m[1][0] = -0.147116f;
2012 U(exp_mat).m[2][0] = 0.0f;
2013 U(exp_mat).m[3][0] = 45.265373f;
2014 U(exp_mat).m[0][1] = 7.647113f;
2015 U(exp_mat).m[1][1] = 8.745192f;
2016 U(exp_mat).m[2][1] = 0.0f;
2017 U(exp_mat).m[3][1] = -13.401899f;
2018 U(exp_mat).m[0][2] = 0.0f;
2019 U(exp_mat).m[1][2] = 0.0f;
2020 U(exp_mat).m[2][2] = 1.0f;
2021 U(exp_mat).m[3][2] = 0.0f;
2022 U(exp_mat).m[0][3] = 0.0f;
2023 U(exp_mat).m[1][3] = 0.0f;
2024 U(exp_mat).m[2][3] = 0.0f;
2025 U(exp_mat).m[3][3] = 1.0f;
2027 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
2029 expect_mat(&exp_mat, &got_mat);
2031 /*_________*/
2033 sca_center.x = 9.0f;
2034 sca_center.y = -5.0f;
2036 trans.x = -6.0f;
2037 trans.y = 7.0f;
2039 rot = D3DX_PI/3.0f;
2041 sca_rot = 5.0f*D3DX_PI/4.0f;
2043 U(exp_mat).m[0][0] = 0.50f;
2044 U(exp_mat).m[1][0] = -0.866025f;
2045 U(exp_mat).m[2][0] = 0.0f;
2046 U(exp_mat).m[3][0] = -6.0f;
2047 U(exp_mat).m[0][1] = 0.866025f;
2048 U(exp_mat).m[1][1] = 0.50f;
2049 U(exp_mat).m[2][1] = 0.0f;
2050 U(exp_mat).m[3][1] = 7.0f;
2051 U(exp_mat).m[0][2] = 0.0f;
2052 U(exp_mat).m[1][2] = 0.0f;
2053 U(exp_mat).m[2][2] = 1.0f;
2054 U(exp_mat).m[3][2] = 0.0f;
2055 U(exp_mat).m[0][3] = 0.0f;
2056 U(exp_mat).m[1][3] = 0.0f;
2057 U(exp_mat).m[2][3] = 0.0f;
2058 U(exp_mat).m[3][3] = 1.0f;
2060 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
2062 expect_mat(&exp_mat, &got_mat);
2064 /*_________*/
2066 U(exp_mat).m[0][0] = 0.50f;
2067 U(exp_mat).m[1][0] = -0.866025f;
2068 U(exp_mat).m[2][0] = 0.0f;
2069 U(exp_mat).m[3][0] = 0.0f;
2070 U(exp_mat).m[0][1] = 0.866025f;
2071 U(exp_mat).m[1][1] = 0.50f;
2072 U(exp_mat).m[2][1] = 0.0f;
2073 U(exp_mat).m[3][1] = 0.0f;
2074 U(exp_mat).m[0][2] = 0.0f;
2075 U(exp_mat).m[1][2] = 0.0f;
2076 U(exp_mat).m[2][2] = 1.0f;
2077 U(exp_mat).m[3][2] = 0.0f;
2078 U(exp_mat).m[0][3] = 0.0f;
2079 U(exp_mat).m[1][3] = 0.0f;
2080 U(exp_mat).m[2][3] = 0.0f;
2081 U(exp_mat).m[3][3] = 1.0f;
2083 D3DXMatrixTransformation2D(&got_mat, NULL, sca_rot, NULL, NULL, rot, NULL);
2085 expect_mat(&exp_mat, &got_mat);
2088 static void test_D3DXVec_Array(void)
2090 unsigned int i;
2091 D3DVIEWPORT9 viewport;
2092 D3DXMATRIX mat, projection, view, world;
2093 D3DXVECTOR4 inp_vec[ARRAY_SIZE];
2094 D3DXVECTOR4 out_vec[ARRAY_SIZE + 2];
2095 D3DXVECTOR4 exp_vec[ARRAY_SIZE + 2];
2096 D3DXPLANE inp_plane[ARRAY_SIZE];
2097 D3DXPLANE out_plane[ARRAY_SIZE + 2];
2098 D3DXPLANE exp_plane[ARRAY_SIZE + 2];
2100 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
2101 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
2103 for (i = 0; i < ARRAY_SIZE + 2; ++i) {
2104 out_vec[i].x = out_vec[i].y = out_vec[i].z = out_vec[i].w = 0.0f;
2105 exp_vec[i].x = exp_vec[i].y = exp_vec[i].z = exp_vec[i].w = 0.0f;
2106 out_plane[i].a = out_plane[i].b = out_plane[i].c = out_plane[i].d = 0.0f;
2107 exp_plane[i].a = exp_plane[i].b = exp_plane[i].c = exp_plane[i].d = 0.0f;
2110 for (i = 0; i < ARRAY_SIZE; ++i) {
2111 inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
2112 inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE - i;
2115 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;
2116 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;
2117 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;
2118 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;
2120 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2122 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
2123 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
2124 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
2125 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
2126 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
2127 U(view).m[3][3] = -40.0f;
2129 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;
2130 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;
2131 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;
2132 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;
2134 /* D3DXVec2TransformCoordArray */
2135 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f;
2136 exp_vec[2].x = 0.653846f; exp_vec[2].y = 0.769231f;
2137 exp_vec[3].x = 0.625f; exp_vec[3].y = 0.75f;
2138 exp_vec[4].x = 0.590909f; exp_vec[4].y = 8.0f/11.0f;
2139 exp_vec[5].x = 0.55f; exp_vec[5].y = 0.7f;
2140 D3DXVec2TransformCoordArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2141 compare_vectors(exp_vec, out_vec);
2143 /* D3DXVec2TransformNormalArray */
2144 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
2145 exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
2146 exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
2147 exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
2148 exp_vec[5].x = 9.0f; exp_vec[5].y = 14.0f;
2149 D3DXVec2TransformNormalArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2150 compare_vectors(exp_vec, out_vec);
2152 /* D3DXVec3TransformCoordArray */
2153 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f; exp_vec[1].z = 0.892857f;
2154 exp_vec[2].x = 0.671875f; exp_vec[2].y = 0.78125f; exp_vec[2].z = 0.890625f;
2155 exp_vec[3].x = 6.0f/9.0f; exp_vec[3].y = 7.0f/9.0f; exp_vec[3].z = 8.0f/9.0f;
2156 exp_vec[4].x = 0.6625f; exp_vec[4].y = 0.775f; exp_vec[4].z = 0.8875f;
2157 exp_vec[5].x = 0.659091f; exp_vec[5].y = 0.772727f; exp_vec[5].z = 0.886364f;
2158 D3DXVec3TransformCoordArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2159 compare_vectors(exp_vec, out_vec);
2161 /* D3DXVec3TransformNormalArray */
2162 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
2163 exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
2164 exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
2165 exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
2166 exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
2167 D3DXVec3TransformNormalArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2168 compare_vectors(exp_vec, out_vec);
2170 /* D3DXVec3ProjectArray */
2171 exp_vec[1].x = 1089.554199f; exp_vec[1].y = -226.590622f; exp_vec[1].z = 0.215273f;
2172 exp_vec[2].x = 1068.903320f; exp_vec[2].y = 103.085129f; exp_vec[2].z = 0.183050f;
2173 exp_vec[3].x = 1051.778931f; exp_vec[3].y = 376.462250f; exp_vec[3].z = 0.156329f;
2174 exp_vec[4].x = 1037.348877f; exp_vec[4].y = 606.827393f; exp_vec[4].z = 0.133813f;
2175 exp_vec[5].x = 1025.023560f; exp_vec[5].y = 803.591248f; exp_vec[5].z = 0.114581f;
2176 D3DXVec3ProjectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2177 compare_vectors(exp_vec, out_vec);
2179 /* D3DXVec3UnprojectArray */
2180 exp_vec[1].x = -6.124031f; exp_vec[1].y = 3.225360f; exp_vec[1].z = 0.620571f;
2181 exp_vec[2].x = -3.807109f; exp_vec[2].y = 2.046579f; exp_vec[2].z = 0.446894f;
2182 exp_vec[3].x = -2.922839f; exp_vec[3].y = 1.596689f; exp_vec[3].z = 0.380609f;
2183 exp_vec[4].x = -2.456225f; exp_vec[4].y = 1.359290f; exp_vec[4].z = 0.345632f;
2184 exp_vec[5].x = -2.167897f; exp_vec[5].y = 1.212597f; exp_vec[5].z = 0.324019f;
2185 D3DXVec3UnprojectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2186 compare_vectors(exp_vec, out_vec);
2188 /* D3DXVec2TransformArray */
2189 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2190 exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
2191 exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
2192 exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
2193 exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
2194 D3DXVec2TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2195 compare_vectors(exp_vec, out_vec);
2197 /* D3DXVec3TransformArray */
2198 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2199 exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
2200 exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
2201 exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
2202 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2203 D3DXVec3TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2204 compare_vectors(exp_vec, out_vec);
2206 /* D3DXVec4TransformArray */
2207 exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
2208 exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f; exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
2209 exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f; exp_vec[3].z = 94.0f; exp_vec[3].w = 104.0f;
2210 exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f; exp_vec[4].z = 86.0f; exp_vec[4].w = 96.0f;
2211 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2212 D3DXVec4TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2213 compare_vectors(exp_vec, out_vec);
2215 /* D3DXPlaneTransformArray */
2216 exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
2217 exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f; exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
2218 exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f; exp_plane[3].c = 94.0f; exp_plane[3].d = 104.0f;
2219 exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f; exp_plane[4].c = 86.0f; exp_plane[4].d = 96.0f;
2220 exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f; exp_plane[5].c = 78.0f; exp_plane[5].d = 88.0f;
2221 D3DXPlaneTransformArray(out_plane + 1, sizeof(D3DXPLANE), inp_plane, sizeof(D3DXPLANE), &mat, ARRAY_SIZE);
2222 compare_planes(exp_plane, out_plane);
2225 START_TEST(math)
2227 D3DXColorTest();
2228 D3DXFresnelTest();
2229 D3DXMatrixTest();
2230 D3DXPlaneTest();
2231 D3DXQuaternionTest();
2232 D3DXVector2Test();
2233 D3DXVector3Test();
2234 D3DXVector4Test();
2235 test_matrix_stack();
2236 test_Matrix_AffineTransformation2D();
2237 test_Matrix_Decompose();
2238 test_Matrix_Transformation2D();
2239 test_D3DXVec_Array();