2 * Copyright 2007 David Adam
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.
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.
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
22 #include "wine/test.h"
24 #define admitted_error 0.0001f
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);
28 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
32 for (i = 0; i < 4; ++i)
34 for (j = 0; j < 4; ++j)
36 if (fabs(U(*m1).m[i][j] - U(*m2).m[i][j]) > admitted_error)
44 #define expect_mat(expectedmat, gotmat) \
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]); \
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);
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);
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);
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);
68 static void D3DXColorTest(void)
70 D3DXCOLOR color, color1, color2, expected, got;
71 LPD3DXCOLOR funcpointer;
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;
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);
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);
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);
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);
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);
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);
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);
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);
169 static void D3DXFresnelTest(void)
174 got = D3DXFresnelTerm(0.5f,1.5);
175 ok( fabs(got - expected) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
178 static void D3DXMatrixTest(void)
180 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
181 LPD3DXMATRIX funcpointer;
184 D3DXVECTOR3 at, axis, eye, last, scaling;
187 FLOAT angle, determinant, expectedfloat, gotfloat;
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;
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;
203 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
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;
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;
214 light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
216 angle = D3DX_PI/3.0f;
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);
233 /*____________D3DXMatrixfDeterminant_____________*/
234 expectedfloat = -147888.0f;
235 gotfloat = D3DXMatrixfDeterminant(&mat);
236 ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
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);
250 /*____________D3DXMatrixIsIdentity______________*/
252 memset(&mat3, 0, sizeof(mat3));
253 got = D3DXMatrixIsIdentity(&mat3);
254 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
255 D3DXMatrixIdentity(&mat3);
257 got = D3DXMatrixIsIdentity(&mat3);
258 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
259 U(mat3).m[0][0] = 0.000009f;
261 got = D3DXMatrixIsIdentity(&mat3);
262 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
263 /* Test the NULL case */
265 got = D3DXMatrixIsIdentity(NULL);
266 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
477 static void D3DXPlaneTest(void)
480 D3DXPLANE expectedplane, gotplane, nulplane, plane;
481 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
482 LPD3DXVECTOR3 funcpointer;
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;
493 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
495 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
497 /*_______________D3DXPlaneDot________________*/
499 got = D3DXPlaneDot(&plane,&vec),
500 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
502 got = D3DXPlaneDot(NULL,&vec),
503 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
505 got = D3DXPlaneDot(NULL,NULL),
506 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
508 /*_______________D3DXPlaneDotCoord________________*/
510 got = D3DXPlaneDotCoord(&plane,&vec),
511 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
513 got = D3DXPlaneDotCoord(NULL,&vec),
514 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
516 got = D3DXPlaneDotCoord(NULL,NULL),
517 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
519 /*_______________D3DXPlaneDotNormal______________*/
521 got = D3DXPlaneDotNormal(&plane,&vec),
522 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
524 got = D3DXPlaneDotNormal(NULL,&vec),
525 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
527 got = D3DXPlaneDotNormal(NULL,NULL),
528 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
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);
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);
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);
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);
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);
582 static void D3X8QuaternionTest(void)
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;
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;
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);
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);
615 /*_______________D3DXQuaternionDot______________________*/
617 got = D3DXQuaternionDot(&q,&r);
618 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
619 /* Tests the case NULL */
621 got = D3DXQuaternionDot(NULL,&r);
622 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
624 got = D3DXQuaternionDot(NULL,NULL);
625 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
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);
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);
658 /*_______________D3DXQuaternionIsIdentity________________*/
659 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
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);
671 /*_______________D3DXQuaternionLength__________________________*/
673 got = D3DXQuaternionLength(&q);
674 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
675 /* Tests the case NULL */
677 got = D3DXQuaternionLength(NULL);
678 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
680 /*_______________D3DXQuaternionLengthSq________________________*/
682 got = D3DXQuaternionLengthSq(&q);
683 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
684 /* Tests the case NULL */
686 got = D3DXQuaternionLengthSq(NULL);
687 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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) };
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);
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);
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);
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);
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);
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);
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);
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;
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;
898 D3DXQuaternionToAxisAngle(&nul,&axis,&angle);
899 expect_vec3(expectedvec,axis);
900 ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle);
903 static void D3X8Vector2Test(void)
905 D3DXVECTOR2 expectedvec, gotvec, nul, nulproj, u, v, w, x;
906 LPD3DXVECTOR2 funcpointer;
907 D3DXVECTOR4 expectedtrans, gottrans;
909 FLOAT coeff1, coeff2, expected, got, scale;
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;
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;
922 coeff1 = 2.0f; coeff2 = 5.0f;
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);
935 /*_______________D3DXVec2BaryCentric___________________*/
936 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
937 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
938 expect_vec(expectedvec,gotvec);
940 /*_______________D3DXVec2CatmullRom____________________*/
941 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
942 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
943 expect_vec(expectedvec,gotvec);
945 /*_______________D3DXVec2CCW__________________________*/
947 got = D3DXVec2CCW(&u,&v);
948 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
949 /* Tests the case NULL */
951 got = D3DXVec2CCW(NULL,&v);
952 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
954 got = D3DXVec2CCW(NULL,NULL);
955 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
957 /*_______________D3DXVec2Dot__________________________*/
959 got = D3DXVec2Dot(&u,&v);
960 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
961 /* Tests the case NULL */
963 got = D3DXVec2Dot(NULL,&v);
964 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
966 got = D3DXVec2Dot(NULL,NULL);
967 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
969 /*_______________D3DXVec2Hermite__________________________*/
970 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
971 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
972 expect_vec(expectedvec,gotvec);
974 /*_______________D3DXVec2Length__________________________*/
976 got = D3DXVec2Length(&u);
977 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
978 /* Tests the case NULL */
980 got = D3DXVec2Length(NULL);
981 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
983 /*_______________D3DXVec2LengthSq________________________*/
985 got = D3DXVec2LengthSq(&u);
986 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
987 /* Tests the case NULL */
989 got = D3DXVec2LengthSq(NULL);
990 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
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);
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);
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);
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);
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);
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);
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);
1066 /*_______________D3DXVec2TransformNormal______________________*/
1067 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
1068 D3DXVec2TransformNormal(&gotvec,&u,&mat);
1069 expect_vec(expectedvec,gotvec);
1072 static void D3X8Vector3Test(void)
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;
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;
1087 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
1088 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
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;
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;
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;
1107 coeff1 = 2.0f; coeff2 = 5.0f;
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);
1120 /*_______________D3DXVec3BaryCentric___________________*/
1121 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
1122 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1124 expect_vec3(expectedvec,gotvec);
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);
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);
1141 /*_______________D3DXVec3Dot__________________________*/
1143 got = D3DXVec3Dot(&u,&v);
1144 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1145 /* Tests the case NULL */
1147 got = D3DXVec3Dot(NULL,&v);
1148 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1150 got = D3DXVec3Dot(NULL,NULL);
1151 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
1158 /*_______________D3DXVec3Length__________________________*/
1160 got = D3DXVec3Length(&u);
1161 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1162 /* Tests the case NULL */
1164 got = D3DXVec3Length(NULL);
1165 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1167 /*_______________D3DXVec3LengthSq________________________*/
1169 got = D3DXVec3LengthSq(&u);
1170 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1171 /* Tests the case NULL */
1173 got = D3DXVec3LengthSq(NULL);
1174 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
1268 static void D3X8Vector4Test(void)
1270 D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x;
1271 LPD3DXVECTOR4 funcpointer;
1272 D3DXVECTOR4 expectedtrans, gottrans;
1274 FLOAT coeff1, coeff2, expected, got, scale;
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;
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;
1287 coeff1 = 2.0f; coeff2 = 5.0;
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);
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);
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);
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);
1315 /*_______________D3DXVec4Dot__________________________*/
1317 got = D3DXVec4Dot(&u,&v);
1318 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1319 /* Tests the case NULL */
1321 got = D3DXVec4Dot(NULL,&v);
1322 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1324 got = D3DXVec4Dot(NULL,NULL);
1325 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
1332 /*_______________D3DXVec4Length__________________________*/
1334 got = D3DXVec4Length(&u);
1335 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1336 /* Tests the case NULL */
1338 got = D3DXVec4Length(NULL);
1339 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1341 /*_______________D3DXVec4LengthSq________________________*/
1343 got = D3DXVec4LengthSq(&u);
1344 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1345 /* Tests the case NULL */
1347 got = D3DXVec4LengthSq(NULL);
1348 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
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);
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);
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);
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);
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);
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);
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);
1415 static void test_matrix_stack(void)
1417 ID3DXMatrixStack *stack;
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
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
1435 hr = D3DXCreateMatrixStack(0, &stack);
1436 ok(SUCCEEDED(hr), "Failed to create a matrix stack, hr %#x\n", hr);
1437 if (FAILED(hr)) return;
1439 ok(D3DXMatrixIsIdentity(ID3DXMatrixStack_GetTop(stack)),
1440 "The top of an empty matrix stack should be an identity matrix\n");
1442 hr = ID3DXMatrixStack_Pop(stack);
1443 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
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");
1449 hr = ID3DXMatrixStack_Push(stack);
1450 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1452 hr = ID3DXMatrixStack_LoadMatrix(stack, NULL);
1453 ok(hr == D3DERR_INVALIDCALL, "LoadMatrix returned %#x, expected D3DERR_INVALIDCALL\n", hr);
1455 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat1);
1456 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1457 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1459 hr = ID3DXMatrixStack_Push(stack);
1460 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1461 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
1463 hr = ID3DXMatrixStack_LoadMatrix(stack, &mat2);
1464 ok(SUCCEEDED(hr), "LoadMatrix failed, hr %#x\n", hr);
1465 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1467 hr = ID3DXMatrixStack_Push(stack);
1468 ok(SUCCEEDED(hr), "Push failed, hr %#x\n", hr);
1469 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
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");
1475 hr = ID3DXMatrixStack_Pop(stack);
1476 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1477 expect_mat(&mat2, ID3DXMatrixStack_GetTop(stack));
1479 hr = ID3DXMatrixStack_Pop(stack);
1480 ok(SUCCEEDED(hr), "Pop failed, hr %#x\n", hr);
1481 expect_mat(&mat1, ID3DXMatrixStack_GetTop(stack));
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");
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");
1491 hr = ID3DXMatrixStack_MultMatrix(stack, NULL);
1492 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1494 hr = ID3DXMatrixStack_MultMatrixLocal(stack, NULL);
1495 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1497 hr = ID3DXMatrixStack_RotateAxis(stack, NULL, 2.0f);
1498 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1500 hr = ID3DXMatrixStack_RotateAxisLocal(stack, NULL, 2.0f);
1501 ok(hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
1503 refcount = ID3DXMatrixStack_Release(stack);
1504 ok(!refcount, "Matrix stack has %u references left.\n", refcount);
1513 D3X8QuaternionTest();
1517 test_matrix_stack();