d3dx9_36: Implementation of D3DXSHRotateZ.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / math.c
blobd1bcfcfcfe1326fd5a189be2e4c2c503bdab8580
1 /*
2 * Copyright 2008 David Adam
3 * Copyright 2008 Luis Busquets
4 * Copyright 2008 Philip Nilsson
5 * Copyright 2008 Henri Verbeet
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
23 #include "d3dx9.h"
24 #include <math.h>
26 #define ARRAY_SIZE 5
28 #define admitted_error 0.0001f
30 #define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1.0f - (out) / (exp))))
32 #define expect_color(expectedcolor,gotcolor) ok((relative_error(expectedcolor.r, gotcolor.r)<admitted_error)&&(relative_error(expectedcolor.g, gotcolor.g)<admitted_error)&&(relative_error(expectedcolor.b, gotcolor.b)<admitted_error)&&(relative_error(expectedcolor.a, gotcolor.a)<admitted_error),"Expected Color= (%f, %f, %f, %f)\n , Got Color= (%f, %f, %f, %f)\n", expectedcolor.r, expectedcolor.g, expectedcolor.b, expectedcolor.a, gotcolor.r, gotcolor.g, gotcolor.b, gotcolor.a);
34 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
36 int i, j;
38 for (i = 0; i < 4; ++i)
40 for (j = 0; j < 4; ++j)
42 if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
43 return FALSE;
47 return TRUE;
50 #define expect_mat(expectedmat, gotmat) \
51 do { \
52 const D3DXMATRIX *__m1 = (expectedmat); \
53 const D3DXMATRIX *__m2 = (gotmat); \
54 ok(compare_matrix(__m1, __m2), "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \
55 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
56 U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
57 U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
58 U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
59 U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
60 U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
61 U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
62 U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
63 U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
64 } while(0)
66 #define compare_rotation(exp, got) \
67 ok(relative_error(exp.w, got.w) < admitted_error && \
68 relative_error(exp.x, got.x) < admitted_error && \
69 relative_error(exp.y, got.y) < admitted_error && \
70 relative_error(exp.z, got.z) < admitted_error, \
71 "Expected rotation = (%f, %f, %f, %f), \
72 got rotation = (%f, %f, %f, %f)\n", \
73 exp.w, exp.x, exp.y, exp.z, got.w, got.x, got.y, got.z)
75 #define compare_scale(exp, got) \
76 ok(relative_error(exp.x, got.x) < admitted_error && \
77 relative_error(exp.y, got.y) < admitted_error && \
78 relative_error(exp.z, got.z) < admitted_error, \
79 "Expected scale = (%f, %f, %f), \
80 got scale = (%f, %f, %f)\n", \
81 exp.x, exp.y, exp.z, got.x, got.y, got.z)
83 #define compare_translation(exp, got) \
84 ok(relative_error(exp.x, got.x) < admitted_error && \
85 relative_error(exp.y, got.y) < admitted_error && \
86 relative_error(exp.z, got.z) < admitted_error, \
87 "Expected translation = (%f, %f, %f), \
88 got translation = (%f, %f, %f)\n", \
89 exp.x, exp.y, exp.z, got.x, got.y, got.z)
91 #define compare_vectors(exp, out) \
92 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
93 ok(relative_error(exp[i].x, out[i].x) < admitted_error && \
94 relative_error(exp[i].y, out[i].y) < admitted_error && \
95 relative_error(exp[i].z, out[i].z) < admitted_error && \
96 relative_error(exp[i].w, out[i].w) < admitted_error, \
97 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
98 out[i].x, out[i].y, out[i].z, out[i].w, \
99 exp[i].x, exp[i].y, exp[i].z, exp[i].w, \
100 i); \
103 #define compare_planes(exp, out) \
104 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
105 ok(relative_error(exp[i].a, out[i].a) < admitted_error && \
106 relative_error(exp[i].b, out[i].b) < admitted_error && \
107 relative_error(exp[i].c, out[i].c) < admitted_error && \
108 relative_error(exp[i].d, out[i].d) < admitted_error, \
109 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
110 out[i].a, out[i].b, out[i].c, out[i].d, \
111 exp[i].a, exp[i].b, exp[i].c, exp[i].d, \
112 i); \
115 #define expect_plane(expectedplane,gotplane) ok((relative_error(expectedplane.a, gotplane.a)<admitted_error)&&(relative_error(expectedplane.b, gotplane.b)<admitted_error)&&(relative_error(expectedplane.c, gotplane.c)<admitted_error)&&(relative_error(expectedplane.d, gotplane.d)<admitted_error),"Expected Plane= (%f, %f, %f, %f)\n , Got Plane= (%f, %f, %f, %f)\n", expectedplane.a, expectedplane.b, expectedplane.c, expectedplane.d, gotplane.a, gotplane.b, gotplane.c, gotplane.d);
117 #define expect_vec(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
119 #define expect_vec3(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error)&&(relative_error(expectedvec.z, gotvec.z)<admitted_error),"Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x, gotvec.y, gotvec.z);
121 #define expect_vec4(expectedvec,gotvec) ok((relative_error(expectedvec.x, gotvec.x)<admitted_error)&&(relative_error(expectedvec.y, gotvec.y)<admitted_error)&&(relative_error(expectedvec.z, gotvec.z)<admitted_error)&&(relative_error(expectedvec.w, gotvec.w)<admitted_error),"Expected Vector= (%f, %f, %f, %f)\n , Got Vector= (%f, %f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, expectedvec.w, gotvec.x, gotvec.y, gotvec.z, gotvec.w);
124 static void D3DXColorTest(void)
126 D3DXCOLOR color, color1, color2, expected, got;
127 LPD3DXCOLOR funcpointer;
128 FLOAT scale;
130 color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
131 color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
132 color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
134 scale = 0.3f;
136 /*_______________D3DXColorAdd________________*/
137 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
138 D3DXColorAdd(&got,&color1,&color2);
139 expect_color(expected,got);
140 /* Test the NULL case */
141 funcpointer = D3DXColorAdd(&got,NULL,&color2);
142 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
143 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
144 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
145 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
146 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
148 /*_______________D3DXColorAdjustContrast______*/
149 expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
150 D3DXColorAdjustContrast(&got,&color,scale);
151 expect_color(expected,got);
153 /*_______________D3DXColorAdjustSaturation______*/
154 expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
155 D3DXColorAdjustSaturation(&got,&color,scale);
156 expect_color(expected,got);
158 /*_______________D3DXColorLerp________________*/
159 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
160 D3DXColorLerp(&got,&color,&color1,scale);
161 expect_color(expected,got);
162 /* Test the NULL case */
163 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
164 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
165 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
166 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
167 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
168 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
170 /*_______________D3DXColorModulate________________*/
171 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
172 D3DXColorModulate(&got,&color1,&color2);
173 expect_color(expected,got);
174 /* Test the NULL case */
175 funcpointer = D3DXColorModulate(&got,NULL,&color2);
176 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
177 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
178 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
179 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
180 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
182 /*_______________D3DXColorNegative________________*/
183 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
184 D3DXColorNegative(&got,&color);
185 expect_color(got,expected);
186 /* Test the greater than 1 case */
187 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
188 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
189 D3DXColorNegative(&got,&color1);
190 expect_color(got,expected);
191 /* Test the negative case */
192 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
193 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
194 D3DXColorNegative(&got,&color1);
195 expect_color(got,expected);
196 /* Test the NULL case */
197 funcpointer = D3DXColorNegative(&got,NULL);
198 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
199 funcpointer = D3DXColorNegative(NULL,NULL);
200 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
202 /*_______________D3DXColorScale________________*/
203 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
204 D3DXColorScale(&got,&color,scale);
205 expect_color(expected,got);
206 /* Test the NULL case */
207 funcpointer = D3DXColorScale(&got,NULL,scale);
208 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
209 funcpointer = D3DXColorScale(NULL,NULL,scale);
210 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
212 /*_______________D3DXColorSubtract_______________*/
213 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
214 D3DXColorSubtract(&got,&color,&color2);
215 expect_color(expected,got);
216 /* Test the NULL case */
217 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
218 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
219 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
220 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
221 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
222 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
225 static void D3DXFresnelTest(void)
227 FLOAT expected, got;
229 expected = 0.089187;
230 got = D3DXFresnelTerm(0.5f,1.5);
231 ok(relative_error(got, expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
234 static void D3DXMatrixTest(void)
236 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
237 LPD3DXMATRIX funcpointer;
238 D3DXPLANE plane;
239 D3DXQUATERNION q, r;
240 D3DXVECTOR3 at, axis, eye, last;
241 D3DXVECTOR4 light;
242 BOOL expected, got;
243 FLOAT angle, determinant, expectedfloat, gotfloat;
245 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
246 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
247 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
248 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
249 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
250 U(mat).m[3][3] = -40.0f;
252 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
253 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
254 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
255 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
256 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
257 U(mat2).m[3][3] = -1.0f;
259 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
261 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
262 r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
264 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
265 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
266 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
267 last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
269 light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
271 angle = D3DX_PI/3.0f;
273 /*____________D3DXMatrixAffineTransformation______*/
274 U(expectedmat).m[0][0] = -459.239990f; U(expectedmat).m[0][1] = -576.719971f; U(expectedmat).m[0][2] = -263.440002f; U(expectedmat).m[0][3] = 0.0f;
275 U(expectedmat).m[1][0] = 519.760010f; U(expectedmat).m[1][1] = -352.440002f; U(expectedmat).m[1][2] = -277.679993f; U(expectedmat).m[1][3] = 0.0f;
276 U(expectedmat).m[2][0] = 363.119995f; U(expectedmat).m[2][1] = -121.040001f; U(expectedmat).m[2][2] = -117.479996f; U(expectedmat).m[2][3] = 0.0f;
277 U(expectedmat).m[3][0] = -1239.0f; U(expectedmat).m[3][1] = 667.0f; U(expectedmat).m[3][2] = 567.0f; U(expectedmat).m[3][3] = 1.0f;
278 D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
279 expect_mat(&expectedmat, &gotmat);
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);
622 /*_______________D3DXPlaneTransform____________*/
623 expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
624 D3DXPlaneTransform(&gotplane,&plane,&mat);
625 expect_plane(expectedplane, gotplane);
628 static void D3DXQuaternionTest(void)
630 D3DXMATRIX mat;
631 D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
632 LPD3DXQUATERNION funcpointer;
633 D3DXVECTOR3 axis, expectedvec;
634 FLOAT angle, expected, got, scale, scale2;
635 BOOL expectedbool, gotbool;
637 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
638 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
639 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
640 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
641 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
642 smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
643 smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallr.w = 0.8f;
645 scale = 0.3f;
646 scale2 = 0.78f;
648 /*_______________D3DXQuaternionBaryCentric________________________*/
649 expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
650 D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
651 expect_vec4(expectedquat,gotquat);
653 /*_______________D3DXQuaternionConjugate________________*/
654 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
655 D3DXQuaternionConjugate(&gotquat,&q);
656 expect_vec4(expectedquat,gotquat);
657 /* Test the NULL case */
658 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
659 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
660 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
661 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
663 /*_______________D3DXQuaternionDot______________________*/
664 expected = 55.0f;
665 got = D3DXQuaternionDot(&q,&r);
666 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
667 /* Tests the case NULL */
668 expected=0.0f;
669 got = D3DXQuaternionDot(NULL,&r);
670 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
671 expected=0.0f;
672 got = D3DXQuaternionDot(NULL,NULL);
673 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
675 /*_______________D3DXQuaternionExp______________________________*/
676 expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
677 D3DXQuaternionExp(&gotquat,&q);
678 expect_vec4(expectedquat,gotquat);
679 /* Test the null quaternion */
680 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
681 D3DXQuaternionExp(&gotquat,&nul);
682 expect_vec4(expectedquat,gotquat);
683 /* Test the case where the norm of the quaternion is <1 */
684 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
685 expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
686 D3DXQuaternionExp(&gotquat,&Nq1);
687 expect_vec4(expectedquat,gotquat);
689 /*_______________D3DXQuaternionIdentity________________*/
690 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
691 D3DXQuaternionIdentity(&gotquat);
692 expect_vec4(expectedquat,gotquat);
693 /* Test the NULL case */
694 funcpointer = D3DXQuaternionIdentity(NULL);
695 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
697 /*_______________D3DXQuaternionInverse________________________*/
698 expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
699 D3DXQuaternionInverse(&gotquat,&q);
700 expect_vec4(expectedquat,gotquat);
702 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 10.0f;
703 D3DXQuaternionInverse(&gotquat,&gotquat);
704 expect_vec4(expectedquat,gotquat);
707 /*_______________D3DXQuaternionIsIdentity________________*/
708 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
709 expectedbool = TRUE;
710 gotbool = D3DXQuaternionIsIdentity(&s);
711 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
712 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
713 expectedbool = FALSE;
714 gotbool = D3DXQuaternionIsIdentity(&q);
715 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
716 /* Test the NULL case */
717 gotbool = D3DXQuaternionIsIdentity(NULL);
718 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
720 /*_______________D3DXQuaternionLength__________________________*/
721 expected = 11.0f;
722 got = D3DXQuaternionLength(&q);
723 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
724 /* Tests the case NULL */
725 expected=0.0f;
726 got = D3DXQuaternionLength(NULL);
727 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
729 /*_______________D3DXQuaternionLengthSq________________________*/
730 expected = 121.0f;
731 got = D3DXQuaternionLengthSq(&q);
732 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
733 /* Tests the case NULL */
734 expected=0.0f;
735 got = D3DXQuaternionLengthSq(NULL);
736 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
738 /*_______________D3DXQuaternionLn______________________________*/
739 expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
740 D3DXQuaternionLn(&gotquat,&q);
741 expect_vec4(expectedquat,gotquat);
742 expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
743 D3DXQuaternionLn(&gotquat,&r);
744 expect_vec4(expectedquat,gotquat);
745 Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
746 expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
747 D3DXQuaternionLn(&gotquat,&Nq);
748 expect_vec4(expectedquat,gotquat);
749 Nq.x = 0.0f; Nq.y = 0.0f; Nq.z = 0.0f; Nq.w = 1.0f;
750 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
751 D3DXQuaternionLn(&gotquat,&Nq);
752 expect_vec4(expectedquat,gotquat);
753 Nq.x = 5.4f; Nq.y = 1.2f; Nq.z = -0.3f; Nq.w = -0.3f;
754 expectedquat.x = 10.616652f; expectedquat.y = 2.359256f; expectedquat.z = -0.589814f; expectedquat.w = 0.0f;
755 D3DXQuaternionLn(&gotquat,&Nq);
756 expect_vec4(expectedquat,gotquat);
757 /* Test the case where the norm of the quaternion is <1 */
758 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = 0.9f;
759 expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
760 D3DXQuaternionLn(&gotquat,&Nq1);
761 expect_vec4(expectedquat,gotquat);
762 /* Test the case where the real part of the quaternion is -1.0f */
763 Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w = -1.0f;
764 expectedquat.x = 0.2f; expectedquat.y = 0.1f; expectedquat.z = 0.3f; expectedquat.w = 0.0f;
765 D3DXQuaternionLn(&gotquat,&Nq1);
766 expect_vec4(expectedquat,gotquat);
768 /*_______________D3DXQuaternionMultiply________________________*/
769 expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
770 D3DXQuaternionMultiply(&gotquat,&q,&r);
771 expect_vec4(expectedquat,gotquat);
773 /*_______________D3DXQuaternionNormalize________________________*/
774 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
775 D3DXQuaternionNormalize(&gotquat,&q);
776 expect_vec4(expectedquat,gotquat);
778 /*_______________D3DXQuaternionRotationAxis___________________*/
779 axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
780 angle = D3DX_PI/3.0f;
781 expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
782 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
783 expect_vec4(expectedquat,gotquat);
784 /* Test the nul quaternion */
785 axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
786 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
787 D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
788 expect_vec4(expectedquat,gotquat);
790 /*_______________D3DXQuaternionRotationMatrix___________________*/
791 /* test when the trace is >0 */
792 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
793 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
794 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
795 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
796 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
797 U(mat).m[3][3] = 48.0f;
798 expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
799 D3DXQuaternionRotationMatrix(&gotquat,&mat);
800 expect_vec4(expectedquat,gotquat);
801 /* test the case when the greater element is (2,2) */
802 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
803 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
804 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
805 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
806 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
807 U(mat).m[3][3] = 48.0f;
808 expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
809 D3DXQuaternionRotationMatrix(&gotquat,&mat);
810 expect_vec4(expectedquat,gotquat);
811 /* test the case when the greater element is (1,1) */
812 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
813 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
814 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
815 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
816 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
817 U(mat).m[3][3] = 48.0f;
818 expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
819 D3DXQuaternionRotationMatrix(&gotquat,&mat);
820 expect_vec4(expectedquat,gotquat);
821 /* test the case when the trace is near 0 in a matrix which is not a rotation */
822 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
823 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
824 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
825 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
826 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
827 U(mat).m[3][3] = 48.0f;
828 expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
829 D3DXQuaternionRotationMatrix(&gotquat,&mat);
830 expect_vec4(expectedquat,gotquat);
831 /* test the case when the trace is 0.49 in a matrix which is not a rotation */
832 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
833 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
834 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
835 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
836 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
837 U(mat).m[3][3] = 48.0f;
838 expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
839 D3DXQuaternionRotationMatrix(&gotquat,&mat);
840 expect_vec4(expectedquat,gotquat);
841 /* test the case when the trace is 0.51 in a matrix which is not a rotation */
842 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
843 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
844 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
845 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
846 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
847 U(mat).m[3][3] = 48.0f;
848 expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
849 D3DXQuaternionRotationMatrix(&gotquat,&mat);
850 expect_vec4(expectedquat,gotquat);
851 /* test the case when the trace is 0.99 in a matrix which is not a rotation */
852 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
853 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
854 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
855 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
856 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
857 U(mat).m[3][3] = 48.0f;
858 expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
859 D3DXQuaternionRotationMatrix(&gotquat,&mat);
860 expect_vec4(expectedquat,gotquat);
861 /* test the case when the trace is 1.0 in a matrix which is not a rotation */
862 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
863 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
864 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
865 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
866 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
867 U(mat).m[3][3] = 48.0f;
868 expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
869 D3DXQuaternionRotationMatrix(&gotquat,&mat);
870 expect_vec4(expectedquat,gotquat);
871 /* test the case when the trace is 1.01 in a matrix which is not a rotation */
872 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
873 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
874 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
875 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
876 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
877 U(mat).m[3][3] = 48.0f;
878 expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
879 D3DXQuaternionRotationMatrix(&gotquat,&mat);
880 expect_vec4(expectedquat,gotquat);
881 /* test the case when the trace is 1.5 in a matrix which is not a rotation */
882 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
883 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
884 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
885 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
886 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
887 U(mat).m[3][3] = 48.0f;
888 expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
889 D3DXQuaternionRotationMatrix(&gotquat,&mat);
890 expect_vec4(expectedquat,gotquat);
891 /* test the case when the trace is 1.7 in a matrix which is not a rotation */
892 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
893 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
894 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
895 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
896 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
897 U(mat).m[3][3] = 48.0f;
898 expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
899 D3DXQuaternionRotationMatrix(&gotquat,&mat);
900 expect_vec4(expectedquat,gotquat);
901 /* test the case when the trace is 1.99 in a matrix which is not a rotation */
902 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
903 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
904 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
905 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
906 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
907 U(mat).m[3][3] = 48.0f;
908 expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
909 D3DXQuaternionRotationMatrix(&gotquat,&mat);
910 expect_vec4(expectedquat,gotquat);
911 /* test the case when the trace is 2.0 in a matrix which is not a rotation */
912 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
913 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
914 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
915 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
916 U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
917 U(mat).m[3][3] = 48.0f;
918 expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
919 D3DXQuaternionRotationMatrix(&gotquat,&mat);
920 expect_vec4(expectedquat,gotquat);
922 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
923 expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
924 D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
925 expect_vec4(expectedquat,gotquat);
927 /*_______________D3DXQuaternionSlerp________________________*/
928 expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
929 D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
930 expect_vec4(expectedquat,gotquat);
931 expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
932 D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
933 expect_vec4(expectedquat,gotquat);
934 expectedquat.x = 0.239485f; expectedquat.y = 0.346580f; expectedquat.z = 0.453676f; expectedquat.w = 0.560772f;
935 D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
936 expect_vec4(expectedquat,gotquat);
938 /*_______________D3DXQuaternionSquad________________________*/
939 expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
940 D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
941 expect_vec4(expectedquat,gotquat);
943 /*_______________D3DXQuaternionSquadSetup___________________*/
944 r.x = 1.0f, r.y = 2.0f; r.z = 4.0f; r.w = 10.0f;
945 s.x = -3.0f; s.y = 4.0f; s.z = -5.0f; s.w = 7.0;
946 t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
947 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
948 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
949 expectedquat.x = 7.121285f; expectedquat.y = 2.159964f; expectedquat.z = -3.855094f; expectedquat.w = 5.362844f;
950 expect_vec4(expectedquat,gotquat);
951 expectedquat.x = -1113.492920f; expectedquat.y = 82.679260f; expectedquat.z = -6.696645f; expectedquat.w = -4.090050f;
952 expect_vec4(expectedquat,Nq);
953 expectedquat.x = -1111.0f; expectedquat.y = 111.0f; expectedquat.z = -11.0f; expectedquat.w = 1.0f;
954 expect_vec4(expectedquat,Nq1);
955 r.x = 0.2f; r.y = 0.3f; r.z = 1.3f; r.w = -0.6f;
956 s.x = -3.0f; s.y =-2.0f; s.z = 4.0f; s.w = 0.2f;
957 t.x = 0.4f; t.y = 8.3f; t.z = -3.1f; t.w = -2.7f;
958 u.x = 1.1f; u.y = -0.7f; u.z = 9.2f; u.w = 0.0f;
959 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&u,&t);
960 expectedquat.x = -4.139569f; expectedquat.y = -2.469115f; expectedquat.z = 2.364477f; expectedquat.w = 0.465494f;
961 expect_vec4(expectedquat,gotquat);
962 expectedquat.x = 2.342533f; expectedquat.y = 2.365127f; expectedquat.z = 8.628538f; expectedquat.w = -0.898356f;
963 expect_vec4(expectedquat,Nq);
964 expectedquat.x = 1.1f; expectedquat.y = -0.7f; expectedquat.z = 9.2f; expectedquat.w = 0.0f;
965 expect_vec4(expectedquat,Nq1);
966 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
967 expectedquat.x = -3.754567f; expectedquat.y = -0.586085f; expectedquat.z = 3.815818f; expectedquat.w = -0.198150f;
968 expect_vec4(expectedquat,gotquat);
969 expectedquat.x = 0.140773f; expectedquat.y = -8.737090f; expectedquat.z = -0.516593f; expectedquat.w = 3.053942f;
970 expect_vec4(expectedquat,Nq);
971 expectedquat.x = -0.4f; expectedquat.y = -8.3f; expectedquat.z = 3.1f; expectedquat.w = 2.7f;
972 expect_vec4(expectedquat,Nq1);
973 r.x = -1.0f; r.y = 0.0f; r.z = 0.0f; r.w = 0.0f;
974 s.x = 1.0f; s.y =0.0f; s.z = 0.0f; s.w = 0.0f;
975 t.x = 1.0f; t.y = 0.0f; t.z = 0.0f; t.w = 0.0f;
976 u.x = -1.0f; u.y = 0.0f; u.z = 0.0f; u.w = 0.0f;
977 D3DXQuaternionSquadSetup(&gotquat,&Nq,&Nq1,&r,&s,&t,&u);
978 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
979 expect_vec4(expectedquat,gotquat);
980 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
981 expect_vec4(expectedquat,Nq);
982 expectedquat.x = 1.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
983 expect_vec4(expectedquat,Nq1);
985 /*_______________D3DXQuaternionToAxisAngle__________________*/
986 Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
987 expectedvec.x = 1.0f/22.0f; expectedvec.y = 2.0f/22.0f; expectedvec.z = 4.0f/22.0f;
988 expected = 2.197869f;
989 D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
990 expect_vec3(expectedvec,axis);
991 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
992 /* Test if |w|>1.0f */
993 expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f;
994 D3DXQuaternionToAxisAngle(&q,&axis,&angle);
995 expect_vec3(expectedvec,axis);
996 /* Test the null quaternion */
997 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
998 expected = 3.141593f;
999 D3DXQuaternionToAxisAngle(&nul,&axis,&angle);
1000 expect_vec3(expectedvec,axis);
1001 ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
1004 static void D3DXVector2Test(void)
1006 D3DXVECTOR2 expectedvec, gotvec, nul, u, v, w, x;
1007 LPD3DXVECTOR2 funcpointer;
1008 D3DXVECTOR4 expectedtrans, gottrans;
1009 D3DXMATRIX mat;
1010 FLOAT coeff1, coeff2, expected, got, scale;
1012 nul.x = 0.0f; nul.y = 0.0f;
1013 u.x = 3.0f; u.y = 4.0f;
1014 v.x = -7.0f; v.y = 9.0f;
1015 w.x = 4.0f; w.y = -3.0f;
1016 x.x = 2.0f; x.y = -11.0f;
1018 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;
1019 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;
1020 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;
1021 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;
1023 coeff1 = 2.0f; coeff2 = 5.0f;
1024 scale = -6.5f;
1026 /*_______________D3DXVec2Add__________________________*/
1027 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
1028 D3DXVec2Add(&gotvec,&u,&v);
1029 expect_vec(expectedvec,gotvec);
1030 /* Tests the case NULL */
1031 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
1032 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1033 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
1034 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1036 /*_______________D3DXVec2BaryCentric___________________*/
1037 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
1038 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1039 expect_vec(expectedvec,gotvec);
1041 /*_______________D3DXVec2CatmullRom____________________*/
1042 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
1043 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1044 expect_vec(expectedvec,gotvec);
1046 /*_______________D3DXVec2CCW__________________________*/
1047 expected = 55.0f;
1048 got = D3DXVec2CCW(&u,&v);
1049 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1050 /* Tests the case NULL */
1051 expected=0.0f;
1052 got = D3DXVec2CCW(NULL,&v);
1053 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1054 expected=0.0f;
1055 got = D3DXVec2CCW(NULL,NULL);
1056 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1058 /*_______________D3DXVec2Dot__________________________*/
1059 expected = 15.0f;
1060 got = D3DXVec2Dot(&u,&v);
1061 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1062 /* Tests the case NULL */
1063 expected=0.0f;
1064 got = D3DXVec2Dot(NULL,&v);
1065 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1066 expected=0.0f;
1067 got = D3DXVec2Dot(NULL,NULL);
1068 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1070 /*_______________D3DXVec2Hermite__________________________*/
1071 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
1072 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
1073 expect_vec(expectedvec,gotvec);
1075 /*_______________D3DXVec2Length__________________________*/
1076 expected = 5.0f;
1077 got = D3DXVec2Length(&u);
1078 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1079 /* Tests the case NULL */
1080 expected=0.0f;
1081 got = D3DXVec2Length(NULL);
1082 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1084 /*_______________D3DXVec2LengthSq________________________*/
1085 expected = 25.0f;
1086 got = D3DXVec2LengthSq(&u);
1087 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1088 /* Tests the case NULL */
1089 expected=0.0f;
1090 got = D3DXVec2LengthSq(NULL);
1091 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1093 /*_______________D3DXVec2Lerp__________________________*/
1094 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
1095 D3DXVec2Lerp(&gotvec,&u,&v,scale);
1096 expect_vec(expectedvec,gotvec);
1097 /* Tests the case NULL */
1098 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
1099 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1100 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1101 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1103 /*_______________D3DXVec2Maximize__________________________*/
1104 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1105 D3DXVec2Maximize(&gotvec,&u,&v);
1106 expect_vec(expectedvec,gotvec);
1107 /* Tests the case NULL */
1108 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1109 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1110 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1111 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1113 /*_______________D3DXVec2Minimize__________________________*/
1114 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1115 D3DXVec2Minimize(&gotvec,&u,&v);
1116 expect_vec(expectedvec,gotvec);
1117 /* Tests the case NULL */
1118 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1119 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1120 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1121 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1123 /*_______________D3DXVec2Normalize_________________________*/
1124 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1125 D3DXVec2Normalize(&gotvec,&u);
1126 expect_vec(expectedvec,gotvec);
1127 /* Test the nul vector */
1128 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1129 D3DXVec2Normalize(&gotvec,&nul);
1130 expect_vec(expectedvec,gotvec);
1132 /*_______________D3DXVec2Scale____________________________*/
1133 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1134 D3DXVec2Scale(&gotvec,&u,scale);
1135 expect_vec(expectedvec,gotvec);
1136 /* Tests the case NULL */
1137 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
1138 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1139 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
1140 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1142 /*_______________D3DXVec2Subtract__________________________*/
1143 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
1144 D3DXVec2Subtract(&gotvec,&u,&v);
1145 expect_vec(expectedvec,gotvec);
1146 /* Tests the case NULL */
1147 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
1148 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1149 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
1150 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1152 /*_______________D3DXVec2Transform_______________________*/
1153 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
1154 D3DXVec2Transform(&gottrans,&u,&mat);
1155 expect_vec4(expectedtrans,gottrans);
1157 /*_______________D3DXVec2TransformCoord_______________________*/
1158 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
1159 D3DXVec2TransformCoord(&gotvec,&u,&mat);
1160 expect_vec(expectedvec,gotvec);
1162 /*_______________D3DXVec2TransformNormal______________________*/
1163 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1164 D3DXVec2TransformNormal(&gotvec,&u,&mat);
1165 expect_vec(expectedvec,gotvec);
1168 static void D3DXVector3Test(void)
1170 D3DVIEWPORT9 viewport;
1171 D3DXVECTOR3 expectedvec, gotvec, nul, u, v, w, x;
1172 LPD3DXVECTOR3 funcpointer;
1173 D3DXVECTOR4 expectedtrans, gottrans;
1174 D3DXMATRIX mat, projection, view, world;
1175 FLOAT coeff1, coeff2, expected, got, scale;
1177 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
1178 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
1179 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
1180 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
1181 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
1183 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1184 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
1186 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;
1187 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;
1188 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;
1189 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;
1191 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
1192 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
1193 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
1194 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
1195 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
1196 U(view).m[3][3] = -40.0f;
1198 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;
1199 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;
1200 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;
1201 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;
1203 coeff1 = 2.0f; coeff2 = 5.0f;
1204 scale = -6.5f;
1206 /*_______________D3DXVec3Add__________________________*/
1207 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
1208 D3DXVec3Add(&gotvec,&u,&v);
1209 expect_vec3(expectedvec,gotvec);
1210 /* Tests the case NULL */
1211 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
1212 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1213 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
1214 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1216 /*_______________D3DXVec3BaryCentric___________________*/
1217 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1218 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1220 expect_vec3(expectedvec,gotvec);
1222 /*_______________D3DXVec3CatmullRom____________________*/
1223 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
1224 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1225 expect_vec3(expectedvec,gotvec);
1227 /*_______________D3DXVec3Cross________________________*/
1228 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
1229 D3DXVec3Cross(&gotvec,&u,&v);
1230 expect_vec3(expectedvec,gotvec);
1231 /* Tests the case NULL */
1232 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
1233 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1234 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
1235 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1237 /*_______________D3DXVec3Dot__________________________*/
1238 expected = -8.0f;
1239 got = D3DXVec3Dot(&u,&v);
1240 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1241 /* Tests the case NULL */
1242 expected=0.0f;
1243 got = D3DXVec3Dot(NULL,&v);
1244 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1245 expected=0.0f;
1246 got = D3DXVec3Dot(NULL,NULL);
1247 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1249 /*_______________D3DXVec3Hermite__________________________*/
1250 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
1251 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
1252 expect_vec3(expectedvec,gotvec);
1254 /*_______________D3DXVec3Length__________________________*/
1255 expected = 11.0f;
1256 got = D3DXVec3Length(&u);
1257 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1258 /* Tests the case NULL */
1259 expected=0.0f;
1260 got = D3DXVec3Length(NULL);
1261 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1263 /*_______________D3DXVec3LengthSq________________________*/
1264 expected = 121.0f;
1265 got = D3DXVec3LengthSq(&u);
1266 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1267 /* Tests the case NULL */
1268 expected=0.0f;
1269 got = D3DXVec3LengthSq(NULL);
1270 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1272 /*_______________D3DXVec3Lerp__________________________*/
1273 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
1274 D3DXVec3Lerp(&gotvec,&u,&v,scale);
1275 expect_vec3(expectedvec,gotvec);
1276 /* Tests the case NULL */
1277 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
1278 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1279 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
1280 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1282 /*_______________D3DXVec3Maximize__________________________*/
1283 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
1284 D3DXVec3Maximize(&gotvec,&u,&v);
1285 expect_vec3(expectedvec,gotvec);
1286 /* Tests the case NULL */
1287 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
1288 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1289 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
1290 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1292 /*_______________D3DXVec3Minimize__________________________*/
1293 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
1294 D3DXVec3Minimize(&gotvec,&u,&v);
1295 expect_vec3(expectedvec,gotvec);
1296 /* Tests the case NULL */
1297 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
1298 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1299 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
1300 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1302 /*_______________D3DXVec3Normalize_________________________*/
1303 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
1304 D3DXVec3Normalize(&gotvec,&u);
1305 expect_vec3(expectedvec,gotvec);
1306 /* Test the nul vector */
1307 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1308 D3DXVec3Normalize(&gotvec,&nul);
1309 expect_vec3(expectedvec,gotvec);
1311 /*_______________D3DXVec3Project_________________________*/
1312 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
1313 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1314 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
1315 expect_vec3(expectedvec,gotvec);
1317 /*_______________D3DXVec3Scale____________________________*/
1318 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
1319 D3DXVec3Scale(&gotvec,&u,scale);
1320 expect_vec3(expectedvec,gotvec);
1321 /* Tests the case NULL */
1322 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
1323 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1324 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
1325 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1327 /*_______________D3DXVec3Subtract_______________________*/
1328 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1329 D3DXVec3Subtract(&gotvec,&u,&v);
1330 expect_vec3(expectedvec,gotvec);
1331 /* Tests the case NULL */
1332 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1333 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1334 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1335 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1337 /*_______________D3DXVec3Transform_______________________*/
1338 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1339 D3DXVec3Transform(&gottrans,&u,&mat);
1340 expect_vec4(expectedtrans,gottrans);
1342 /*_______________D3DXVec3TransformCoord_______________________*/
1343 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1344 D3DXVec3TransformCoord(&gotvec,&u,&mat);
1345 expect_vec3(expectedvec,gotvec);
1347 /*_______________D3DXVec3TransformNormal______________________*/
1348 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1349 D3DXVec3TransformNormal(&gotvec,&u,&mat);
1350 expect_vec3(expectedvec,gotvec);
1352 /*_______________D3DXVec3Unproject_________________________*/
1353 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1354 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1355 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1356 expect_vec3(expectedvec,gotvec);
1357 /* World matrix can be omitted */
1358 D3DXMatrixMultiply(&mat,&world,&view);
1359 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&mat,NULL);
1360 expect_vec3(expectedvec,gotvec);
1363 static void D3DXVector4Test(void)
1365 D3DXVECTOR4 expectedvec, gotvec, u, v, w, x;
1366 LPD3DXVECTOR4 funcpointer;
1367 D3DXVECTOR4 expectedtrans, gottrans;
1368 D3DXMATRIX mat;
1369 FLOAT coeff1, coeff2, expected, got, scale;
1371 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1372 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1373 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1374 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1376 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;
1377 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;
1378 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;
1379 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;
1381 coeff1 = 2.0f; coeff2 = 5.0;
1382 scale = -6.5f;
1384 /*_______________D3DXVec4Add__________________________*/
1385 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1386 D3DXVec4Add(&gotvec,&u,&v);
1387 expect_vec4(expectedvec,gotvec);
1388 /* Tests the case NULL */
1389 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1390 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1391 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1392 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1394 /*_______________D3DXVec4BaryCentric____________________*/
1395 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
1396 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1397 expect_vec4(expectedvec,gotvec);
1399 /*_______________D3DXVec4CatmullRom____________________*/
1400 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1401 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1402 expect_vec4(expectedvec,gotvec);
1404 /*_______________D3DXVec4Cross_________________________*/
1405 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1406 D3DXVec4Cross(&gotvec,&u,&v,&w);
1407 expect_vec4(expectedvec,gotvec);
1409 /*_______________D3DXVec4Dot__________________________*/
1410 expected = 55.0f;
1411 got = D3DXVec4Dot(&u,&v);
1412 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1413 /* Tests the case NULL */
1414 expected=0.0f;
1415 got = D3DXVec4Dot(NULL,&v);
1416 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1417 expected=0.0f;
1418 got = D3DXVec4Dot(NULL,NULL);
1419 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1421 /*_______________D3DXVec4Hermite_________________________*/
1422 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1423 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1424 expect_vec4(expectedvec,gotvec);
1426 /*_______________D3DXVec4Length__________________________*/
1427 expected = 11.0f;
1428 got = D3DXVec4Length(&u);
1429 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1430 /* Tests the case NULL */
1431 expected=0.0f;
1432 got = D3DXVec4Length(NULL);
1433 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1435 /*_______________D3DXVec4LengthSq________________________*/
1436 expected = 121.0f;
1437 got = D3DXVec4LengthSq(&u);
1438 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1439 /* Tests the case NULL */
1440 expected=0.0f;
1441 got = D3DXVec4LengthSq(NULL);
1442 ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1444 /*_______________D3DXVec4Lerp__________________________*/
1445 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1446 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1447 expect_vec4(expectedvec,gotvec);
1448 /* Tests the case NULL */
1449 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1450 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1451 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1452 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1454 /*_______________D3DXVec4Maximize__________________________*/
1455 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1456 D3DXVec4Maximize(&gotvec,&u,&v);
1457 expect_vec4(expectedvec,gotvec);
1458 /* Tests the case NULL */
1459 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1460 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1461 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1462 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1464 /*_______________D3DXVec4Minimize__________________________*/
1465 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1466 D3DXVec4Minimize(&gotvec,&u,&v);
1467 expect_vec4(expectedvec,gotvec);
1468 /* Tests the case NULL */
1469 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1470 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1471 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1472 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1474 /*_______________D3DXVec4Normalize_________________________*/
1475 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1476 D3DXVec4Normalize(&gotvec,&u);
1477 expect_vec4(expectedvec,gotvec);
1479 /*_______________D3DXVec4Scale____________________________*/
1480 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1481 D3DXVec4Scale(&gotvec,&u,scale);
1482 expect_vec4(expectedvec,gotvec);
1483 /* Tests the case NULL */
1484 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1485 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1486 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1487 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1489 /*_______________D3DXVec4Subtract__________________________*/
1490 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1491 D3DXVec4Subtract(&gotvec,&u,&v);
1492 expect_vec4(expectedvec,gotvec);
1493 /* Tests the case NULL */
1494 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1495 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1496 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1497 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1499 /*_______________D3DXVec4Transform_______________________*/
1500 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1501 D3DXVec4Transform(&gottrans,&u,&mat);
1502 expect_vec4(expectedtrans,gottrans);
1505 static void test_matrix_stack(void)
1507 ID3DXMatrixStack *stack;
1508 ULONG refcount;
1509 HRESULT hr;
1511 const D3DXMATRIX mat1 = {{{
1512 1.0f, 2.0f, 3.0f, 4.0f,
1513 5.0f, 6.0f, 7.0f, 8.0f,
1514 9.0f, 10.0f, 11.0f, 12.0f,
1515 13.0f, 14.0f, 15.0f, 16.0f
1516 }}};
1518 const D3DXMATRIX mat2 = {{{
1519 17.0f, 18.0f, 19.0f, 20.0f,
1520 21.0f, 22.0f, 23.0f, 24.0f,
1521 25.0f, 26.0f, 27.0f, 28.0f,
1522 29.0f, 30.0f, 31.0f, 32.0f
1523 }}};
1525 hr = D3DXCreateMatrixStack(0, &stack);
1526 ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1527 if (FAILED(hr)) return;
1529 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1530 "The top of an empty matrix stack should be an identity matrix\n");
1532 hr = ID3DXMatrixStack_Pop(stack);
1533 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1535 hr = ID3DXMatrixStack_Push(stack);
1536 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1537 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1539 hr = ID3DXMatrixStack_Push(stack);
1540 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1542 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1543 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1544 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1546 hr = ID3DXMatrixStack_Push(stack);
1547 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1548 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1550 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1551 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1552 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1554 hr = ID3DXMatrixStack_Push(stack);
1555 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1556 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1558 hr = ID3DXMatrixStack_LoadIdentity(stack);
1559 ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
1560 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1562 hr = ID3DXMatrixStack_Pop(stack);
1563 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1564 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1566 hr = ID3DXMatrixStack_Pop(stack);
1567 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1568 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1570 hr = ID3DXMatrixStack_Pop(stack);
1571 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1572 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1574 hr = ID3DXMatrixStack_Pop(stack);
1575 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1576 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1578 refcount = ID3DXMatrixStack_Release(stack);
1579 ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1582 static void test_Matrix_AffineTransformation2D(void)
1584 D3DXMATRIX exp_mat, got_mat;
1585 D3DXVECTOR2 center, position;
1586 FLOAT angle, scale;
1588 center.x = 3.0f;
1589 center.y = 4.0f;
1591 position.x = -6.0f;
1592 position.y = 7.0f;
1594 angle = D3DX_PI/3.0f;
1596 scale = 20.0f;
1598 U(exp_mat).m[0][0] = 10.0f;
1599 U(exp_mat).m[1][0] = -17.320507f;
1600 U(exp_mat).m[2][0] = 0.0f;
1601 U(exp_mat).m[3][0] = -1.035898f;
1602 U(exp_mat).m[0][1] = 17.320507f;
1603 U(exp_mat).m[1][1] = 10.0f;
1604 U(exp_mat).m[2][1] = 0.0f;
1605 U(exp_mat).m[3][1] = 6.401924f;
1606 U(exp_mat).m[0][2] = 0.0f;
1607 U(exp_mat).m[1][2] = 0.0f;
1608 U(exp_mat).m[2][2] = 1.0f;
1609 U(exp_mat).m[3][2] = 0.0f;
1610 U(exp_mat).m[0][3] = 0.0f;
1611 U(exp_mat).m[1][3] = 0.0f;
1612 U(exp_mat).m[2][3] = 0.0f;
1613 U(exp_mat).m[3][3] = 1.0f;
1615 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, &position);
1617 expect_mat(&exp_mat, &got_mat);
1619 /*______________*/
1621 center.x = 3.0f;
1622 center.y = 4.0f;
1624 angle = D3DX_PI/3.0f;
1626 scale = 20.0f;
1628 U(exp_mat).m[0][0] = 10.0f;
1629 U(exp_mat).m[1][0] = -17.320507f;
1630 U(exp_mat).m[2][0] = 0.0f;
1631 U(exp_mat).m[3][0] = 4.964102f;
1632 U(exp_mat).m[0][1] = 17.320507f;
1633 U(exp_mat).m[1][1] = 10.0f;
1634 U(exp_mat).m[2][1] = 0.0f;
1635 U(exp_mat).m[3][1] = -0.598076f;
1636 U(exp_mat).m[0][2] = 0.0f;
1637 U(exp_mat).m[1][2] = 0.0f;
1638 U(exp_mat).m[2][2] = 1.0f;
1639 U(exp_mat).m[3][2] = 0.0f;
1640 U(exp_mat).m[0][3] = 0.0f;
1641 U(exp_mat).m[1][3] = 0.0f;
1642 U(exp_mat).m[2][3] = 0.0f;
1643 U(exp_mat).m[3][3] = 1.0f;
1645 D3DXMatrixAffineTransformation2D(&got_mat, scale, &center, angle, NULL);
1647 expect_mat(&exp_mat, &got_mat);
1649 /*______________*/
1651 position.x = -6.0f;
1652 position.y = 7.0f;
1654 angle = D3DX_PI/3.0f;
1656 scale = 20.0f;
1658 U(exp_mat).m[0][0] = 10.0f;
1659 U(exp_mat).m[1][0] = -17.320507f;
1660 U(exp_mat).m[2][0] = 0.0f;
1661 U(exp_mat).m[3][0] = -6.0f;
1662 U(exp_mat).m[0][1] = 17.320507f;
1663 U(exp_mat).m[1][1] = 10.0f;
1664 U(exp_mat).m[2][1] = 0.0f;
1665 U(exp_mat).m[3][1] = 7.0f;
1666 U(exp_mat).m[0][2] = 0.0f;
1667 U(exp_mat).m[1][2] = 0.0f;
1668 U(exp_mat).m[2][2] = 1.0f;
1669 U(exp_mat).m[3][2] = 0.0f;
1670 U(exp_mat).m[0][3] = 0.0f;
1671 U(exp_mat).m[1][3] = 0.0f;
1672 U(exp_mat).m[2][3] = 0.0f;
1673 U(exp_mat).m[3][3] = 1.0f;
1675 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, &position);
1677 expect_mat(&exp_mat, &got_mat);
1679 /*______________*/
1681 angle = 5.0f * D3DX_PI/4.0f;
1683 scale = -20.0f;
1685 U(exp_mat).m[0][0] = 14.142133f;
1686 U(exp_mat).m[1][0] = -14.142133f;
1687 U(exp_mat).m[2][0] = 0.0f;
1688 U(exp_mat).m[3][0] = 0.0f;
1689 U(exp_mat).m[0][1] = 14.142133;
1690 U(exp_mat).m[1][1] = 14.142133f;
1691 U(exp_mat).m[2][1] = 0.0f;
1692 U(exp_mat).m[3][1] = 0.0f;
1693 U(exp_mat).m[0][2] = 0.0f;
1694 U(exp_mat).m[1][2] = 0.0f;
1695 U(exp_mat).m[2][2] = 1.0f;
1696 U(exp_mat).m[3][2] = 0.0f;
1697 U(exp_mat).m[0][3] = 0.0f;
1698 U(exp_mat).m[1][3] = 0.0f;
1699 U(exp_mat).m[2][3] = 0.0f;
1700 U(exp_mat).m[3][3] = 1.0f;
1702 D3DXMatrixAffineTransformation2D(&got_mat, scale, NULL, angle, NULL);
1704 expect_mat(&exp_mat, &got_mat);
1707 static void test_Matrix_Decompose(void)
1709 D3DXMATRIX pm;
1710 D3DXQUATERNION exp_rotation, got_rotation;
1711 D3DXVECTOR3 exp_scale, got_scale, exp_translation, got_translation;
1712 HRESULT hr;
1714 /*___________*/
1716 U(pm).m[0][0] = -0.9238790f;
1717 U(pm).m[1][0] = -0.2705984f;
1718 U(pm).m[2][0] = 0.2705984f;
1719 U(pm).m[3][0] = -5.0f;
1720 U(pm).m[0][1] = 0.2705984f;
1721 U(pm).m[1][1] = 0.03806049f;
1722 U(pm).m[2][1] = 0.9619395f;
1723 U(pm).m[3][1] = 0.0f;
1724 U(pm).m[0][2] = -0.2705984f;
1725 U(pm).m[1][2] = 0.9619395f;
1726 U(pm).m[2][2] = 0.03806049f;
1727 U(pm).m[3][2] = 10.0f;
1728 U(pm).m[0][3] = 0.0f;
1729 U(pm).m[1][3] = 0.0f;
1730 U(pm).m[2][3] = 0.0f;
1731 U(pm).m[3][3] = 1.0f;
1733 exp_scale.x = 1.0f;
1734 exp_scale.y = 1.0f;
1735 exp_scale.z = 1.0f;
1737 exp_rotation.w = 0.195091f;
1738 exp_rotation.x = 0.0f;
1739 exp_rotation.y = 0.693520f;
1740 exp_rotation.z = 0.693520f;
1742 exp_translation.x = -5.0f;
1743 exp_translation.y = 0.0f;
1744 exp_translation.z = 10.0f;
1746 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1748 compare_scale(exp_scale, got_scale);
1749 compare_rotation(exp_rotation, got_rotation);
1750 compare_translation(exp_translation, got_translation);
1752 /*_________*/
1754 U(pm).m[0][0] = -2.255813f;
1755 U(pm).m[1][0] = 1.302324f;
1756 U(pm).m[2][0] = 1.488373f;
1757 U(pm).m[3][0] = 1.0f;
1758 U(pm).m[0][1] = 1.302327f;
1759 U(pm).m[1][1] = -0.7209296f;
1760 U(pm).m[2][1] = 2.60465f;
1761 U(pm).m[3][1] = 2.0f;
1762 U(pm).m[0][2] = 1.488371f;
1763 U(pm).m[1][2] = 2.604651f;
1764 U(pm).m[2][2] = -0.02325551f;
1765 U(pm).m[3][2] = 3.0f;
1766 U(pm).m[0][3] = 0.0f;
1767 U(pm).m[1][3] = 0.0f;
1768 U(pm).m[2][3] = 0.0f;
1769 U(pm).m[3][3] = 1.0f;
1771 exp_scale.x = 3.0f;
1772 exp_scale.y = 3.0f;
1773 exp_scale.z = 3.0f;
1775 exp_rotation.w = 0.0;
1776 exp_rotation.x = 0.352180f;
1777 exp_rotation.y = 0.616316f;
1778 exp_rotation.z = 0.704361f;
1780 exp_translation.x = 1.0f;
1781 exp_translation.y = 2.0f;
1782 exp_translation.z = 3.0f;
1784 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1786 compare_scale(exp_scale, got_scale);
1787 compare_rotation(exp_rotation, got_rotation);
1788 compare_translation(exp_translation, got_translation);
1790 /*_____________*/
1792 U(pm).m[0][0] = 2.427051f;
1793 U(pm).m[1][0] = 0.0f;
1794 U(pm).m[2][0] = 1.763355f;
1795 U(pm).m[3][0] = 5.0f;
1796 U(pm).m[0][1] = 0.0f;
1797 U(pm).m[1][1] = 3.0f;
1798 U(pm).m[2][1] = 0.0f;
1799 U(pm).m[3][1] = 5.0f;
1800 U(pm).m[0][2] = -1.763355f;
1801 U(pm).m[1][2] = 0.0f;
1802 U(pm).m[2][2] = 2.427051f;
1803 U(pm).m[3][2] = 5.0f;
1804 U(pm).m[0][3] = 0.0f;
1805 U(pm).m[1][3] = 0.0f;
1806 U(pm).m[2][3] = 0.0f;
1807 U(pm).m[3][3] = 1.0f;
1809 exp_scale.x = 3.0f;
1810 exp_scale.y = 3.0f;
1811 exp_scale.z = 3.0f;
1813 exp_rotation.w = 0.951057f;
1814 exp_rotation.x = 0.0f;
1815 exp_rotation.y = 0.309017f;
1816 exp_rotation.z = 0.0f;
1818 exp_translation.x = 5.0f;
1819 exp_translation.y = 5.0f;
1820 exp_translation.z = 5.0f;
1822 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1824 compare_scale(exp_scale, got_scale);
1825 compare_rotation(exp_rotation, got_rotation);
1826 compare_translation(exp_translation, got_translation);
1828 /*_____________*/
1830 U(pm).m[0][0] = -0.9238790f;
1831 U(pm).m[1][0] = -0.2705984f;
1832 U(pm).m[2][0] = 0.2705984f;
1833 U(pm).m[3][0] = -5.0f;
1834 U(pm).m[0][1] = 0.2705984f;
1835 U(pm).m[1][1] = 0.03806049f;
1836 U(pm).m[2][1] = 0.9619395f;
1837 U(pm).m[3][1] = 0.0f;
1838 U(pm).m[0][2] = -0.2705984f;
1839 U(pm).m[1][2] = 0.9619395f;
1840 U(pm).m[2][2] = 0.03806049f;
1841 U(pm).m[3][2] = 10.0f;
1842 U(pm).m[0][3] = 0.0f;
1843 U(pm).m[1][3] = 0.0f;
1844 U(pm).m[2][3] = 0.0f;
1845 U(pm).m[3][3] = 1.0f;
1847 exp_scale.x = 1.0f;
1848 exp_scale.y = 1.0f;
1849 exp_scale.z = 1.0f;
1851 exp_rotation.w = 0.195091f;
1852 exp_rotation.x = 0.0f;
1853 exp_rotation.y = 0.693520f;
1854 exp_rotation.z = 0.693520f;
1856 exp_translation.x = -5.0f;
1857 exp_translation.y = 0.0f;
1858 exp_translation.z = 10.0f;
1860 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1862 compare_scale(exp_scale, got_scale);
1863 compare_rotation(exp_rotation, got_rotation);
1864 compare_translation(exp_translation, got_translation);
1866 /*__________*/
1868 U(pm).m[0][0] = -0.9238790f;
1869 U(pm).m[1][0] = -0.5411968f;
1870 U(pm).m[2][0] = 0.8117952f;
1871 U(pm).m[3][0] = -5.0f;
1872 U(pm).m[0][1] = 0.2705984f;
1873 U(pm).m[1][1] = 0.07612098f;
1874 U(pm).m[2][1] = 2.8858185f;
1875 U(pm).m[3][1] = 0.0f;
1876 U(pm).m[0][2] = -0.2705984f;
1877 U(pm).m[1][2] = 1.9238790f;
1878 U(pm).m[2][2] = 0.11418147f;
1879 U(pm).m[3][2] = 10.0f;
1880 U(pm).m[0][3] = 0.0f;
1881 U(pm).m[1][3] = 0.0f;
1882 U(pm).m[2][3] = 0.0f;
1883 U(pm).m[3][3] = 1.0f;
1885 exp_scale.x = 1.0f;
1886 exp_scale.y = 2.0f;
1887 exp_scale.z = 3.0f;
1889 exp_rotation.w = 0.195091f;
1890 exp_rotation.x = 0.0f;
1891 exp_rotation.y = 0.693520f;
1892 exp_rotation.z = 0.693520f;
1894 exp_translation.x = -5.0f;
1895 exp_translation.y = 0.0f;
1896 exp_translation.z = 10.0f;
1898 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1900 compare_scale(exp_scale, got_scale);
1901 compare_rotation(exp_rotation, got_rotation);
1902 compare_translation(exp_translation, got_translation);
1904 /*__________*/
1906 U(pm).m[0][0] = 0.7156004f;
1907 U(pm).m[1][0] = -0.5098283f;
1908 U(pm).m[2][0] = -0.4774843f;
1909 U(pm).m[3][0] = -5.0f;
1910 U(pm).m[0][1] = -0.6612288f;
1911 U(pm).m[1][1] = -0.7147621f;
1912 U(pm).m[2][1] = -0.2277977f;
1913 U(pm).m[3][1] = 0.0f;
1914 U(pm).m[0][2] = -0.2251499f;
1915 U(pm).m[1][2] = 0.4787385f;
1916 U(pm).m[2][2] = -0.8485972f;
1917 U(pm).m[3][2] = 10.0f;
1918 U(pm).m[0][3] = 0.0f;
1919 U(pm).m[1][3] = 0.0f;
1920 U(pm).m[2][3] = 0.0f;
1921 U(pm).m[3][3] = 1.0f;
1923 exp_scale.x = 1.0f;
1924 exp_scale.y = 1.0f;
1925 exp_scale.z = 1.0f;
1927 exp_rotation.w = 0.195091f;
1928 exp_rotation.x = 0.905395f;
1929 exp_rotation.y = -0.323355f;
1930 exp_rotation.z = -0.194013f;
1932 exp_translation.x = -5.0f;
1933 exp_translation.y = 0.0f;
1934 exp_translation.z = 10.0f;
1936 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1938 compare_scale(exp_scale, got_scale);
1939 compare_rotation(exp_rotation, got_rotation);
1940 compare_translation(exp_translation, got_translation);
1942 /*_____________*/
1944 U(pm).m[0][0] = 0.06554436f;
1945 U(pm).m[1][0] = -0.6873012f;
1946 U(pm).m[2][0] = 0.7234092f;
1947 U(pm).m[3][0] = -5.0f;
1948 U(pm).m[0][1] = -0.9617381f;
1949 U(pm).m[1][1] = -0.2367795f;
1950 U(pm).m[2][1] = -0.1378230f;
1951 U(pm).m[3][1] = 0.0f;
1952 U(pm).m[0][2] = 0.2660144f;
1953 U(pm).m[1][2] = -0.6866967f;
1954 U(pm).m[2][2] = -0.6765233f;
1955 U(pm).m[3][2] = 10.0f;
1956 U(pm).m[0][3] = 0.0f;
1957 U(pm).m[1][3] = 0.0f;
1958 U(pm).m[2][3] = 0.0f;
1959 U(pm).m[3][3] = 1.0f;
1961 exp_scale.x = 1.0f;
1962 exp_scale.y = 1.0f;
1963 exp_scale.z = 1.0f;
1965 exp_rotation.w = -0.195091f;
1966 exp_rotation.x = 0.703358f;
1967 exp_rotation.y = -0.586131f;
1968 exp_rotation.z = 0.351679f;
1970 exp_translation.x = -5.0f;
1971 exp_translation.y = 0.0f;
1972 exp_translation.z = 10.0f;
1974 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
1976 compare_scale(exp_scale, got_scale);
1977 compare_rotation(exp_rotation, got_rotation);
1978 compare_translation(exp_translation, got_translation);
1980 /*_________*/
1982 U(pm).m[0][0] = 7.121047f;
1983 U(pm).m[1][0] = -5.883487f;
1984 U(pm).m[2][0] = 11.81843f;
1985 U(pm).m[3][0] = -5.0f;
1986 U(pm).m[0][1] = 5.883487f;
1987 U(pm).m[1][1] = -10.60660f;
1988 U(pm).m[2][1] = -8.825232f;
1989 U(pm).m[3][1] = 0.0f;
1990 U(pm).m[0][2] = 11.81843f;
1991 U(pm).m[1][2] = 8.8252320f;
1992 U(pm).m[2][2] = -2.727645f;
1993 U(pm).m[3][2] = 2.0f;
1994 U(pm).m[0][3] = 0.0f;
1995 U(pm).m[1][3] = 0.0f;
1996 U(pm).m[2][3] = 0.0f;
1997 U(pm).m[3][3] = 1.0f;
1999 exp_scale.x = 15.0f;
2000 exp_scale.y = 15.0f;
2001 exp_scale.z = 15.0f;
2003 exp_rotation.w = 0.382684f;
2004 exp_rotation.x = 0.768714f;
2005 exp_rotation.y = 0.0f;
2006 exp_rotation.z = 0.512476f;
2008 exp_translation.x = -5.0f;
2009 exp_translation.y = 0.0f;
2010 exp_translation.z = 2.0f;
2012 D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2014 compare_scale(exp_scale, got_scale);
2015 compare_rotation(exp_rotation, got_rotation);
2016 compare_translation(exp_translation, got_translation);
2018 /*__________*/
2020 U(pm).m[0][0] = 0.0f;
2021 U(pm).m[1][0] = 4.0f;
2022 U(pm).m[2][0] = 5.0f;
2023 U(pm).m[3][0] = -5.0f;
2024 U(pm).m[0][1] = 0.0f;
2025 U(pm).m[1][1] = -10.60660f;
2026 U(pm).m[2][1] = -8.825232f;
2027 U(pm).m[3][1] = 6.0f;
2028 U(pm).m[0][2] = 0.0f;
2029 U(pm).m[1][2] = 8.8252320f;
2030 U(pm).m[2][2] = 2.727645;
2031 U(pm).m[3][2] = 3.0f;
2032 U(pm).m[0][3] = 0.0f;
2033 U(pm).m[1][3] = 0.0f;
2034 U(pm).m[2][3] = 0.0f;
2035 U(pm).m[3][3] = 1.0f;
2037 hr = D3DXMatrixDecompose(&got_scale, &got_rotation, &got_translation, &pm);
2038 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %x\n", hr);
2041 static void test_Matrix_Transformation2D(void)
2043 D3DXMATRIX exp_mat, got_mat;
2044 D3DXVECTOR2 rot_center, sca, sca_center, trans;
2045 FLOAT rot, sca_rot;
2047 rot_center.x = 3.0f;
2048 rot_center.y = 4.0f;
2050 sca.x = 12.0f;
2051 sca.y = -3.0f;
2053 sca_center.x = 9.0f;
2054 sca_center.y = -5.0f;
2056 trans.x = -6.0f;
2057 trans.y = 7.0f;
2059 rot = D3DX_PI/3.0f;
2061 sca_rot = 5.0f*D3DX_PI/4.0f;
2063 U(exp_mat).m[0][0] = -4.245192f;
2064 U(exp_mat).m[1][0] = -0.147116f;
2065 U(exp_mat).m[2][0] = 0.0f;
2066 U(exp_mat).m[3][0] = 45.265373f;
2067 U(exp_mat).m[0][1] = 7.647113f;
2068 U(exp_mat).m[1][1] = 8.745192f;
2069 U(exp_mat).m[2][1] = 0.0f;
2070 U(exp_mat).m[3][1] = -13.401899f;
2071 U(exp_mat).m[0][2] = 0.0f;
2072 U(exp_mat).m[1][2] = 0.0f;
2073 U(exp_mat).m[2][2] = 1.0f;
2074 U(exp_mat).m[3][2] = 0.0f;
2075 U(exp_mat).m[0][3] = 0.0f;
2076 U(exp_mat).m[1][3] = 0.0f;
2077 U(exp_mat).m[2][3] = 0.0f;
2078 U(exp_mat).m[3][3] = 1.0f;
2080 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, &sca, &rot_center, rot, &trans);
2082 expect_mat(&exp_mat, &got_mat);
2084 /*_________*/
2086 sca_center.x = 9.0f;
2087 sca_center.y = -5.0f;
2089 trans.x = -6.0f;
2090 trans.y = 7.0f;
2092 rot = D3DX_PI/3.0f;
2094 sca_rot = 5.0f*D3DX_PI/4.0f;
2096 U(exp_mat).m[0][0] = 0.50f;
2097 U(exp_mat).m[1][0] = -0.866025f;
2098 U(exp_mat).m[2][0] = 0.0f;
2099 U(exp_mat).m[3][0] = -6.0f;
2100 U(exp_mat).m[0][1] = 0.866025f;
2101 U(exp_mat).m[1][1] = 0.50f;
2102 U(exp_mat).m[2][1] = 0.0f;
2103 U(exp_mat).m[3][1] = 7.0f;
2104 U(exp_mat).m[0][2] = 0.0f;
2105 U(exp_mat).m[1][2] = 0.0f;
2106 U(exp_mat).m[2][2] = 1.0f;
2107 U(exp_mat).m[3][2] = 0.0f;
2108 U(exp_mat).m[0][3] = 0.0f;
2109 U(exp_mat).m[1][3] = 0.0f;
2110 U(exp_mat).m[2][3] = 0.0f;
2111 U(exp_mat).m[3][3] = 1.0f;
2113 D3DXMatrixTransformation2D(&got_mat, &sca_center, sca_rot, NULL, NULL, rot, &trans);
2115 expect_mat(&exp_mat, &got_mat);
2117 /*_________*/
2119 U(exp_mat).m[0][0] = 0.50f;
2120 U(exp_mat).m[1][0] = -0.866025f;
2121 U(exp_mat).m[2][0] = 0.0f;
2122 U(exp_mat).m[3][0] = 0.0f;
2123 U(exp_mat).m[0][1] = 0.866025f;
2124 U(exp_mat).m[1][1] = 0.50f;
2125 U(exp_mat).m[2][1] = 0.0f;
2126 U(exp_mat).m[3][1] = 0.0f;
2127 U(exp_mat).m[0][2] = 0.0f;
2128 U(exp_mat).m[1][2] = 0.0f;
2129 U(exp_mat).m[2][2] = 1.0f;
2130 U(exp_mat).m[3][2] = 0.0f;
2131 U(exp_mat).m[0][3] = 0.0f;
2132 U(exp_mat).m[1][3] = 0.0f;
2133 U(exp_mat).m[2][3] = 0.0f;
2134 U(exp_mat).m[3][3] = 1.0f;
2136 D3DXMatrixTransformation2D(&got_mat, NULL, sca_rot, NULL, NULL, rot, NULL);
2138 expect_mat(&exp_mat, &got_mat);
2141 static void test_D3DXVec_Array(void)
2143 unsigned int i;
2144 D3DVIEWPORT9 viewport;
2145 D3DXMATRIX mat, projection, view, world;
2146 D3DXVECTOR4 inp_vec[ARRAY_SIZE];
2147 D3DXVECTOR4 out_vec[ARRAY_SIZE + 2];
2148 D3DXVECTOR4 exp_vec[ARRAY_SIZE + 2];
2149 D3DXPLANE inp_plane[ARRAY_SIZE];
2150 D3DXPLANE out_plane[ARRAY_SIZE + 2];
2151 D3DXPLANE exp_plane[ARRAY_SIZE + 2];
2153 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
2154 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
2156 for (i = 0; i < ARRAY_SIZE + 2; ++i) {
2157 out_vec[i].x = out_vec[i].y = out_vec[i].z = out_vec[i].w = 0.0f;
2158 exp_vec[i].x = exp_vec[i].y = exp_vec[i].z = exp_vec[i].w = 0.0f;
2159 out_plane[i].a = out_plane[i].b = out_plane[i].c = out_plane[i].d = 0.0f;
2160 exp_plane[i].a = exp_plane[i].b = exp_plane[i].c = exp_plane[i].d = 0.0f;
2163 for (i = 0; i < ARRAY_SIZE; ++i) {
2164 inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
2165 inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE - i;
2168 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;
2169 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;
2170 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;
2171 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;
2173 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
2175 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
2176 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
2177 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
2178 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
2179 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
2180 U(view).m[3][3] = -40.0f;
2182 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;
2183 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;
2184 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;
2185 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;
2187 /* D3DXVec2TransformCoordArray */
2188 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f;
2189 exp_vec[2].x = 0.653846f; exp_vec[2].y = 0.769231f;
2190 exp_vec[3].x = 0.625f; exp_vec[3].y = 0.75f;
2191 exp_vec[4].x = 0.590909f; exp_vec[4].y = 8.0f/11.0f;
2192 exp_vec[5].x = 0.55f; exp_vec[5].y = 0.7f;
2193 D3DXVec2TransformCoordArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2194 compare_vectors(exp_vec, out_vec);
2196 /* D3DXVec2TransformNormalArray */
2197 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
2198 exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
2199 exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
2200 exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
2201 exp_vec[5].x = 9.0f; exp_vec[5].y = 14.0f;
2202 D3DXVec2TransformNormalArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2203 compare_vectors(exp_vec, out_vec);
2205 /* D3DXVec3TransformCoordArray */
2206 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f; exp_vec[1].z = 0.892857f;
2207 exp_vec[2].x = 0.671875f; exp_vec[2].y = 0.78125f; exp_vec[2].z = 0.890625f;
2208 exp_vec[3].x = 6.0f/9.0f; exp_vec[3].y = 7.0f/9.0f; exp_vec[3].z = 8.0f/9.0f;
2209 exp_vec[4].x = 0.6625f; exp_vec[4].y = 0.775f; exp_vec[4].z = 0.8875f;
2210 exp_vec[5].x = 0.659091f; exp_vec[5].y = 0.772727f; exp_vec[5].z = 0.886364f;
2211 D3DXVec3TransformCoordArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2212 compare_vectors(exp_vec, out_vec);
2214 /* D3DXVec3TransformNormalArray */
2215 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
2216 exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
2217 exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
2218 exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
2219 exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
2220 D3DXVec3TransformNormalArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2221 compare_vectors(exp_vec, out_vec);
2223 /* D3DXVec3ProjectArray */
2224 exp_vec[1].x = 1089.554199f; exp_vec[1].y = -226.590622f; exp_vec[1].z = 0.215273f;
2225 exp_vec[2].x = 1068.903320f; exp_vec[2].y = 103.085129f; exp_vec[2].z = 0.183050f;
2226 exp_vec[3].x = 1051.778931f; exp_vec[3].y = 376.462250f; exp_vec[3].z = 0.156329f;
2227 exp_vec[4].x = 1037.348877f; exp_vec[4].y = 606.827393f; exp_vec[4].z = 0.133813f;
2228 exp_vec[5].x = 1025.023560f; exp_vec[5].y = 803.591248f; exp_vec[5].z = 0.114581f;
2229 D3DXVec3ProjectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2230 compare_vectors(exp_vec, out_vec);
2232 /* D3DXVec3UnprojectArray */
2233 exp_vec[1].x = -6.124031f; exp_vec[1].y = 3.225360f; exp_vec[1].z = 0.620571f;
2234 exp_vec[2].x = -3.807109f; exp_vec[2].y = 2.046579f; exp_vec[2].z = 0.446894f;
2235 exp_vec[3].x = -2.922839f; exp_vec[3].y = 1.596689f; exp_vec[3].z = 0.380609f;
2236 exp_vec[4].x = -2.456225f; exp_vec[4].y = 1.359290f; exp_vec[4].z = 0.345632f;
2237 exp_vec[5].x = -2.167897f; exp_vec[5].y = 1.212597f; exp_vec[5].z = 0.324019f;
2238 D3DXVec3UnprojectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
2239 compare_vectors(exp_vec, out_vec);
2241 /* D3DXVec2TransformArray */
2242 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2243 exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
2244 exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
2245 exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
2246 exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
2247 D3DXVec2TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2248 compare_vectors(exp_vec, out_vec);
2250 /* D3DXVec3TransformArray */
2251 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
2252 exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
2253 exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
2254 exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
2255 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2256 D3DXVec3TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2257 compare_vectors(exp_vec, out_vec);
2259 /* D3DXVec4TransformArray */
2260 exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
2261 exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f; exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
2262 exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f; exp_vec[3].z = 94.0f; exp_vec[3].w = 104.0f;
2263 exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f; exp_vec[4].z = 86.0f; exp_vec[4].w = 96.0f;
2264 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
2265 D3DXVec4TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
2266 compare_vectors(exp_vec, out_vec);
2268 /* D3DXPlaneTransformArray */
2269 exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
2270 exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f; exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
2271 exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f; exp_plane[3].c = 94.0f; exp_plane[3].d = 104.0f;
2272 exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f; exp_plane[4].c = 86.0f; exp_plane[4].d = 96.0f;
2273 exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f; exp_plane[5].c = 78.0f; exp_plane[5].d = 88.0f;
2274 D3DXPlaneTransformArray(out_plane + 1, sizeof(D3DXPLANE), inp_plane, sizeof(D3DXPLANE), &mat, ARRAY_SIZE);
2275 compare_planes(exp_plane, out_plane);
2278 static void test_D3DXFloat_Array(void)
2280 static const float z = 0.0f;
2281 /* Compilers set different sign bits on 0.0 / 0.0, pick the right ones for NaN and -NaN */
2282 float tmpnan = 0.0f/z;
2283 float nnan = copysignf(1, tmpnan) < 0.0f ? tmpnan : -tmpnan;
2284 float nan = -nnan;
2285 unsigned int i;
2286 void *out = NULL;
2287 D3DXFLOAT16 half;
2288 FLOAT single;
2289 struct
2291 FLOAT single_in;
2293 /* half_ver2 occurs on WXPPROSP3 (32 bit math), WVISTAADM (32 bit math), W7PRO (32 bit math) */
2294 WORD half_ver1, half_ver2;
2296 /* single_out_ver2 confirms that half -> single conversion is consistent across platforms */
2297 FLOAT single_out_ver1, single_out_ver2;
2298 } testdata[] = {
2299 { 80000.0f, 0x7c00, 0x7ce2, 65536.0f, 80000.0f },
2300 { 65503.0f, 0x7bff, 0x7bff, 65504.0f, 65504.0f },
2301 { 65504.0f, 0x7bff, 0x7bff, 65504.0f, 65504.0f },
2302 { 65520.0f, 0x7bff, 0x7c00, 65504.0f, 65536.0f },
2303 { 65521.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2304 { 65534.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2305 { 65535.0f, 0x7c00, 0x7c00, 65535.0f, 65536.0f },
2306 { 65536.0f, 0x7c00, 0x7c00, 65536.0f, 65536.0f },
2307 { -80000.0f, 0xfc00, 0xfce2, -65536.0f, -80000.0f },
2308 { -65503.0f, 0xfbff, 0xfbff, -65504.0f, -65504.0f },
2309 { -65504.0f, 0xfbff, 0xfbff, -65504.0f, -65504.0f },
2310 { -65520.0f, 0xfbff, 0xfc00, -65504.0f, -65536.0f },
2311 { -65521.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2312 { -65534.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2313 { -65535.0f, 0xfc00, 0xfc00, -65535.0f, -65536.0f },
2314 { -65536.0f, 0xfc00, 0xfc00, -65536.0f, -65536.0f },
2315 { 1.0f/z, 0x7c00, 0x7fff, 65536.0f, 131008.0f },
2316 { -1.0f/z, 0xffff, 0xffff, -131008.0f, -131008.0f },
2317 { nan, 0x7fff, 0x7fff, 131008.0f, 131008.0f },
2318 { nnan, 0xffff, 0xffff, -131008.0f, -131008.0f },
2319 { 0.0f, 0x0, 0x0, 0.0f, 0.0f },
2320 { -0.0f, 0x8000, 0x8000, 0.0f, 0.0f },
2321 { 2.9809595e-08f, 0x0, 0x0, 0.0f, 0.0f },
2322 { -2.9809595e-08f, 0x8000, 0x8000, -0.0f, -0.0f },
2323 { 2.9809598e-08f, 0x1, 0x1, 5.96046e-08f, 5.96046e-08f },
2324 { -2.9809598e-08f, 0x8001, 0x8001, -5.96046e-08f, -5.96046e-08f },
2325 { 8.9406967e-08f, 0x2, 0x2, 1.19209e-07f, 1.19209e-07f }
2328 /* exception on NULL out or in parameter */
2329 out = D3DXFloat32To16Array(&half, &single, 0);
2330 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2332 out = D3DXFloat16To32Array(&single, &half, 0);
2333 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2335 for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++)
2337 out = D3DXFloat32To16Array(&half, &testdata[i].single_in, 1);
2338 ok(out == &half, "Got %p, expected %p.\n", out, &half);
2339 ok(half.value == testdata[i].half_ver1 || half.value == testdata[i].half_ver2,
2340 "Got %x, expected %x or %x for index %d.\n", half.value, testdata[i].half_ver1,
2341 testdata[i].half_ver2, i);
2343 out = D3DXFloat16To32Array(&single, (D3DXFLOAT16 *)&testdata[i].half_ver1, 1);
2344 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2345 ok(relative_error(single, testdata[i].single_out_ver1) < admitted_error,
2346 "Got %g, expected %g for index %d.\n", single, testdata[i].single_out_ver1, i);
2348 out = D3DXFloat16To32Array(&single, (D3DXFLOAT16 *)&testdata[i].half_ver2, 1);
2349 ok(out == &single, "Got %p, expected %p.\n", out, &single);
2350 ok(relative_error(single, testdata[i].single_out_ver2) < admitted_error,
2351 "Got %g, expected %g for index %d.\n", single, testdata[i].single_out_ver2, i);
2355 static void test_D3DXSHAdd(void)
2357 UINT i, k;
2358 FLOAT *ret = (FLOAT *)0xdeadbeef;
2359 const FLOAT in1[50] =
2361 1.11f, 1.12f, 1.13f, 1.14f, 1.15f, 1.16f, 1.17f, 1.18f,
2362 1.19f, 1.20f, 1.21f, 1.22f, 1.23f, 1.24f, 1.25f, 1.26f,
2363 1.27f, 1.28f, 1.29f, 1.30f, 1.31f, 1.32f, 1.33f, 1.34f,
2364 1.35f, 1.36f, 1.37f, 1.38f, 1.39f, 1.40f, 1.41f, 1.42f,
2365 1.43f, 1.44f, 1.45f, 1.46f, 1.47f, 1.48f, 1.49f, 1.50f,
2366 1.51f, 1.52f, 1.53f, 1.54f, 1.55f, 1.56f, 1.57f, 1.58f,
2367 1.59f, 1.60f,
2369 const FLOAT in2[50] =
2371 2.11f, 2.12f, 2.13f, 2.14f, 2.15f, 2.16f, 2.17f, 2.18f,
2372 2.19f, 2.20f, 2.21f, 2.22f, 2.23f, 2.24f, 2.25f, 2.26f,
2373 2.27f, 2.28f, 2.29f, 2.30f, 2.31f, 2.32f, 2.33f, 2.34f,
2374 2.35f, 2.36f, 2.37f, 2.38f, 2.39f, 2.40f, 2.41f, 2.42f,
2375 2.43f, 2.44f, 2.45f, 2.46f, 2.47f, 2.48f, 2.49f, 2.50f,
2376 2.51f, 2.52f, 2.53f, 2.54f, 2.55f, 2.56f, 2.57f, 2.58f,
2377 2.59f, 2.60f,
2379 FLOAT out[50] = {0.0f};
2382 * Order is not limited by D3DXSH_MINORDER and D3DXSH_MAXORDER!
2383 * All values will work, test from 0-7 [D3DXSH_MINORDER = 2, D3DXSH_MAXORDER = 6]
2384 * Exceptions will show up when out, in1 or in2 are NULL
2386 for (k = 0; k < 8; ++k)
2388 UINT count = k * k;
2390 ret = D3DXSHAdd(&out[0], k, &in1[0], &in2[0]);
2391 ok(ret == out, "%u: D3DXSHAdd() failed, got %p, expected %p\n", k, out, ret);
2393 for (i = 0; i < count; ++i)
2395 ok(relative_error(in1[i] + in2[i], out[i]) < admitted_error,
2396 "%u-%u: D3DXSHAdd() failed, got %f, expected %f\n", k, i, out[i], in1[i] + in2[i]);
2398 ok(out[count] == 0.0f, "%u-%u: D3DXSHAdd() failed, got %f, expected 0.0\n", k, k * k, out[count]);
2402 static void test_D3DXSHDot(void)
2404 unsigned int i;
2405 FLOAT a[64], b[64], got;
2406 CONST FLOAT expected[] =
2407 { 0.5f, 0.5f, 25.0f, 262.5f, 1428.0f, 5362.0f, 15873.0f, 39812.0f, 88400.0f, };
2409 for (i = 0; i < 64; i++)
2411 a[i] = (FLOAT)i + 1.0f;
2412 b[i] = (FLOAT)i + 0.5f;
2415 /* D3DXSHDot computes by using order * order elements */
2416 for (i = 0; i < 9; i++)
2418 got = D3DXSHDot(i, a, b);
2419 ok(relative_error(got, expected[i]) < admitted_error, "order %d: expected %f, received %f\n", i, expected[i], got);
2422 return;
2425 static void test_D3DXSHEvalDirection(void)
2427 unsigned int i, order;
2428 D3DXVECTOR3 d;
2429 FLOAT a[100], expected[100], *received_ptr;
2430 CONST FLOAT table[36] =
2431 { 0.282095f, -0.977205f, 1.465808f, -0.488603f, 2.185097f, -6.555291f,
2432 8.200181f, -3.277646f, -1.638823f, 1.180087f, 17.343668f, -40.220032f,
2433 47.020218f, -20.110016f, -13.007751f, 6.490479f, -15.020058f, 10.620785f,
2434 117.325661f, -240.856750f, 271.657288f, -120.428375f, -87.994247f, 58.414314f,
2435 -4.380850f, 24.942520f, -149.447693f, 78.278130f, 747.791748f, -1427.687866f,
2436 1574.619141, -713.843933f, -560.843811f, 430.529724, -43.588909, -26.911665, };
2438 d.x = 1.0; d.y = 2.0f; d.z = 3.0f;
2440 for(order = 0; order < 10; order++)
2442 for(i = 0; i < 100; i++)
2443 a[i] = 1.5f + i;
2445 received_ptr = D3DXSHEvalDirection(a, order, &d);
2446 ok(received_ptr == a, "Expected %p, received %p\n", a, received_ptr);
2448 for(i = 0; i < 100; i++)
2450 /* if the order is < D3DXSH_MINORDER or order > D3DXSH_MAXORDER or the index of the element is greater than order * order - 1, D3DXSHEvalDirection does not modify the output */
2451 if ( (order < D3DXSH_MINORDER) || (order > D3DXSH_MAXORDER) || (i >= order * order) )
2452 expected[i] = 1.5f + i;
2453 else
2454 expected[i] = table[i];
2456 ok(relative_error(a[i], expected[i]) < admitted_error, "order %u, index %u: expected %f, received %f\n", order, i, expected[i], a[i]);
2461 static void test_D3DXSHMultiply2(void)
2463 unsigned int i;
2464 FLOAT a[20], b[20], c[20];
2465 /* D3DXSHMultiply2 only modifies the first 4 elements of the array */
2466 const FLOAT expected[20] =
2467 { 3.418594f, 1.698211f, 1.703853f, 1.709494f, 4.0f, 5.0f,
2468 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
2469 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
2471 for (i = 0; i < 20; i++)
2473 a[i] = 1.0f + i / 100.0f;
2474 b[i] = 3.0f - i / 100.0f;
2475 c[i] = i;
2478 D3DXSHMultiply2(c, a, b);
2479 for (i = 0; i < 20; i++)
2480 ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]);
2483 static void test_D3DXSHMultiply3(void)
2485 unsigned int i;
2486 FLOAT a[20], b[20], c[20];
2487 /* D3DXSHMultiply only modifies the first 9 elements of the array */
2488 const FLOAT expected[20] =
2489 { 7.813913f, 2.256058f, 5.9484005f, 4.970894f, 2.899858f, 3.598946f,
2490 1.726572f, 5.573538f, 0.622063f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
2491 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
2493 for (i = 0; i < 20; i++)
2495 a[i] = 1.0f + (FLOAT)i/100.0f;
2496 b[i] = 3.0f - (FLOAT)i/100.0f;
2497 c[i] = (FLOAT)i;
2500 D3DXSHMultiply3(c, a, b);
2501 for (i = 0; i < 20; i++)
2502 ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]);
2505 static void test_D3DXSHRotateZ(void)
2507 unsigned int i, j, order, square;
2508 FLOAT angle[] = { D3DX_PI / 3.0f, -D3DX_PI / 3.0f, 4.0f * D3DX_PI / 3.0f, }, expected, in[100], out[100], *received_ptr, table[] =
2509 { /* Angle = D3DX_PI / 3.0f */
2510 1.01f, 4.477762f, 3.010000f, 0.264289f, 5.297888f, 9.941864f, 7.010000f, -1.199813f,
2511 -8.843789f, -10.010002f, 7.494040f, 18.138016f, 13.010000, -3.395966f, -17.039942f,
2512 -16.009998f, -30.164297f, -18.010004f, 10.422242f, 29.066219f, 21.010000f, -6.324171f,
2513 -27.968145f, -24.009998f, 2.226099f, -18.180565, -43.824551f, -28.010004f, 14.082493f,
2514 42.726471f, 31.010000f, -9.984426f, -41.628399f, -34.009995f, 5.886358f, 40.530331f,
2515 /* Angle = D3DX_PI / 3.0f */
2516 1.01f, -2.467762f, 3.010000f, 3.745711f, -10.307890f, -3.931864f, 7.010000f, 9.209813f,
2517 -0.166214f, -10.010002f, -18.504044f, -6.128017f, 13.010000f, 17.405966f, 2.029938f,
2518 -16.009998f, 13.154303f, -18.010004f, -29.432247f, -9.056221f, 21.010000f, 28.334169f,
2519 4.958139f, -24.010002f, -27.236092f, 44.190582f, 16.814558f, -28.009996f, -43.092499f,
2520 -12.716474f, 31.010000f, 41.994423f, 8.618393f, -34.010002f, -40.896347f, -4.520310f,
2521 /* Angle = 4.0f * D3DX_PI / 3.0f */
2522 1.01f, -4.477762f, 3.010000f, -0.264289f, 5.297887f, -9.941864f, 7.010000f, 1.199814f,
2523 -8.843788f, 10.010004f, 7.494038f, -18.138016f, 13.010000f, 3.395967f, -17.039940f,
2524 16.009996f, -30.164293f, 18.010006f, 10.422239f, -29.066219f, 21.010000f, 6.324172f,
2525 -27.968143f, 24.009993f, 2.226105f, 18.180552f, -43.824543f, 28.010008f, 14.082489f,
2526 -42.726471f, 31.010000f, 9.984427f, -41.628399f, 34.009987f, 5.886366f, -40.530327, };
2528 for (i = 0; i < 100; i++)
2529 in[i] = i + 1.01f;
2531 for (j = 0; j < 3; j++)
2533 for (order = 0; order < 10; order++)
2535 for (i = 0; i < 100; i++)
2536 out[i] = ( i + 1.0f ) * ( i + 1.0f );
2538 received_ptr = D3DXSHRotateZ(out, order, angle[j], in);
2539 ok(received_ptr == out, "angle %f, order %u, Expected %p, received %p\n", angle[j], order, out, received_ptr);
2541 for (i = 0; i < 100; i++)
2543 /* order = 0 or order = 1 behaves like order = D3DXSH_MINORDER */
2544 square = ( order <= D3DXSH_MINORDER ) ? D3DXSH_MINORDER * D3DXSH_MINORDER : order * order;
2545 expected = table[36 * j + i];
2546 if ( i >= square || ( (order >= D3DXSH_MAXORDER) && ( i >= D3DXSH_MAXORDER * D3DXSH_MAXORDER ) ) )
2547 expected = ( i + 1.0f ) * ( i + 1.0f );
2549 ok(relative_error(out[i], expected) < admitted_error, "angle %f, order %u index %u, Expected %f, received %f\n", angle[j], order, i, expected, out[i]);
2555 static void test_D3DXSHScale(void)
2557 unsigned int i, order;
2558 FLOAT a[100], b[100], expected, *received_array;
2560 for (i = 0; i < 100; i++)
2562 a[i] = i;
2563 b[i] = i;
2566 for (order = 0; order < 10; order++)
2568 received_array = D3DXSHScale(b, order, a, 5.0f);
2569 ok(received_array == b, "Expected %p, received %p\n", b, received_array);
2571 for (i = 0; i < 100; i++)
2573 if (i < order * order)
2574 expected = 5.0f * a[i];
2575 /* D3DXSHScale does not modify the elements of the array after the order * order-th element */
2576 else
2577 expected = a[i];
2578 ok(relative_error(b[i], expected) < admitted_error, "order %d, element %d, expected %f, received %f\n", order, i, expected, b[i]);
2583 START_TEST(math)
2585 D3DXColorTest();
2586 D3DXFresnelTest();
2587 D3DXMatrixTest();
2588 D3DXPlaneTest();
2589 D3DXQuaternionTest();
2590 D3DXVector2Test();
2591 D3DXVector3Test();
2592 D3DXVector4Test();
2593 test_matrix_stack();
2594 test_Matrix_AffineTransformation2D();
2595 test_Matrix_Decompose();
2596 test_Matrix_Transformation2D();
2597 test_D3DXVec_Array();
2598 test_D3DXFloat_Array();
2599 test_D3DXSHAdd();
2600 test_D3DXSHDot();
2601 test_D3DXSHEvalDirection();
2602 test_D3DXSHMultiply2();
2603 test_D3DXSHMultiply3();
2604 test_D3DXSHRotateZ();
2605 test_D3DXSHScale();