push 97f44e0adb27fff75ba63d8fb97c65db9edfbe82
[wine/hacks.git] / dlls / d3dx8 / tests / math.c
blob229d0b7dc61d7b73cbff90f5230b5dcb7cc124b1
1 /*
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
19 #include <assert.h>
20 #include "d3dx8.h"
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 #define expect_mat(expectedmat,gotmat)\
29 { \
30 int i,j,equal=1; \
31 for (i=0; i<4; i++)\
33 for (j=0; j<4; j++)\
35 if (fabs(U(expectedmat).m[i][j]-U(gotmat).m[i][j])>admitted_error) \
37 equal=0;\
41 ok(equal, "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" \
42 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
43 U(expectedmat).m[0][0],U(expectedmat).m[0][1],U(expectedmat).m[0][2],U(expectedmat).m[0][3], \
44 U(expectedmat).m[1][0],U(expectedmat).m[1][1],U(expectedmat).m[1][2],U(expectedmat).m[1][3], \
45 U(expectedmat).m[2][0],U(expectedmat).m[2][1],U(expectedmat).m[2][2],U(expectedmat).m[2][3], \
46 U(expectedmat).m[3][0],U(expectedmat).m[3][1],U(expectedmat).m[3][2],U(expectedmat).m[3][3], \
47 U(gotmat).m[0][0],U(gotmat).m[0][1],U(gotmat).m[0][2],U(gotmat).m[0][3], \
48 U(gotmat).m[1][0],U(gotmat).m[1][1],U(gotmat).m[1][2],U(gotmat).m[1][3], \
49 U(gotmat).m[2][0],U(gotmat).m[2][1],U(gotmat).m[2][2],U(gotmat).m[2][3], \
50 U(gotmat).m[3][0],U(gotmat).m[3][1],U(gotmat).m[3][2],U(gotmat).m[3][3]); \
53 #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);
55 #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);
57 #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);
59 #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);
61 static void D3DXColorTest(void)
63 D3DXCOLOR color, color1, color2, expected, got;
64 LPD3DXCOLOR funcpointer;
65 FLOAT scale;
67 color.r = 0.2f; color.g = 0.75f; color.b = 0.41f; color.a = 0.93f;
68 color1.r = 0.6f; color1.g = 0.55f; color1.b = 0.23f; color1.a = 0.82f;
69 color2.r = 0.3f; color2.g = 0.5f; color2.b = 0.76f; color2.a = 0.11f;
71 scale = 0.3f;
73 /*_______________D3DXColorAdd________________*/
74 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
75 D3DXColorAdd(&got,&color1,&color2);
76 expect_color(expected,got);
77 /* Test the NULL case */
78 funcpointer = D3DXColorAdd(&got,NULL,&color2);
79 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
80 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
81 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
82 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
83 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
85 /*_______________D3DXColorAdjustContrast______*/
86 expected.r = 0.41f; expected.g = 0.575f; expected.b = 0.473f, expected.a = 0.93f;
87 D3DXColorAdjustContrast(&got,&color,scale);
88 expect_color(expected,got);
90 /*_______________D3DXColorAdjustSaturation______*/
91 expected.r = 0.486028f; expected.g = 0.651028f; expected.b = 0.549028f, expected.a = 0.93f;
92 D3DXColorAdjustSaturation(&got,&color,scale);
93 expect_color(expected,got);
95 /*_______________D3DXColorLerp________________*/
96 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
97 D3DXColorLerp(&got,&color,&color1,scale);
98 expect_color(expected,got);
99 /* Test the NULL case */
100 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
101 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
102 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
103 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
104 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
105 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
107 /*_______________D3DXColorModulate________________*/
108 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
109 D3DXColorModulate(&got,&color1,&color2);
110 expect_color(expected,got);
111 /* Test the NULL case */
112 funcpointer = D3DXColorModulate(&got,NULL,&color2);
113 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
114 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
115 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
116 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
117 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
119 /*_______________D3DXColorNegative________________*/
120 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
121 D3DXColorNegative(&got,&color);
122 expect_color(got,expected);
123 /* Test the greater than 1 case */
124 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
125 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
126 D3DXColorNegative(&got,&color1);
127 expect_color(got,expected);
128 /* Test the negative case */
129 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
130 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
131 D3DXColorNegative(&got,&color1);
132 expect_color(got,expected);
133 /* Test the NULL case */
134 funcpointer = D3DXColorNegative(&got,NULL);
135 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
136 funcpointer = D3DXColorNegative(NULL,NULL);
137 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
139 /*_______________D3DXColorScale________________*/
140 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
141 D3DXColorScale(&got,&color,scale);
142 expect_color(expected,got);
143 /* Test the NULL case */
144 funcpointer = D3DXColorScale(&got,NULL,scale);
145 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
146 funcpointer = D3DXColorScale(NULL,NULL,scale);
147 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
149 /*_______________D3DXColorSubtract_______________*/
150 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
151 D3DXColorSubtract(&got,&color,&color2);
152 expect_color(expected,got);
153 /* Test the NULL case */
154 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
155 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
156 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
157 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
158 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
159 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
162 static void D3DXMatrixTest(void)
164 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
165 LPD3DXMATRIX funcpointer;
166 D3DXPLANE plane;
167 D3DXQUATERNION q;
168 D3DXVECTOR3 at, axis, eye;
169 D3DXVECTOR4 light;
170 BOOL expected, got;
171 FLOAT angle, determinant, expectedfloat, gotfloat;
173 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
174 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
175 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
176 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
177 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
178 U(mat).m[3][3] = -40.0f;
180 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
181 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
182 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
183 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
184 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
185 U(mat2).m[3][3] = -1.0f;
187 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
189 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
191 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
192 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
193 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
195 light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
197 angle = D3DX_PI/3.0f;
199 /*____________D3DXMatrixAffineTransformation______*/
200 expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
201 expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
202 expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
203 expectedmat.m[3][0] = -1239.0f; expectedmat.m[3][1] = 667.0f; expectedmat.m[3][2] = 567.0f; expectedmat.m[3][3] = 1.0f;
204 D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
205 expect_mat(expectedmat,gotmat);
206 /* Test the NULL case */
207 expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
208 expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
209 expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
210 expectedmat.m[3][0] = 1.0f; expectedmat.m[3][1] = -3.0f; expectedmat.m[3][2] = 7.0f; expectedmat.m[3][3] = 1.0f;
211 D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
212 expect_mat(expectedmat,gotmat);
214 /*____________D3DXMatrixfDeterminant_____________*/
215 expectedfloat = -147888.0f;
216 gotfloat = D3DXMatrixfDeterminant(&mat);
217 ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
219 /*____________D3DXMatrixInverse______________*/
220 expectedmat.m[0][0] = 16067.0f/73944.0f; expectedmat.m[0][1] = -10165.0f/147888.0f; expectedmat.m[0][2] = -2729.0f/147888.0f; expectedmat.m[0][3] = -1631.0f/49296.0f;
221 expectedmat.m[1][0] = -565.0f/36972.0f; expectedmat.m[1][1] = 2723.0f/73944.0f; expectedmat.m[1][2] = -1073.0f/73944.0f; expectedmat.m[1][3] = 289.0f/24648.0f;
222 expectedmat.m[2][0] = -389.0f/2054.0f; expectedmat.m[2][1] = 337.0f/4108.0f; expectedmat.m[2][2] = 181.0f/4108.0f; expectedmat.m[2][3] = 317.0f/4108.0f;
223 expectedmat.m[3][0] = 163.0f/5688.0f; expectedmat.m[3][1] = -101.0f/11376.0f; expectedmat.m[3][2] = -73.0f/11376.0f; expectedmat.m[3][3] = -127.0f/3792.0f;
224 expectedfloat = -147888.0f;
225 D3DXMatrixInverse(&gotmat,&determinant,&mat);
226 expect_mat(expectedmat,gotmat);
227 ok(fabs( determinant - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
228 funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
229 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
231 /*____________D3DXMatrixIsIdentity______________*/
232 expected = FALSE;
233 got = D3DXMatrixIsIdentity(&mat3);
234 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
235 D3DXMatrixIdentity(&mat3);
236 expected = TRUE;
237 got = D3DXMatrixIsIdentity(&mat3);
238 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
239 U(mat3).m[0][0] = 0.000009f;
240 expected = FALSE;
241 got = D3DXMatrixIsIdentity(&mat3);
242 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
243 /* Test the NULL case */
244 expected = FALSE;
245 got = D3DXMatrixIsIdentity(NULL);
246 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
248 /*____________D3DXMatrixLookatLH_______________*/
249 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;
250 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;
251 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;
252 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;
253 D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
254 expect_mat(expectedmat,gotmat);
256 /*____________D3DXMatrixLookatRH_______________*/
257 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;
258 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;
259 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;
260 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;
261 D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
262 expect_mat(expectedmat,gotmat);
264 /*____________D3DXMatrixMultiply______________*/
265 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;
266 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;
267 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;
268 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;
269 D3DXMatrixMultiply(&gotmat,&mat,&mat2);
270 expect_mat(expectedmat,gotmat);
272 /*____________D3DXMatrixMultiplyTranspose____*/
273 expectedmat.m[0][0] = 73.0f; expectedmat.m[0][1] = 231.0f; expectedmat.m[0][2] = 239.0f; expectedmat.m[0][3] = -164.0f;
274 expectedmat.m[1][0] = 193.0f; expectedmat.m[1][1] = 551.0f; expectedmat.m[1][2] = 523.0f; expectedmat.m[1][3] = -320.0;
275 expectedmat.m[2][0] = -197.0f; expectedmat.m[2][1] = -489.0f; expectedmat.m[2][2] = -400.0f; expectedmat.m[2][3] = 187.0f;
276 expectedmat.m[3][0] = -77.0f; expectedmat.m[3][1] = -169.0f; expectedmat.m[3][2] = -116.0f; expectedmat.m[3][3] = 31.0f;
277 D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
278 expect_mat(expectedmat,gotmat);
280 /*____________D3DXMatrixOrthoLH_______________*/
281 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;
282 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;
283 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;
284 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;
285 D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
286 expect_mat(expectedmat,gotmat);
288 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
289 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;
290 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;
291 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;
292 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;
293 D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
294 expect_mat(expectedmat,gotmat);
296 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
297 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;
298 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;
299 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;
300 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;
301 D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
302 expect_mat(expectedmat,gotmat);
304 /*____________D3DXMatrixOrthoRH_______________*/
305 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;
306 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;
307 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;
308 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;
309 D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
310 expect_mat(expectedmat,gotmat);
312 /*____________D3DXMatrixPerspectiveFovLH_______________*/
313 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;
314 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;
315 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;
316 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;
317 D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
318 expect_mat(expectedmat,gotmat);
320 /*____________D3DXMatrixPerspectiveFovRH_______________*/
321 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;
322 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;
323 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;
324 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;
325 D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
326 expect_mat(expectedmat,gotmat);
328 /*____________D3DXMatrixPerspectiveLH_______________*/
329 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;
330 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;
331 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;
332 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;
333 D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
334 expect_mat(expectedmat,gotmat);
336 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
337 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;
338 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;
339 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;
340 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;
341 D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
342 expect_mat(expectedmat,gotmat);
344 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
345 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;
346 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;
347 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;
348 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;
349 D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
350 expect_mat(expectedmat,gotmat);
352 /*____________D3DXMatrixPerspectiveRH_______________*/
353 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;
354 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;
355 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;
356 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;
357 D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
358 expect_mat(expectedmat,gotmat);
360 /*____________D3DXMatrixReflect______________*/
361 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;
362 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;
363 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;
364 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;
365 D3DXMatrixReflect(&gotmat,&plane);
366 expect_mat(expectedmat,gotmat);
367 /*____________D3DXMatrixRotationAxis_____*/
368 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;
369 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;
370 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;
371 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;
372 D3DXMatrixRotationAxis(&gotmat,&axis,angle);
373 expect_mat(expectedmat,gotmat);
375 /*____________D3DXMatrixRotationQuaternion______________*/
376 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;
377 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;
378 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;
379 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;
380 D3DXMatrixRotationQuaternion(&gotmat,&q);
381 expect_mat(expectedmat,gotmat);
383 /*____________D3DXMatrixRotationX______________*/
384 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;
385 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;
386 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;
387 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;
388 D3DXMatrixRotationX(&gotmat,angle);
389 expect_mat(expectedmat,gotmat);
391 /*____________D3DXMatrixRotationY______________*/
392 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;
393 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;
394 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;
395 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;
396 D3DXMatrixRotationY(&gotmat,angle);
397 expect_mat(expectedmat,gotmat);
399 /*____________D3DXMatrixRotationYawPitchRoll____*/
400 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;
401 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;
402 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;
403 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;
404 D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
405 expect_mat(expectedmat,gotmat);
407 /*____________D3DXMatrixRotationZ______________*/
408 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;
409 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;
410 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;
411 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;
412 D3DXMatrixRotationZ(&gotmat,angle);
413 expect_mat(expectedmat,gotmat);
415 /*____________D3DXMatrixScaling______________*/
416 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;
417 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;
418 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;
419 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;
420 D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
421 expect_mat(expectedmat,gotmat);
423 /*____________D3DXMatrixShadow______________*/
424 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;
425 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;
426 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;
427 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;
428 D3DXMatrixShadow(&gotmat,&light,&plane);
429 expect_mat(expectedmat,gotmat);
431 /*____________D3DXMatrixTranslation______________*/
432 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;
433 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;
434 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;
435 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;
436 D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
437 expect_mat(expectedmat,gotmat);
439 /*____________D3DXMatrixTranspose______________*/
440 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;
441 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;
442 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;
443 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;
444 D3DXMatrixTranspose(&gotmat,&mat);
445 expect_mat(expectedmat,gotmat);
448 static void D3DXPlaneTest(void)
450 D3DXMATRIX mat;
451 D3DXPLANE expectedplane, gotplane, nulplane, plane;
452 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2, vec3;
453 LPD3DXVECTOR3 funcpointer;
454 D3DXVECTOR4 vec;
455 FLOAT expected, got;
457 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
458 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
459 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
460 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
461 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
462 U(mat).m[3][3] = -40.0f;
464 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
466 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
468 /*_______________D3DXPlaneDot________________*/
469 expected = 42.0f;
470 got = D3DXPlaneDot(&plane,&vec),
471 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
472 expected = 0.0f;
473 got = D3DXPlaneDot(NULL,&vec),
474 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
475 expected = 0.0f;
476 got = D3DXPlaneDot(NULL,NULL),
477 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
479 /*_______________D3DXPlaneDotCoord________________*/
480 expected = -28.0f;
481 got = D3DXPlaneDotCoord(&plane,&vec),
482 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
483 expected = 0.0f;
484 got = D3DXPlaneDotCoord(NULL,&vec),
485 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
486 expected = 0.0f;
487 got = D3DXPlaneDotCoord(NULL,NULL),
488 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
490 /*_______________D3DXPlaneDotNormal______________*/
491 expected = -35.0f;
492 got = D3DXPlaneDotNormal(&plane,&vec),
493 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
494 expected = 0.0f;
495 got = D3DXPlaneDotNormal(NULL,&vec),
496 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
497 expected = 0.0f;
498 got = D3DXPlaneDotNormal(NULL,NULL),
499 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
501 /*_______________D3DXPlaneFromPointNormal_______*/
502 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
503 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
504 expectedplane.a = 17.0f; expectedplane.b = 31.0f; expectedplane.c = 24.0f; expectedplane.d = -950.0f;
505 D3DXPlaneFromPointNormal(&gotplane,&vec1,&vec2);
506 expect_plane(expectedplane, gotplane);
508 /*_______________D3DXPlaneFromPoints_______*/
509 vec1.x = 1.0f; vec1.y = 2.0f; vec1.z = 3.0f;
510 vec2.x = 1.0f; vec2.y = -6.0f; vec2.z = -5.0f;
511 vec3.x = 83.0f; vec3.y = 74.0f; vec3.z = 65.0f;
512 expectedplane.a = 0.085914f; expectedplane.b = -0.704492f; expectedplane.c = 0.704492f; expectedplane.d = -0.790406f;
513 D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
514 expect_plane(expectedplane, gotplane);
515 /* Test if 2 vectors are parallels */
516 vec3.x = 1.0f; vec3.y = 1.0f; vec3.z = 2.0f;
517 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
518 D3DXPlaneFromPoints(&gotplane,&vec1,&vec2,&vec3);
519 expect_plane(expectedplane, gotplane);
521 /*_______________D3DXPlaneIntersectLine___________*/
522 vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
523 vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
524 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
525 D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
526 expect_vec3(expectedvec, gotvec);
527 /* Test a parallele line */
528 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
529 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
530 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
531 funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
532 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
534 /*_______________D3DXPlaneNormalize______________*/
535 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);
536 D3DXPlaneNormalize(&gotplane, &plane);
537 expect_plane(expectedplane, gotplane);
538 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
539 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
540 D3DXPlaneNormalize(&gotplane, &nulplane);
541 expect_plane(expectedplane, gotplane);
542 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 4.3f;
543 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
544 D3DXPlaneNormalize(&gotplane, &nulplane);
545 expect_plane(expectedplane, gotplane);
547 /*_______________D3DXPlaneTransform____________*/
548 expectedplane.a = 49.0f; expectedplane.b = -98.0f; expectedplane.c = 55.0f; expectedplane.d = -165.0f;
549 D3DXPlaneTransform(&gotplane,&plane,&mat);
550 expect_plane(expectedplane, gotplane);
553 static void D3X8QuaternionTest(void)
555 D3DXQUATERNION expectedquat, gotquat, nul, q, r, s, t, u;
556 LPD3DXQUATERNION funcpointer;
557 FLOAT expected, got, scale, scale2;
558 BOOL expectedbool, gotbool;
560 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
561 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
562 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
563 t.x = -1111.0f, t.y= 111.0f; t.z = -11.0f; t.w = 1.0f;
564 u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
566 scale = 0.3f;
567 scale2 = 0.78f;
569 /*_______________D3DXQuaternionBaryCentric________________________*/
570 expectedquat.x = -867.444458; expectedquat.y = 87.851111f; expectedquat.z = -9.937778f; expectedquat.w = 3.235555f;
571 D3DXQuaternionBaryCentric(&gotquat,&q,&r,&t,scale,scale2);
572 expect_vec4(expectedquat,gotquat);
574 /*_______________D3DXQuaternionConjugate________________*/
575 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
576 D3DXQuaternionConjugate(&gotquat,&q);
577 expect_vec4(expectedquat,gotquat);
578 /* Test the NULL case */
579 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
580 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
581 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
582 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
584 /*_______________D3DXQuaternionDot______________________*/
585 expected = 55.0f;
586 got = D3DXQuaternionDot(&q,&r);
587 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
588 /* Tests the case NULL */
589 expected=0.0f;
590 got = D3DXQuaternionDot(NULL,&r);
591 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
592 expected=0.0f;
593 got = D3DXQuaternionDot(NULL,NULL);
594 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
596 /*_______________D3DXQuaternionIdentity________________*/
597 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
598 D3DXQuaternionIdentity(&gotquat);
599 expect_vec4(expectedquat,gotquat);
600 /* Test the NULL case */
601 funcpointer = D3DXQuaternionIdentity(NULL);
602 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
604 /*_______________D3DXQuaternionInverse________________________*/
605 expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
606 D3DXQuaternionInverse(&gotquat,&q);
607 expect_vec4(expectedquat,gotquat);
608 /* test the null quaternion */
609 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
610 D3DXQuaternionInverse(&gotquat,&nul);
611 expect_vec4(expectedquat,gotquat);
613 /*_______________D3DXQuaternionIsIdentity________________*/
614 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
615 expectedbool = TRUE;
616 gotbool = D3DXQuaternionIsIdentity(&s);
617 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
618 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
619 expectedbool = FALSE;
620 gotbool = D3DXQuaternionIsIdentity(&q);
621 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
622 /* Test the NULL case */
623 gotbool = D3DXQuaternionIsIdentity(NULL);
624 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
626 /*_______________D3DXQuaternionLength__________________________*/
627 expected = 11.0f;
628 got = D3DXQuaternionLength(&q);
629 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
630 /* Tests the case NULL */
631 expected=0.0f;
632 got = D3DXQuaternionLength(NULL);
633 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
635 /*_______________D3DXQuaternionLengthSq________________________*/
636 expected = 121.0f;
637 got = D3DXQuaternionLengthSq(&q);
638 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
639 /* Tests the case NULL */
640 expected=0.0f;
641 got = D3DXQuaternionLengthSq(NULL);
642 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
644 /*_______________D3DXQuaternionMultiply________________________*/
645 expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
646 D3DXQuaternionMultiply(&gotquat,&q,&r);
647 expect_vec4(expectedquat,gotquat);
649 /*_______________D3DXQuaternionNormalize________________________*/
650 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
651 D3DXQuaternionNormalize(&gotquat,&q);
652 expect_vec4(expectedquat,gotquat);
653 /* Test the nul quaternion */
654 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
655 D3DXQuaternionNormalize(&gotquat,&nul);
656 expect_vec4(expectedquat,gotquat);
658 /*_______________D3DXQuaternionSlerp________________________*/
659 expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
660 D3DXQuaternionSlerp(&gotquat,&q,&r,scale);
661 expect_vec4(expectedquat,gotquat);
662 expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
663 D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
664 expect_vec4(expectedquat,gotquat);
666 /*_______________D3DXQuaternionSquad________________________*/
667 expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
668 D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale);
669 expect_vec4(expectedquat,gotquat);
672 static void D3X8Vector2Test(void)
674 D3DXVECTOR2 expectedvec, gotvec, nul, nulproj, u, v, w, x;
675 LPD3DXVECTOR2 funcpointer;
676 D3DXVECTOR4 expectedtrans, gottrans;
677 D3DXMATRIX mat;
678 FLOAT coeff1, coeff2, expected, got, scale;
680 nul.x = 0.0f; nul.y = 0.0f;
681 u.x = 3.0f; u.y = 4.0f;
682 v.x = -7.0f; v.y = 9.0f;
683 w.x = 4.0f; w.y = -3.0f;
684 x.x = 2.0f; x.y = -11.0f;
686 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;
687 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;
688 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;
689 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;
691 coeff1 = 2.0f; coeff2 = 5.0f;
692 scale = -6.5f;
694 /*_______________D3DXVec2Add__________________________*/
695 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
696 D3DXVec2Add(&gotvec,&u,&v);
697 expect_vec(expectedvec,gotvec);
698 /* Tests the case NULL */
699 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
700 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
701 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
702 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
704 /*_______________D3DXVec2BaryCentric___________________*/
705 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
706 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
707 expect_vec(expectedvec,gotvec);
709 /*_______________D3DXVec2CatmullRom____________________*/
710 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
711 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
712 expect_vec(expectedvec,gotvec);
714 /*_______________D3DXVec2CCW__________________________*/
715 expected = 55.0f;
716 got = D3DXVec2CCW(&u,&v);
717 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
718 /* Tests the case NULL */
719 expected=0.0f;
720 got = D3DXVec2CCW(NULL,&v);
721 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
722 expected=0.0f;
723 got = D3DXVec2CCW(NULL,NULL);
724 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
726 /*_______________D3DXVec2Dot__________________________*/
727 expected = 15.0f;
728 got = D3DXVec2Dot(&u,&v);
729 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
730 /* Tests the case NULL */
731 expected=0.0f;
732 got = D3DXVec2Dot(NULL,&v);
733 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
734 expected=0.0f;
735 got = D3DXVec2Dot(NULL,NULL);
736 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
738 /*_______________D3DXVec2Hermite__________________________*/
739 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
740 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
741 expect_vec(expectedvec,gotvec);
743 /*_______________D3DXVec2Length__________________________*/
744 expected = 5.0f;
745 got = D3DXVec2Length(&u);
746 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
747 /* Tests the case NULL */
748 expected=0.0f;
749 got = D3DXVec2Length(NULL);
750 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
752 /*_______________D3DXVec2LengthSq________________________*/
753 expected = 25.0f;
754 got = D3DXVec2LengthSq(&u);
755 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
756 /* Tests the case NULL */
757 expected=0.0f;
758 got = D3DXVec2LengthSq(NULL);
759 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
761 /*_______________D3DXVec2Lerp__________________________*/
762 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
763 D3DXVec2Lerp(&gotvec,&u,&v,scale);
764 expect_vec(expectedvec,gotvec);
765 /* Tests the case NULL */
766 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
767 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
768 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
769 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
771 /*_______________D3DXVec2Maximize__________________________*/
772 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
773 D3DXVec2Maximize(&gotvec,&u,&v);
774 expect_vec(expectedvec,gotvec);
775 /* Tests the case NULL */
776 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
777 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
778 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
779 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
781 /*_______________D3DXVec2Minimize__________________________*/
782 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
783 D3DXVec2Minimize(&gotvec,&u,&v);
784 expect_vec(expectedvec,gotvec);
785 /* Tests the case NULL */
786 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
787 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
788 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
789 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
791 /*_______________D3DXVec2Normalize_________________________*/
792 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
793 D3DXVec2Normalize(&gotvec,&u);
794 expect_vec(expectedvec,gotvec);
795 /* Test the nul vector */
796 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
797 D3DXVec2Normalize(&gotvec,&nul);
798 expect_vec(expectedvec,gotvec);
800 /*_______________D3DXVec2Scale____________________________*/
801 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
802 D3DXVec2Scale(&gotvec,&u,scale);
803 expect_vec(expectedvec,gotvec);
804 /* Tests the case NULL */
805 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
806 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
807 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
808 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
810 /*_______________D3DXVec2Subtract__________________________*/
811 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
812 D3DXVec2Subtract(&gotvec,&u,&v);
813 expect_vec(expectedvec,gotvec);
814 /* Tests the case NULL */
815 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
816 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
817 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
818 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
820 /*_______________D3DXVec2Transform_______________________*/
821 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
822 D3DXVec2Transform(&gottrans,&u,&mat);
823 expect_vec4(expectedtrans,gottrans);
825 /*_______________D3DXVec2TransformCoord_______________________*/
826 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
827 D3DXVec2TransformCoord(&gotvec,&u,&mat);
828 expect_vec(expectedvec,gotvec);
829 /* Test the nul projected vector */
830 nulproj.x = -2.0f; nulproj.y = -1.0f;
831 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
832 D3DXVec2TransformCoord(&gotvec,&nulproj,&mat);
833 expect_vec(expectedvec,gotvec);
835 /*_______________D3DXVec2TransformNormal______________________*/
836 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
837 D3DXVec2TransformNormal(&gotvec,&u,&mat);
838 expect_vec(expectedvec,gotvec);
841 static void D3X8Vector3Test(void)
843 D3DVIEWPORT8 viewport;
844 D3DXVECTOR3 expectedvec, gotvec, nul, nulproj, u, v, w, x;
845 LPD3DXVECTOR3 funcpointer;
846 D3DXVECTOR4 expectedtrans, gottrans;
847 D3DXMATRIX mat, projection, view, world;
848 FLOAT coeff1, coeff2, expected, got, scale;
850 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
851 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
852 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
853 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
854 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
856 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
857 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
859 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;
860 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;
861 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;
862 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;
864 view.m[0][1] = 5.0f; view.m[0][2] = 7.0f; view.m[0][3] = 8.0f;
865 view.m[1][0] = 11.0f; view.m[1][2] = 16.0f; view.m[1][3] = 33.0f;
866 view.m[2][0] = 19.0f; view.m[2][1] = -21.0f; view.m[2][3] = 43.0f;
867 view.m[3][0] = 2.0f; view.m[3][1] = 3.0f; view.m[3][2] = -4.0f;
868 view.m[0][0] = 10.0f; view.m[1][1] = 20.0f; view.m[2][2] = 30.0f;
869 view.m[3][3] = -40.0f;
871 world.m[0][0] = 21.0f; world.m[0][1] = 2.0f; world.m[0][2] = 3.0f; world.m[0][3] = 4.0;
872 world.m[1][0] = 5.0f; world.m[1][1] = 23.0f; world.m[1][2] = 7.0f; world.m[1][3] = 8.0f;
873 world.m[2][0] = -8.0f; world.m[2][1] = -7.0f; world.m[2][2] = 25.0f; world.m[2][3] = -5.0f;
874 world.m[3][0] = -4.0f; world.m[3][1] = -3.0f; world.m[3][2] = -2.0f; world.m[3][3] = 27.0f;
876 coeff1 = 2.0f; coeff2 = 5.0f;
877 scale = -6.5f;
879 /*_______________D3DXVec3Add__________________________*/
880 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
881 D3DXVec3Add(&gotvec,&u,&v);
882 expect_vec3(expectedvec,gotvec);
883 /* Tests the case NULL */
884 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
885 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
886 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
887 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
889 /*_______________D3DXVec3BaryCentric___________________*/
890 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
891 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
893 expect_vec3(expectedvec,gotvec);
895 /*_______________D3DXVec3CatmullRom____________________*/
896 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
897 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
898 expect_vec3(expectedvec,gotvec);
900 /*_______________D3DXVec3Cross________________________*/
901 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
902 D3DXVec3Cross(&gotvec,&u,&v);
903 expect_vec3(expectedvec,gotvec);
904 /* Tests the case NULL */
905 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
906 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
907 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
908 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
910 /*_______________D3DXVec3Dot__________________________*/
911 expected = -8.0f;
912 got = D3DXVec3Dot(&u,&v);
913 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
914 /* Tests the case NULL */
915 expected=0.0f;
916 got = D3DXVec3Dot(NULL,&v);
917 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
918 expected=0.0f;
919 got = D3DXVec3Dot(NULL,NULL);
920 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
922 /*_______________D3DXVec3Hermite__________________________*/
923 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
924 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
925 expect_vec3(expectedvec,gotvec);
927 /*_______________D3DXVec3Length__________________________*/
928 expected = 11.0f;
929 got = D3DXVec3Length(&u);
930 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
931 /* Tests the case NULL */
932 expected=0.0f;
933 got = D3DXVec3Length(NULL);
934 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
936 /*_______________D3DXVec3LengthSq________________________*/
937 expected = 121.0f;
938 got = D3DXVec3LengthSq(&u);
939 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
940 /* Tests the case NULL */
941 expected=0.0f;
942 got = D3DXVec3LengthSq(NULL);
943 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
945 /*_______________D3DXVec3Lerp__________________________*/
946 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
947 D3DXVec3Lerp(&gotvec,&u,&v,scale);
948 expect_vec3(expectedvec,gotvec);
949 /* Tests the case NULL */
950 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
951 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
952 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
953 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
955 /*_______________D3DXVec3Maximize__________________________*/
956 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
957 D3DXVec3Maximize(&gotvec,&u,&v);
958 expect_vec3(expectedvec,gotvec);
959 /* Tests the case NULL */
960 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
961 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
962 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
963 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
965 /*_______________D3DXVec3Minimize__________________________*/
966 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
967 D3DXVec3Minimize(&gotvec,&u,&v);
968 expect_vec3(expectedvec,gotvec);
969 /* Tests the case NULL */
970 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
971 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
972 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
973 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
975 /*_______________D3DXVec3Normalize_________________________*/
976 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
977 D3DXVec3Normalize(&gotvec,&u);
978 expect_vec3(expectedvec,gotvec);
979 /* Test the nul vector */
980 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
981 D3DXVec3Normalize(&gotvec,&nul);
982 expect_vec3(expectedvec,gotvec);
984 /*_______________D3DXVec3Project_________________________*/
985 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
986 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
987 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
988 expect_vec3(expectedvec,gotvec);
990 /*_______________D3DXVec3Scale____________________________*/
991 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
992 D3DXVec3Scale(&gotvec,&u,scale);
993 expect_vec3(expectedvec,gotvec);
994 /* Tests the case NULL */
995 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
996 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
997 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
998 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1000 /*_______________D3DXVec3Subtract_______________________*/
1001 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
1002 D3DXVec3Subtract(&gotvec,&u,&v);
1003 expect_vec3(expectedvec,gotvec);
1004 /* Tests the case NULL */
1005 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
1006 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1007 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
1008 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1010 /*_______________D3DXVec3Transform_______________________*/
1011 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
1012 D3DXVec3Transform(&gottrans,&u,&mat);
1013 expect_vec4(expectedtrans,gottrans);
1015 /*_______________D3DXVec3TransformCoord_______________________*/
1016 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
1017 D3DXVec3TransformCoord(&gotvec,&u,&mat);
1018 expect_vec3(expectedvec,gotvec);
1019 /* Test the nul projected vector */
1020 nulproj.x = 1.0f; nulproj.y = -1.0f, nulproj.z = -1.0f;
1021 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
1022 D3DXVec3TransformCoord(&gotvec,&nulproj,&mat);
1023 expect_vec3(expectedvec,gotvec);
1025 /*_______________D3DXVec3TransformNormal______________________*/
1026 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
1027 D3DXVec3TransformNormal(&gotvec,&u,&mat);
1028 expect_vec3(expectedvec,gotvec);
1030 /*_______________D3DXVec3Unproject_________________________*/
1031 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
1032 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
1033 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
1034 expect_vec3(expectedvec,gotvec);
1037 static void D3X8Vector4Test(void)
1039 D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x;
1040 LPD3DXVECTOR4 funcpointer;
1041 D3DXVECTOR4 expectedtrans, gottrans;
1042 D3DXMATRIX mat;
1043 FLOAT coeff1, coeff2, expected, got, scale;
1045 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
1046 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
1047 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
1048 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
1049 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
1051 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;
1052 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;
1053 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;
1054 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;
1056 coeff1 = 2.0f; coeff2 = 5.0;
1057 scale = -6.5f;
1059 /*_______________D3DXVec4Add__________________________*/
1060 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
1061 D3DXVec4Add(&gotvec,&u,&v);
1062 expect_vec4(expectedvec,gotvec);
1063 /* Tests the case NULL */
1064 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
1065 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1066 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
1067 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1069 /*_______________D3DXVec4BaryCentric____________________*/
1070 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
1071 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
1072 expect_vec4(expectedvec,gotvec);
1074 /*_______________D3DXVec4CatmullRom____________________*/
1075 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
1076 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
1077 expect_vec4(expectedvec,gotvec);
1079 /*_______________D3DXVec4Cross_________________________*/
1080 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
1081 D3DXVec4Cross(&gotvec,&u,&v,&w);
1082 expect_vec4(expectedvec,gotvec);
1084 /*_______________D3DXVec4Dot__________________________*/
1085 expected = 55.0f;
1086 got = D3DXVec4Dot(&u,&v);
1087 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1088 /* Tests the case NULL */
1089 expected=0.0f;
1090 got = D3DXVec4Dot(NULL,&v);
1091 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1092 expected=0.0f;
1093 got = D3DXVec4Dot(NULL,NULL);
1094 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1096 /*_______________D3DXVec4Hermite_________________________*/
1097 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
1098 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
1099 expect_vec4(expectedvec,gotvec);
1101 /*_______________D3DXVec4Length__________________________*/
1102 expected = 11.0f;
1103 got = D3DXVec4Length(&u);
1104 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1105 /* Tests the case NULL */
1106 expected=0.0f;
1107 got = D3DXVec4Length(NULL);
1108 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1110 /*_______________D3DXVec4LengthSq________________________*/
1111 expected = 121.0f;
1112 got = D3DXVec4LengthSq(&u);
1113 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1114 /* Tests the case NULL */
1115 expected=0.0f;
1116 got = D3DXVec4LengthSq(NULL);
1117 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1119 /*_______________D3DXVec4Lerp__________________________*/
1120 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1121 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1122 expect_vec4(expectedvec,gotvec);
1123 /* Tests the case NULL */
1124 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1125 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1126 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1127 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1129 /*_______________D3DXVec4Maximize__________________________*/
1130 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1131 D3DXVec4Maximize(&gotvec,&u,&v);
1132 expect_vec4(expectedvec,gotvec);
1133 /* Tests the case NULL */
1134 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1135 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1136 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1137 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1139 /*_______________D3DXVec4Minimize__________________________*/
1140 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1141 D3DXVec4Minimize(&gotvec,&u,&v);
1142 expect_vec4(expectedvec,gotvec);
1143 /* Tests the case NULL */
1144 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1145 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1146 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1147 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1149 /*_______________D3DXVec4Normalize_________________________*/
1150 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1151 D3DXVec4Normalize(&gotvec,&u);
1152 expect_vec4(expectedvec,gotvec);
1153 /* Test the nul vector */
1154 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expectedvec.w = 0.0f;
1155 D3DXVec4Normalize(&gotvec,&nul);
1156 expect_vec4(expectedvec,gotvec);
1158 /*_______________D3DXVec4Scale____________________________*/
1159 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1160 D3DXVec4Scale(&gotvec,&u,scale);
1161 expect_vec4(expectedvec,gotvec);
1162 /* Tests the case NULL */
1163 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1164 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1165 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1166 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1168 /*_______________D3DXVec4Subtract__________________________*/
1169 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1170 D3DXVec4Subtract(&gotvec,&u,&v);
1171 expect_vec4(expectedvec,gotvec);
1172 /* Tests the case NULL */
1173 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1174 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1175 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1176 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1178 /*_______________D3DXVec4Transform_______________________*/
1179 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1180 D3DXVec4Transform(&gottrans,&u,&mat);
1181 expect_vec4(expectedtrans,gottrans);
1184 START_TEST(math)
1186 D3DXColorTest();
1187 D3DXMatrixTest();
1188 D3DXPlaneTest();
1189 D3X8QuaternionTest();
1190 D3X8Vector2Test();
1191 D3X8Vector3Test();
1192 D3X8Vector4Test();