mapi32/tests: Fix typo.
[wine] / dlls / d3dx8 / tests / math.c
1 /*
2  * Copyright 2007 David Adam
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <assert.h>
20 #include "d3dx8.h"
21
22 #include "wine/test.h"
23
24 #define admitted_error 0.0001f
25
26 #define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotcolor.r)<admitted_error)&&(fabs(expectedcolor.g-gotcolor.g)<admitted_error)&&(fabs(expectedcolor.b-gotcolor.b)<admitted_error)&&(fabs(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);
27
28 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
29 {
30     int i, j;
31
32     for (i = 0; i < 4; ++i)
33     {
34         for (j = 0; j < 4; ++j)
35         {
36             if (fabs(U(*m1).m[i][j] - U(*m2).m[i][j]) > admitted_error)
37                 return FALSE;
38         }
39     }
40
41     return TRUE;
42 }
43
44 #define expect_mat(expectedmat, gotmat) \
45 do { \
46     const D3DXMATRIX *__m1 = (expectedmat); \
47     const D3DXMATRIX *__m2 = (gotmat); \
48     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" \
49             "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
50             U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
51             U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
52             U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
53             U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
54             U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
55             U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
56             U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
57             U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
58 } while(0)
59
60 #define expect_plane(expectedplane,gotplane) ok((fabs(expectedplane.a-gotplane.a)<admitted_error)&&(fabs(expectedplane.b-gotplane.b)<admitted_error)&&(fabs(expectedplane.c-gotplane.c)<admitted_error)&&(fabs(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);
61
62 #define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
63
64 #define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(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);
65
66 #define expect_vec4(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expectedvec.z-gotvec.z)<admitted_error)&&(fabs(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);
67
68 static void D3DXColorTest(void)
69 {
70     D3DXCOLOR color, color1, color2, expected, got;
71     LPD3DXCOLOR funcpointer;
72     FLOAT scale;
73
74     color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
75     color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
76     color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
77
78     scale = 0.3f;
79
80 /*_______________D3DXColorAdd________________*/
81     expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
82     D3DXColorAdd(&got,&color1,&color2);
83     expect_color(expected,got);
84     /* Test the NULL case */
85     funcpointer = D3DXColorAdd(&got,NULL,&color2);
86     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
87     funcpointer = D3DXColorAdd(NULL,NULL,&color2);
88     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
89     funcpointer = D3DXColorAdd(NULL,NULL,NULL);
90     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
91
92 /*_______________D3DXColorAdjustContrast______*/
93     expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
94     D3DXColorAdjustContrast(&got,&color,scale);
95     expect_color(expected,got);
96
97 /*_______________D3DXColorAdjustSaturation______*/
98     expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
99     D3DXColorAdjustSaturation(&got,&color,scale);
100     expect_color(expected,got);
101
102 /*_______________D3DXColorLerp________________*/
103     expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
104     D3DXColorLerp(&got,&color,&color1,scale);
105     expect_color(expected,got);
106     /* Test the NULL case */
107     funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
108     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
109     funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
110     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
111     funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
112     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
113
114 /*_______________D3DXColorModulate________________*/
115     expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
116     D3DXColorModulate(&got,&color1,&color2);
117     expect_color(expected,got);
118     /* Test the NULL case */
119     funcpointer = D3DXColorModulate(&got,NULL,&color2);
120     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
121     funcpointer = D3DXColorModulate(NULL,NULL,&color2);
122     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
123     funcpointer = D3DXColorModulate(NULL,NULL,NULL);
124     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
125
126 /*_______________D3DXColorNegative________________*/
127     expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
128     D3DXColorNegative(&got,&color);
129     expect_color(got,expected);
130     /* Test the greater than 1 case */
131     color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
132     expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
133     D3DXColorNegative(&got,&color1);
134     expect_color(got,expected);
135     /* Test the negative case */
136     color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
137     expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
138     D3DXColorNegative(&got,&color1);
139     expect_color(got,expected);
140     /* Test the NULL case */
141     funcpointer = D3DXColorNegative(&got,NULL);
142     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
143     funcpointer = D3DXColorNegative(NULL,NULL);
144     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
145
146 /*_______________D3DXColorScale________________*/
147     expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
148     D3DXColorScale(&got,&color,scale);
149     expect_color(expected,got);
150     /* Test the NULL case */
151     funcpointer = D3DXColorScale(&got,NULL,scale);
152     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
153     funcpointer = D3DXColorScale(NULL,NULL,scale);
154     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
155
156 /*_______________D3DXColorSubtract_______________*/
157     expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
158     D3DXColorSubtract(&got,&color,&color2);
159     expect_color(expected,got);
160     /* Test the NULL case */
161     funcpointer = D3DXColorSubtract(&got,NULL,&color2);
162     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
163     funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
164     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
165     funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
166     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
167 }
168
169 static void D3DXFresnelTest(void)
170 {
171     FLOAT expected, got;
172
173     expected = 0.089187;
174     got = D3DXFresnelTerm(0.5f,1.5);
175     ok( fabs(got - expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
176 }
177
178 static void D3DXMatrixTest(void)
179 {
180     D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
181     LPD3DXMATRIX funcpointer;
182     D3DXPLANE plane;
183     D3DXQUATERNION q, r;
184     D3DXVECTOR3 at, axis, eye, last, scaling;
185     D3DXVECTOR4 light;
186     BOOL expected, got;
187     FLOAT angle, determinant, expectedfloat, gotfloat;
188
189     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
190     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
191     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
192     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
193     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
194     U(mat).m[3][3] = -40.0f;
195
196     U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
197     U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
198     U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
199     U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
200     U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
201     U(mat2).m[3][3] = -1.0f;
202
203     plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
204
205     q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
206     r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
207
208     at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
209     axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
210     eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
211     last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
212     scaling.x = 0.03f; scaling.y =0.05f; scaling.z = 0.06f;
213
214     light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
215
216     angle = D3DX_PI/3.0f;
217
218 /*____________D3DXMatrixAffineTransformation______*/
219     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;
220     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;
221     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;
222     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;
223     D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
224     expect_mat(&expectedmat, &gotmat);
225 /* Test the NULL case */
226     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;
227     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;
228     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;
229     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;
230     D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
231     expect_mat(&expectedmat, &gotmat);
232
233 /*____________D3DXMatrixfDeterminant_____________*/
234     expectedfloat = -147888.0f;
235     gotfloat = D3DXMatrixfDeterminant(&mat);
236     ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
237
238 /*____________D3DXMatrixInverse______________*/
239     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;
240     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;
241     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;
242     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;
243     expectedfloat = -147888.0f;
244     D3DXMatrixInverse(&gotmat,&determinant,&mat);
245     expect_mat(&expectedmat, &gotmat);
246     ok(fabs( determinant - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
247     funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
248     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
249
250 /*____________D3DXMatrixIsIdentity______________*/
251     expected = FALSE;
252     memset(&mat3, 0, sizeof(mat3));
253     got = D3DXMatrixIsIdentity(&mat3);
254     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
255     D3DXMatrixIdentity(&mat3);
256     expected = TRUE;
257     got = D3DXMatrixIsIdentity(&mat3);
258     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
259     U(mat3).m[0][0] = 0.000009f;
260     expected = FALSE;
261     got = D3DXMatrixIsIdentity(&mat3);
262     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
263     /* Test the NULL case */
264     expected = FALSE;
265     got = D3DXMatrixIsIdentity(NULL);
266     ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
267
268 /*____________D3DXMatrixLookatLH_______________*/
269     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;
270     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;
271     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;
272     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;
273     D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
274     expect_mat(&expectedmat, &gotmat);
275
276 /*____________D3DXMatrixLookatRH_______________*/
277     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;
278     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;
279     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;
280     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;
281     D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
282     expect_mat(&expectedmat, &gotmat);
283
284 /*____________D3DXMatrixMultiply______________*/
285     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;
286     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;
287     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;
288     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;
289     D3DXMatrixMultiply(&gotmat,&mat,&mat2);
290     expect_mat(&expectedmat, &gotmat);
291
292 /*____________D3DXMatrixMultiplyTranspose____*/
293     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;
294     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;
295     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;
296     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;
297     D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
298     expect_mat(&expectedmat, &gotmat);
299
300 /*____________D3DXMatrixOrthoLH_______________*/
301     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;
302     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;
303     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;
304     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;
305     D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
306     expect_mat(&expectedmat, &gotmat);
307
308 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
309     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;
310     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;
311     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;
312     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;
313     D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
314     expect_mat(&expectedmat, &gotmat);
315
316 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
317     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;
318     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;
319     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;
320     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;
321     D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
322     expect_mat(&expectedmat, &gotmat);
323
324 /*____________D3DXMatrixOrthoRH_______________*/
325     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;
326     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;
327     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;
328     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;
329     D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
330     expect_mat(&expectedmat, &gotmat);
331
332 /*____________D3DXMatrixPerspectiveFovLH_______________*/
333     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;
334     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;
335     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;
336     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;
337     D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
338     expect_mat(&expectedmat, &gotmat);
339
340 /*____________D3DXMatrixPerspectiveFovRH_______________*/
341     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;
342     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;
343     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;
344     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;
345     D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
346     expect_mat(&expectedmat, &gotmat);
347
348 /*____________D3DXMatrixPerspectiveLH_______________*/
349     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;
350     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;
351     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;
352     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;
353     D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
354     expect_mat(&expectedmat, &gotmat);
355
356 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
357     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;
358     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;
359     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;
360     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;
361     D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
362     expect_mat(&expectedmat, &gotmat);
363
364 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
365     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;
366     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;
367     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;
368     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;
369     D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
370     expect_mat(&expectedmat, &gotmat);
371
372 /*____________D3DXMatrixPerspectiveRH_______________*/
373     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;
374     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;
375     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;
376     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;
377     D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
378     expect_mat(&expectedmat, &gotmat);
379
380 /*____________D3DXMatrixReflect______________*/
381     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;
382     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;
383     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;
384     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;
385     D3DXMatrixReflect(&gotmat,&plane);
386     expect_mat(&expectedmat, &gotmat);
387
388 /*____________D3DXMatrixRotationAxis_____*/
389     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;
390     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;
391     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;
392     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;
393     D3DXMatrixRotationAxis(&gotmat,&axis,angle);
394     expect_mat(&expectedmat, &gotmat);
395
396 /*____________D3DXMatrixRotationQuaternion______________*/
397     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;
398     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;
399     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;
400     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;
401     D3DXMatrixRotationQuaternion(&gotmat,&q);
402     expect_mat(&expectedmat, &gotmat);
403
404 /*____________D3DXMatrixRotationX______________*/
405     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;
406     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;
407     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;
408     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;
409     D3DXMatrixRotationX(&gotmat,angle);
410     expect_mat(&expectedmat, &gotmat);
411
412 /*____________D3DXMatrixRotationY______________*/
413     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;
414     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;
415     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;
416     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;
417     D3DXMatrixRotationY(&gotmat,angle);
418     expect_mat(&expectedmat, &gotmat);
419
420 /*____________D3DXMatrixRotationYawPitchRoll____*/
421     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;
422     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;
423     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;
424     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;
425     D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
426     expect_mat(&expectedmat, &gotmat);
427
428 /*____________D3DXMatrixRotationZ______________*/
429     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;
430     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;
431     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;
432     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;
433     D3DXMatrixRotationZ(&gotmat,angle);
434     expect_mat(&expectedmat, &gotmat);
435
436 /*____________D3DXMatrixScaling______________*/
437     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;
438     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;
439     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;
440     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;
441     D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
442     expect_mat(&expectedmat, &gotmat);
443
444 /*____________D3DXMatrixShadow______________*/
445     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;
446     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;
447     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;
448     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;
449     D3DXMatrixShadow(&gotmat,&light,&plane);
450     expect_mat(&expectedmat, &gotmat);
451
452 /*____________D3DXMatrixTransformation______________*/
453     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;
454     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;
455     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;
456     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;
457     D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
458     expect_mat(&expectedmat, &gotmat);
459
460 /*____________D3DXMatrixTranslation______________*/
461     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;
462     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;
463     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;
464     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;
465     D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
466     expect_mat(&expectedmat, &gotmat);
467
468 /*____________D3DXMatrixTranspose______________*/
469     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;
470     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;
471     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;
472     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;
473     D3DXMatrixTranspose(&gotmat,&mat);
474     expect_mat(&expectedmat, &gotmat);
475 }
476
477 static void D3DXPlaneTest(void)
478 {
479     D3DXMATRIX mat;
480     D3DXPLANE expectedplane, gotplane, nulplane, plane;
481     D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
482     LPD3DXVECTOR3 funcpointer;
483     D3DXVECTOR4 vec;
484     FLOAT expected, got;
485
486     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
487     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
488     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
489     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
490     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
491     U(mat).m[3][3] = -40.0f;
492
493     plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
494
495     vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
496
497 /*_______________D3DXPlaneDot________________*/
498     expected = 42.0f;
499     got = D3DXPlaneDot(&plane,&vec),
500     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
501     expected = 0.0f;
502     got = D3DXPlaneDot(NULL,&vec),
503     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
504     expected = 0.0f;
505     got = D3DXPlaneDot(NULL,NULL),
506     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
507
508 /*_______________D3DXPlaneDotCoord________________*/
509     expected = -28.0f;
510     got = D3DXPlaneDotCoord(&plane,&vec),
511     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
512     expected = 0.0f;
513     got = D3DXPlaneDotCoord(NULL,&vec),
514     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
515     expected = 0.0f;
516     got = D3DXPlaneDotCoord(NULL,NULL),
517     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
518
519 /*_______________D3DXPlaneDotNormal______________*/
520     expected = -35.0f;
521     got = D3DXPlaneDotNormal(&plane,&vec),
522     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
523     expected = 0.0f;
524     got = D3DXPlaneDotNormal(NULL,&vec),
525     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
526     expected = 0.0f;
527     got = D3DXPlaneDotNormal(NULL,NULL),
528     ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
529
530 /*_______________D3DXPlaneFromPointNormal_______*/
531     vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
532     vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
533     expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
534     D3DXPlaneFromPointNormal(&gotplane,&vec1,&vec2);
535     expect_plane(expectedplane, gotplane);
536
537 /*_______________D3DXPlaneFromPoints_______*/
538     vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
539     vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
540     vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
541     expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
542     D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
543     expect_plane(expectedplane, gotplane);
544     /* Test if 2 vectors are parallels */
545     vec3.x = 1.0f; vec3.y = 1.0f; vec3.z = 2.0f;
546     expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
547     D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
548     expect_plane(expectedplane, gotplane);
549
550 /*_______________D3DXPlaneIntersectLine___________*/
551     vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
552     vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
553     expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
554     D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
555     expect_vec3(expectedvec, gotvec);
556     /* Test a parallel line */
557     vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
558     vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
559     expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
560     funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
561     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
562
563 /*_______________D3DXPlaneNormalize______________*/
564     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);
565     D3DXPlaneNormalize(&gotplane, &plane);
566     expect_plane(expectedplane, gotplane);
567     nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
568     expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
569     D3DXPlaneNormalize(&gotplane, &nulplane);
570     expect_plane(expectedplane, gotplane);
571     nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 4.3f;
572     expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
573     D3DXPlaneNormalize(&gotplane, &nulplane);
574     expect_plane(expectedplane, gotplane);
575
576 /*_______________D3DXPlaneTransform____________*/
577     expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
578     D3DXPlaneTransform(&gotplane,&plane,&mat);
579     expect_plane(expectedplane, gotplane);
580 }
581
582 static void D3X8QuaternionTest(void)
583 {
584     D3DXMATRIX mat;
585     D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, q, r, s, t, u;
586     LPD3DXQUATERNION funcpointer;
587     D3DXVECTOR3 axis, expectedvec;
588     FLOAT angle, expected, got, scale, scale2;
589     BOOL expectedbool, gotbool;
590
591     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
592     q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
593     r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
594     t.x = -1111.0f, t.y= 111.0f; t.z = -11.0f; t.w = 1.0f;
595     u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
596
597     scale = 0.3f;
598     scale2 = 0.78f;
599
600 /*_______________D3DXQuaternionBaryCentric________________________*/
601     expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
602     D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
603     expect_vec4(expectedquat,gotquat);
604
605 /*_______________D3DXQuaternionConjugate________________*/
606     expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
607     D3DXQuaternionConjugate(&gotquat,&q);
608     expect_vec4(expectedquat,gotquat);
609     /* Test the NULL case */
610     funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
611     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
612     funcpointer = D3DXQuaternionConjugate(NULL,NULL);
613     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
614
615 /*_______________D3DXQuaternionDot______________________*/
616     expected = 55.0f;
617     got = D3DXQuaternionDot(&q,&r);
618     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
619     /* Tests the case NULL */
620     expected=0.0f;
621     got = D3DXQuaternionDot(NULL,&r);
622     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
623     expected=0.0f;
624     got = D3DXQuaternionDot(NULL,NULL);
625     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
626
627 /*_______________D3DXQuaternionExp______________________________*/
628     expectedquat.x = -0.216382f; expectedquat.y = -0.432764f; expectedquat.z = -0.8655270f; expectedquat.w = -0.129449f;
629     D3DXQuaternionExp(&gotquat,&q);
630     expect_vec4(expectedquat,gotquat);
631     /* Test the null quaternion */
632     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
633     D3DXQuaternionExp(&gotquat,&nul);
634     expect_vec4(expectedquat,gotquat);
635     /* Test the case where the norm of the quaternion is <1 */
636     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
637     expectedquat.x = 0.195366; expectedquat.y = 0.097683f; expectedquat.z = 0.293049f; expectedquat.w = 0.930813f;
638     D3DXQuaternionExp(&gotquat,&Nq1);
639     expect_vec4(expectedquat,gotquat);
640
641 /*_______________D3DXQuaternionIdentity________________*/
642     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
643     D3DXQuaternionIdentity(&gotquat);
644     expect_vec4(expectedquat,gotquat);
645     /* Test the NULL case */
646     funcpointer = D3DXQuaternionIdentity(NULL);
647     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
648
649 /*_______________D3DXQuaternionInverse________________________*/
650     expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
651     D3DXQuaternionInverse(&gotquat,&q);
652     expect_vec4(expectedquat,gotquat);
653     /* test the null quaternion */
654     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
655     D3DXQuaternionInverse(&gotquat,&nul);
656     expect_vec4(expectedquat,gotquat);
657
658 /*_______________D3DXQuaternionIsIdentity________________*/
659     s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
660     expectedbool = TRUE;
661     gotbool = D3DXQuaternionIsIdentity(&s);
662     ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
663     s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
664     expectedbool = FALSE;
665     gotbool = D3DXQuaternionIsIdentity(&q);
666     ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
667     /* Test the NULL case */
668     gotbool = D3DXQuaternionIsIdentity(NULL);
669     ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
670
671 /*_______________D3DXQuaternionLength__________________________*/
672    expected = 11.0f;
673    got = D3DXQuaternionLength(&q);
674    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
675    /* Tests the case NULL */
676     expected=0.0f;
677     got = D3DXQuaternionLength(NULL);
678     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
679
680 /*_______________D3DXQuaternionLengthSq________________________*/
681     expected = 121.0f;
682     got = D3DXQuaternionLengthSq(&q);
683     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
684     /* Tests the case NULL */
685     expected=0.0f;
686     got = D3DXQuaternionLengthSq(NULL);
687     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
688
689 /*_______________D3DXQuaternionLn______________________________*/
690     expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
691     D3DXQuaternionLn(&gotquat,&q);
692     expect_vec4(expectedquat,gotquat);
693     expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
694     D3DXQuaternionLn(&gotquat,&r);
695     expect_vec4(expectedquat,gotquat);
696     Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
697     expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
698     D3DXQuaternionLn(&gotquat,&Nq);
699     expect_vec4(expectedquat,gotquat);
700     /* Test the cas where the norm of the quaternion is <1 */
701     Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
702     expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
703     D3DXQuaternionLn(&gotquat,&Nq1);
704     todo_wine{ expect_vec4(expectedquat,gotquat) };
705
706 /*_______________D3DXQuaternionMultiply________________________*/
707     expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
708     D3DXQuaternionMultiply(&gotquat,&q,&r);
709     expect_vec4(expectedquat,gotquat);
710
711 /*_______________D3DXQuaternionNormalize________________________*/
712     expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
713     D3DXQuaternionNormalize(&gotquat,&q);
714     expect_vec4(expectedquat,gotquat);
715     /* Test the nul quaternion */
716     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
717     D3DXQuaternionNormalize(&gotquat,&nul);
718     expect_vec4(expectedquat,gotquat);
719
720 /*_______________D3DXQuaternionRotationAxis___________________*/
721     axis.x = 2.0f; axis.y = 7.0; axis.z = 13.0f;
722     angle = D3DX_PI/3.0f;
723     expectedquat.x = 0.067116; expectedquat.y = 0.234905f; expectedquat.z = 0.436251f; expectedquat.w = 0.866025f;
724     D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
725     expect_vec4(expectedquat,gotquat);
726  /* Test the nul quaternion */
727     axis.x = 0.0f; axis.y = 0.0; axis.z = 0.0f;
728     expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.866025f;
729     D3DXQuaternionRotationAxis(&gotquat,&axis,angle);
730     expect_vec4(expectedquat,gotquat);
731
732 /*_______________D3DXQuaternionRotationMatrix___________________*/
733     /* test when the trace is >0 */
734     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
735     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
736     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
737     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
738     U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
739     U(mat).m[3][3] = 48.0f;
740     expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f;
741     D3DXQuaternionRotationMatrix(&gotquat,&mat);
742     expect_vec4(expectedquat,gotquat);
743     /* test the case when the greater element is (2,2) */
744     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
745     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
746     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
747     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
748     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f;
749     U(mat).m[3][3] = 48.0f;
750     expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f;
751     D3DXQuaternionRotationMatrix(&gotquat,&mat);
752     expect_vec4(expectedquat,gotquat);
753     /* test the case when the greater element is (1,1) */
754     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
755     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
756     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
757     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
758     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f;
759     U(mat).m[3][3] = 48.0f;
760     expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f;
761     D3DXQuaternionRotationMatrix(&gotquat,&mat);
762     expect_vec4(expectedquat,gotquat);
763     /* test the case when the trace is near 0 in a matrix which is not a rotation */
764     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
765     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
766     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
767     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
768     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f;
769     U(mat).m[3][3] = 48.0f;
770     expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f;
771     D3DXQuaternionRotationMatrix(&gotquat,&mat);
772     expect_vec4(expectedquat,gotquat);
773     /* test the case when the trace is 0.49 in a matrix which is not a rotation */
774     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
775     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
776     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
777     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
778     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f;
779     U(mat).m[3][3] = 48.0f;
780     expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f;
781     D3DXQuaternionRotationMatrix(&gotquat,&mat);
782     expect_vec4(expectedquat,gotquat);
783     /* test the case when the trace is 0.51 in a matrix which is not a rotation */
784     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
785     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
786     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
787     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
788     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f;
789     U(mat).m[3][3] = 48.0f;
790     expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f;
791     D3DXQuaternionRotationMatrix(&gotquat,&mat);
792     expect_vec4(expectedquat,gotquat);
793     /* test the case when the trace is 0.99 in a matrix which is not a rotation */
794     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
795     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
796     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
797     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
798     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f;
799     U(mat).m[3][3] = 48.0f;
800     expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f;
801     D3DXQuaternionRotationMatrix(&gotquat,&mat);
802     expect_vec4(expectedquat,gotquat);
803     /* test the case when the trace is 1.0 in a matrix which is not a rotation */
804     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
805     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
806     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
807     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
808     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f;
809     U(mat).m[3][3] = 48.0f;
810     expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f;
811     D3DXQuaternionRotationMatrix(&gotquat,&mat);
812     expect_vec4(expectedquat,gotquat);
813     /* test the case when the trace is 1.01 in a matrix which is not a rotation */
814     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
815     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
816     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
817     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
818     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f;
819     U(mat).m[3][3] = 48.0f;
820     expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f;
821     D3DXQuaternionRotationMatrix(&gotquat,&mat);
822     expect_vec4(expectedquat,gotquat);
823     /* test the case when the trace is 1.5 in a matrix which is not a rotation */
824     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
825     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
826     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
827     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
828     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f;
829     U(mat).m[3][3] = 48.0f;
830     expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f;
831     D3DXQuaternionRotationMatrix(&gotquat,&mat);
832     expect_vec4(expectedquat,gotquat);
833     /* test the case when the trace is 1.7 in a matrix which is not a rotation */
834     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
835     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
836     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
837     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
838     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f;
839     U(mat).m[3][3] = 48.0f;
840     expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f;
841     D3DXQuaternionRotationMatrix(&gotquat,&mat);
842     expect_vec4(expectedquat,gotquat);
843     /* test the case when the trace is 1.99 in a matrix which is not a rotation */
844     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
845     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
846     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
847     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
848     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f;
849     U(mat).m[3][3] = 48.0f;
850     expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f;
851     D3DXQuaternionRotationMatrix(&gotquat,&mat);
852     expect_vec4(expectedquat,gotquat);
853     /* test the case when the trace is 2.0 in a matrix which is not a rotation */
854     U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
855     U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
856     U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
857     U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
858     U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f;
859     U(mat).m[3][3] = 48.0f;
860     expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f;
861     D3DXQuaternionRotationMatrix(&gotquat,&mat);
862     expect_vec4(expectedquat,gotquat);
863
864 /*_______________D3DXQuaternionRotationYawPitchRoll__________*/
865     expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f;
866     D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
867     expect_vec4(expectedquat,gotquat);
868
869 /*_______________D3DXQuaternionSlerp________________________*/
870     expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
871     D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
872     expect_vec4(expectedquat,gotquat);
873     expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
874     D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
875     expect_vec4(expectedquat,gotquat);
876
877 /*_______________D3DXQuaternionSquad________________________*/
878     expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
879     D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
880     expect_vec4(expectedquat,gotquat);
881
882 /*_______________D3DXQuaternionToAxisAngle__________________*/
883     Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f;
884     expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f;
885     expected = 2.197869f;
886     D3DXQuaternionToAxisAngle(&Nq,&axis,&angle);
887     expect_vec3(expectedvec,axis);
888     ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
889     /* Test if |w|>1.0f */
890     expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f;
891     expected = 0.0f;
892     D3DXQuaternionToAxisAngle(&q,&axis,&angle);
893     expect_vec3(expectedvec,axis);
894     ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
895     /* Test the null quaternion */
896     expectedvec.x = 1.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
897     expected = 0.0f;
898     D3DXQuaternionToAxisAngle(&nul,&axis,&angle);
899     expect_vec3(expectedvec,axis);
900     ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
901 }
902
903 static void D3X8Vector2Test(void)
904 {
905     D3DXVECTOR2 expectedvec, gotvec, nul, nulproj, u, v, w, x;
906     LPD3DXVECTOR2 funcpointer;
907     D3DXVECTOR4 expectedtrans, gottrans;
908     D3DXMATRIX mat;
909     FLOAT coeff1, coeff2, expected, got, scale;
910
911     nul.x = 0.0f; nul.y = 0.0f;
912     u.x = 3.0f; u.y = 4.0f;
913     v.x = -7.0f; v.y = 9.0f;
914     w.x = 4.0f; w.y = -3.0f;
915     x.x = 2.0f; x.y = -11.0f;
916
917     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;
918     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;
919     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;
920     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;
921
922     coeff1 = 2.0f; coeff2 = 5.0f;
923     scale = -6.5f;
924
925 /*_______________D3DXVec2Add__________________________*/
926     expectedvec.x = -4.0f; expectedvec.y = 13.0f;
927     D3DXVec2Add(&gotvec,&u,&v);
928     expect_vec(expectedvec,gotvec);
929     /* Tests the case NULL */
930     funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
931     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
932     funcpointer = D3DXVec2Add(NULL,NULL,NULL);
933     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
934
935 /*_______________D3DXVec2BaryCentric___________________*/
936     expectedvec.x = -12.0f; expectedvec.y = -21.0f;
937     D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
938     expect_vec(expectedvec,gotvec);
939
940 /*_______________D3DXVec2CatmullRom____________________*/
941     expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
942     D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
943     expect_vec(expectedvec,gotvec);
944
945 /*_______________D3DXVec2CCW__________________________*/
946    expected = 55.0f;
947    got = D3DXVec2CCW(&u,&v);
948    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
949    /* Tests the case NULL */
950     expected=0.0f;
951     got = D3DXVec2CCW(NULL,&v);
952     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
953     expected=0.0f;
954     got = D3DXVec2CCW(NULL,NULL);
955     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
956
957 /*_______________D3DXVec2Dot__________________________*/
958     expected = 15.0f;
959     got = D3DXVec2Dot(&u,&v);
960     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
961     /* Tests the case NULL */
962     expected=0.0f;
963     got = D3DXVec2Dot(NULL,&v);
964     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
965     expected=0.0f;
966     got = D3DXVec2Dot(NULL,NULL);
967     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
968
969 /*_______________D3DXVec2Hermite__________________________*/
970     expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
971     D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
972     expect_vec(expectedvec,gotvec);
973
974 /*_______________D3DXVec2Length__________________________*/
975    expected = 5.0f;
976    got = D3DXVec2Length(&u);
977    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
978    /* Tests the case NULL */
979     expected=0.0f;
980     got = D3DXVec2Length(NULL);
981     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
982
983 /*_______________D3DXVec2LengthSq________________________*/
984    expected = 25.0f;
985    got = D3DXVec2LengthSq(&u);
986    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
987    /* Tests the case NULL */
988     expected=0.0f;
989     got = D3DXVec2LengthSq(NULL);
990     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
991
992 /*_______________D3DXVec2Lerp__________________________*/
993    expectedvec.x = 68.0f; expectedvec.y = -28.5f;
994    D3DXVec2Lerp(&gotvec,&u,&v,scale);
995    expect_vec(expectedvec,gotvec);
996    /* Tests the case NULL */
997     funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
998     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
999     funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
1000     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1001
1002 /*_______________D3DXVec2Maximize__________________________*/
1003    expectedvec.x = 3.0f; expectedvec.y = 9.0f;
1004    D3DXVec2Maximize(&gotvec,&u,&v);
1005    expect_vec(expectedvec,gotvec);
1006    /* Tests the case NULL */
1007     funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
1008     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1009     funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
1010     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1011
1012 /*_______________D3DXVec2Minimize__________________________*/
1013     expectedvec.x = -7.0f; expectedvec.y = 4.0f;
1014     D3DXVec2Minimize(&gotvec,&u,&v);
1015     expect_vec(expectedvec,gotvec);
1016     /* Tests the case NULL */
1017     funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
1018     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1019     funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
1020     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1021
1022 /*_______________D3DXVec2Normalize_________________________*/
1023     expectedvec.x = 0.6f; expectedvec.y = 0.8f;
1024     D3DXVec2Normalize(&gotvec,&u);
1025     expect_vec(expectedvec,gotvec);
1026     /* Test the nul vector */
1027     expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1028     D3DXVec2Normalize(&gotvec,&nul);
1029     expect_vec(expectedvec,gotvec);
1030
1031 /*_______________D3DXVec2Scale____________________________*/
1032     expectedvec.x = -19.5f; expectedvec.y = -26.0f;
1033     D3DXVec2Scale(&gotvec,&u,scale);
1034     expect_vec(expectedvec,gotvec);
1035     /* Tests the case NULL */
1036     funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
1037     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1038     funcpointer = D3DXVec2Scale(NULL,NULL,scale);
1039     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1040
1041 /*_______________D3DXVec2Subtract__________________________*/
1042    expectedvec.x = 10.0f; expectedvec.y = -5.0f;
1043    D3DXVec2Subtract(&gotvec,&u,&v);
1044    expect_vec(expectedvec,gotvec);
1045    /* Tests the case NULL */
1046     funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
1047     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1048     funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
1049     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1050
1051 /*_______________D3DXVec2Transform_______________________*/
1052     expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
1053     D3DXVec2Transform(&gottrans,&u,&mat);
1054     expect_vec4(expectedtrans,gottrans);
1055
1056 /*_______________D3DXVec2TransformCoord_______________________*/
1057     expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
1058     D3DXVec2TransformCoord(&gotvec,&u,&mat);
1059     expect_vec(expectedvec,gotvec);
1060     /* Test the nul projected vector */
1061     nulproj.x = -2.0f; nulproj.y = -1.0f;
1062     expectedvec.x = 0.0f; expectedvec.y = 0.0f;
1063     D3DXVec2TransformCoord(&gotvec,&nulproj,&mat);
1064     expect_vec(expectedvec,gotvec);
1065
1066  /*_______________D3DXVec2TransformNormal______________________*/
1067     expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1068     D3DXVec2TransformNormal(&gotvec,&u,&mat);
1069     expect_vec(expectedvec,gotvec);
1070 }
1071
1072 static void D3X8Vector3Test(void)
1073 {
1074     D3DVIEWPORT8 viewport;
1075     D3DXVECTOR3 expectedvec, gotvec, nul, nulproj, u, v, w, x;
1076     LPD3DXVECTOR3 funcpointer;
1077     D3DXVECTOR4 expectedtrans, gottrans;
1078     D3DXMATRIX mat, projection, view, world;
1079     FLOAT coeff1, coeff2, expected, got, scale;
1080
1081     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
1082     u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
1083     v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
1084     w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
1085     x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
1086
1087     viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1088     viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
1089
1090     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;
1091     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;
1092     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;
1093     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;
1094
1095     U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
1096     U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
1097     U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
1098     U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
1099     U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
1100     U(view).m[3][3] = -40.0f;
1101
1102     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;
1103     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;
1104     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;
1105     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;
1106
1107     coeff1 = 2.0f; coeff2 = 5.0f;
1108     scale = -6.5f;
1109
1110 /*_______________D3DXVec3Add__________________________*/
1111     expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
1112     D3DXVec3Add(&gotvec,&u,&v);
1113     expect_vec3(expectedvec,gotvec);
1114     /* Tests the case NULL */
1115     funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
1116     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1117     funcpointer = D3DXVec3Add(NULL,NULL,NULL);
1118     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1119
1120 /*_______________D3DXVec3BaryCentric___________________*/
1121     expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1122     D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1123
1124     expect_vec3(expectedvec,gotvec);
1125
1126 /*_______________D3DXVec3CatmullRom____________________*/
1127     expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
1128     D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1129     expect_vec3(expectedvec,gotvec);
1130
1131 /*_______________D3DXVec3Cross________________________*/
1132     expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
1133     D3DXVec3Cross(&gotvec,&u,&v);
1134     expect_vec3(expectedvec,gotvec);
1135     /* Tests the case NULL */
1136     funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
1137     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1138     funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
1139     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1140
1141 /*_______________D3DXVec3Dot__________________________*/
1142     expected = -8.0f;
1143     got = D3DXVec3Dot(&u,&v);
1144     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1145     /* Tests the case NULL */
1146     expected=0.0f;
1147     got = D3DXVec3Dot(NULL,&v);
1148     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1149     expected=0.0f;
1150     got = D3DXVec3Dot(NULL,NULL);
1151     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1152
1153 /*_______________D3DXVec3Hermite__________________________*/
1154     expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
1155     D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
1156     expect_vec3(expectedvec,gotvec);
1157
1158 /*_______________D3DXVec3Length__________________________*/
1159    expected = 11.0f;
1160    got = D3DXVec3Length(&u);
1161    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1162    /* Tests the case NULL */
1163     expected=0.0f;
1164     got = D3DXVec3Length(NULL);
1165     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1166
1167 /*_______________D3DXVec3LengthSq________________________*/
1168     expected = 121.0f;
1169     got = D3DXVec3LengthSq(&u);
1170     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1171    /* Tests the case NULL */
1172     expected=0.0f;
1173     got = D3DXVec3LengthSq(NULL);
1174     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1175
1176 /*_______________D3DXVec3Lerp__________________________*/
1177     expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
1178     D3DXVec3Lerp(&gotvec,&u,&v,scale);
1179     expect_vec3(expectedvec,gotvec);
1180     /* Tests the case NULL */
1181     funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
1182     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1183     funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
1184     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1185
1186 /*_______________D3DXVec3Maximize__________________________*/
1187     expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
1188     D3DXVec3Maximize(&gotvec,&u,&v);
1189     expect_vec3(expectedvec,gotvec);
1190     /* Tests the case NULL */
1191     funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
1192     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1193     funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
1194     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1195
1196 /*_______________D3DXVec3Minimize__________________________*/
1197     expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
1198     D3DXVec3Minimize(&gotvec,&u,&v);
1199     expect_vec3(expectedvec,gotvec);
1200     /* Tests the case NULL */
1201     funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
1202     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1203     funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
1204     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1205
1206 /*_______________D3DXVec3Normalize_________________________*/
1207     expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
1208     D3DXVec3Normalize(&gotvec,&u);
1209     expect_vec3(expectedvec,gotvec);
1210     /* Test the nul vector */
1211     expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1212     D3DXVec3Normalize(&gotvec,&nul);
1213     expect_vec3(expectedvec,gotvec);
1214
1215 /*_______________D3DXVec3Project_________________________*/
1216     expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
1217     D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1218     D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
1219     expect_vec3(expectedvec,gotvec);
1220
1221 /*_______________D3DXVec3Scale____________________________*/
1222     expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
1223     D3DXVec3Scale(&gotvec,&u,scale);
1224     expect_vec3(expectedvec,gotvec);
1225     /* Tests the case NULL */
1226     funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
1227     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1228     funcpointer = D3DXVec3Scale(NULL,NULL,scale);
1229     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1230
1231 /*_______________D3DXVec3Subtract_______________________*/
1232     expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1233     D3DXVec3Subtract(&gotvec,&u,&v);
1234     expect_vec3(expectedvec,gotvec);
1235     /* Tests the case NULL */
1236     funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1237     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1238     funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1239     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1240
1241 /*_______________D3DXVec3Transform_______________________*/
1242     expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1243     D3DXVec3Transform(&gottrans,&u,&mat);
1244     expect_vec4(expectedtrans,gottrans);
1245
1246 /*_______________D3DXVec3TransformCoord_______________________*/
1247     expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1248     D3DXVec3TransformCoord(&gotvec,&u,&mat);
1249     expect_vec3(expectedvec,gotvec);
1250     /* Test the nul projected vector */
1251     nulproj.x = 1.0f; nulproj.y = -1.0f, nulproj.z = -1.0f;
1252     expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1253     D3DXVec3TransformCoord(&gotvec,&nulproj,&mat);
1254     expect_vec3(expectedvec,gotvec);
1255
1256 /*_______________D3DXVec3TransformNormal______________________*/
1257     expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1258     D3DXVec3TransformNormal(&gotvec,&u,&mat);
1259     expect_vec3(expectedvec,gotvec);
1260
1261 /*_______________D3DXVec3Unproject_________________________*/
1262     expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1263     D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1264     D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1265     expect_vec3(expectedvec,gotvec);
1266 }
1267
1268 static void D3X8Vector4Test(void)
1269 {
1270     D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x;
1271     LPD3DXVECTOR4 funcpointer;
1272     D3DXVECTOR4 expectedtrans, gottrans;
1273     D3DXMATRIX mat;
1274     FLOAT coeff1, coeff2, expected, got, scale;
1275
1276     nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
1277     u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1278     v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1279     w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1280     x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1281
1282     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;
1283     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;
1284     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;
1285     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;
1286
1287     coeff1 = 2.0f; coeff2 = 5.0;
1288     scale = -6.5f;
1289
1290 /*_______________D3DXVec4Add__________________________*/
1291     expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1292     D3DXVec4Add(&gotvec,&u,&v);
1293     expect_vec4(expectedvec,gotvec);
1294     /* Tests the case NULL */
1295     funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1296     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1297     funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1298     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1299
1300 /*_______________D3DXVec4BaryCentric____________________*/
1301     expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z =  -44.0f; expectedvec.w = -41.0f;
1302     D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1303     expect_vec4(expectedvec,gotvec);
1304
1305 /*_______________D3DXVec4CatmullRom____________________*/
1306     expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1307     D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1308     expect_vec4(expectedvec,gotvec);
1309
1310 /*_______________D3DXVec4Cross_________________________*/
1311     expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1312     D3DXVec4Cross(&gotvec,&u,&v,&w);
1313     expect_vec4(expectedvec,gotvec);
1314
1315 /*_______________D3DXVec4Dot__________________________*/
1316     expected = 55.0f;
1317     got = D3DXVec4Dot(&u,&v);
1318     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1319     /* Tests the case NULL */
1320     expected=0.0f;
1321     got = D3DXVec4Dot(NULL,&v);
1322     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1323     expected=0.0f;
1324     got = D3DXVec4Dot(NULL,NULL);
1325     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1326
1327 /*_______________D3DXVec4Hermite_________________________*/
1328     expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1329     D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1330     expect_vec4(expectedvec,gotvec);
1331
1332 /*_______________D3DXVec4Length__________________________*/
1333    expected = 11.0f;
1334    got = D3DXVec4Length(&u);
1335    ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1336    /* Tests the case NULL */
1337     expected=0.0f;
1338     got = D3DXVec4Length(NULL);
1339     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1340
1341 /*_______________D3DXVec4LengthSq________________________*/
1342     expected = 121.0f;
1343     got = D3DXVec4LengthSq(&u);
1344     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1345     /* Tests the case NULL */
1346     expected=0.0f;
1347     got = D3DXVec4LengthSq(NULL);
1348     ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1349
1350 /*_______________D3DXVec4Lerp__________________________*/
1351     expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5;  expectedvec.w = 29.5;
1352     D3DXVec4Lerp(&gotvec,&u,&v,scale);
1353     expect_vec4(expectedvec,gotvec);
1354     /* Tests the case NULL */
1355     funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1356     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1357     funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1358     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1359
1360 /*_______________D3DXVec4Maximize__________________________*/
1361     expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1362     D3DXVec4Maximize(&gotvec,&u,&v);
1363     expect_vec4(expectedvec,gotvec);
1364     /* Tests the case NULL */
1365     funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1366     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1367     funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1368     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1369
1370 /*_______________D3DXVec4Minimize__________________________*/
1371     expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1372     D3DXVec4Minimize(&gotvec,&u,&v);
1373     expect_vec4(expectedvec,gotvec);
1374     /* Tests the case NULL */
1375     funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1376     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1377     funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1378     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1379
1380 /*_______________D3DXVec4Normalize_________________________*/
1381     expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1382     D3DXVec4Normalize(&gotvec,&u);
1383     expect_vec4(expectedvec,gotvec);
1384     /* Test the nul vector */
1385     expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expectedvec.w = 0.0f;
1386     D3DXVec4Normalize(&gotvec,&nul);
1387     expect_vec4(expectedvec,gotvec);
1388
1389 /*_______________D3DXVec4Scale____________________________*/
1390     expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1391     D3DXVec4Scale(&gotvec,&u,scale);
1392     expect_vec4(expectedvec,gotvec);
1393     /* Tests the case NULL */
1394     funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1395     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1396     funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1397     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1398
1399 /*_______________D3DXVec4Subtract__________________________*/
1400     expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1401     D3DXVec4Subtract(&gotvec,&u,&v);
1402     expect_vec4(expectedvec,gotvec);
1403     /* Tests the case NULL */
1404     funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1405     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1406     funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1407     ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1408
1409 /*_______________D3DXVec4Transform_______________________*/
1410     expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1411     D3DXVec4Transform(&gottrans,&u,&mat);
1412     expect_vec4(expectedtrans,gottrans);
1413 }
1414
1415 static void test_matrix_stack(void)
1416 {
1417     ID3DXMatrixStack *stack;
1418     ULONG refcount;
1419     HRESULT hr;
1420
1421     const D3DXMATRIX mat1 = {{{
1422          1.0f,  2.0f,  3.0f,  4.0f,
1423          5.0f,  6.0f,  7.0f,  8.0f,
1424          9.0f, 10.0f, 11.0f, 12.0f,
1425         13.0f, 14.0f, 15.0f, 16.0f
1426     }}};
1427
1428     const D3DXMATRIX mat2 = {{{
1429         17.0f, 18.0f, 19.0f, 20.0f,
1430         21.0f, 22.0f, 23.0f, 24.0f,
1431         25.0f, 26.0f, 27.0f, 28.0f,
1432         29.0f, 30.0f, 31.0f, 32.0f
1433     }}};
1434
1435     hr = D3DXCreateMatrixStack(0, &stack);
1436     ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1437     if (FAILED(hr)) return;
1438
1439     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1440             "The top of an empty matrix stack should be an identity matrix\n");
1441
1442     hr = ID3DXMatrixStack_Pop(stack);
1443     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1444
1445     hr = ID3DXMatrixStack_Push(stack);
1446     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1447     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1448
1449     hr = ID3DXMatrixStack_Push(stack);
1450     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1451
1452     hr = ID3DXMatrixStack_LoadMatrix(stack, NULL);
1453     ok(hr == D3DERR_INVALIDCALL, "LoadMatrix returned %#x, expected D3DERR_INVALIDCALL\n", hr);
1454
1455     hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1456     ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1457     expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1458
1459     hr = ID3DXMatrixStack_Push(stack);
1460     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1461     expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1462
1463     hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1464     ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1465     expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1466
1467     hr = ID3DXMatrixStack_Push(stack);
1468     ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1469     expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1470
1471     hr = ID3DXMatrixStack_LoadIdentity(stack);
1472     ok(SUCCEEDED(hr), "LoadIdentity failed, hr %#x\n", hr);
1473     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1474
1475     hr = ID3DXMatrixStack_Pop(stack);
1476     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1477     expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1478
1479     hr = ID3DXMatrixStack_Pop(stack);
1480     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1481     expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1482
1483     hr = ID3DXMatrixStack_Pop(stack);
1484     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1485     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1486
1487     hr = ID3DXMatrixStack_Pop(stack);
1488     ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1489     ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)), "The top should be an identity matrix\n");
1490
1491     hr = ID3DXMatrixStack_MultMatrix(stack, NULL);
1492     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1493
1494     hr = ID3DXMatrixStack_MultMatrixLocal(stack, NULL);
1495     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1496
1497     hr = ID3DXMatrixStack_RotateAxis(stack, NULL, 2.0f);
1498     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1499
1500     hr = ID3DXMatrixStack_RotateAxisLocal(stack, NULL, 2.0f);
1501     ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1502
1503     refcount = ID3DXMatrixStack_Release(stack);
1504     ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1505 }
1506
1507 START_TEST(math)
1508 {
1509     D3DXColorTest();
1510     D3DXFresnelTest();
1511     D3DXMatrixTest();
1512     D3DXPlaneTest();
1513     D3X8QuaternionTest();
1514     D3X8Vector2Test();
1515     D3X8Vector3Test();
1516     D3X8Vector4Test();
1517     test_matrix_stack();
1518 }