d3dx8: Implement D3DXPlaneIntersectLine.
[wine/wine-kai.git] / dlls / d3dx8 / tests / math.c
blob526fc00cdc1e9bd5e8d61a42f64ab4cdbab5d36f
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;
70 scale = 0.3f;
72 /*_______________D3DXColorAdd________________*/
73 expected.r = 0.9f; expected.g = 1.05f; expected.b = 0.99f, expected.a = 0.93f;
74 D3DXColorAdd(&got,&color1,&color2);
75 expect_color(expected,got);
76 /* Test the NULL case */
77 funcpointer = D3DXColorAdd(&got,NULL,&color2);
78 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
79 funcpointer = D3DXColorAdd(NULL,NULL,&color2);
80 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
81 funcpointer = D3DXColorAdd(NULL,NULL,NULL);
82 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
84 /*_______________D3DXColorLerp________________*/
85 expected.r = 0.32f; expected.g = 0.69f; expected.b = 0.356f; expected.a = 0.897f;
86 D3DXColorLerp(&got,&color,&color1,scale);
87 expect_color(expected,got);
88 /* Test the NULL case */
89 funcpointer = D3DXColorLerp(&got,NULL,&color1,scale);
90 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
91 funcpointer = D3DXColorLerp(NULL,NULL,&color1,scale);
92 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
93 funcpointer = D3DXColorLerp(NULL,NULL,NULL,scale);
94 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
96 /*_______________D3DXColorModulate________________*/
97 expected.r = 0.18f; expected.g = 0.275f; expected.b = 0.1748f; expected.a = 0.0902f;
98 D3DXColorModulate(&got,&color1,&color2);
99 expect_color(expected,got);
100 /* Test the NULL case */
101 funcpointer = D3DXColorModulate(&got,NULL,&color2);
102 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
103 funcpointer = D3DXColorModulate(NULL,NULL,&color2);
104 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
105 funcpointer = D3DXColorModulate(NULL,NULL,NULL);
106 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
108 /*_______________D3DXColorNegative________________*/
109 expected.r = 0.8f; expected.g = 0.25f; expected.b = 0.59f; expected.a = 0.93f;
110 D3DXColorNegative(&got,&color);
111 expect_color(got,expected);
112 /* Test the greater than 1 case */
113 color1.r = 0.2f; color1.g = 1.75f; color1.b = 0.41f; color1.a = 0.93f;
114 expected.r = 0.8f; expected.g = -0.75f; expected.b = 0.59f; expected.a = 0.93f;
115 D3DXColorNegative(&got,&color1);
116 expect_color(got,expected);
117 /* Test the negative case */
118 color1.r = 0.2f; color1.g = -0.75f; color1.b = 0.41f; color1.a = 0.93f;
119 expected.r = 0.8f; expected.g = 1.75f; expected.b = 0.59f; expected.a = 0.93f;
120 D3DXColorNegative(&got,&color1);
121 expect_color(got,expected);
122 /* Test the NULL case */
123 funcpointer = D3DXColorNegative(&got,NULL);
124 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
125 funcpointer = D3DXColorNegative(NULL,NULL);
126 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
128 /*_______________D3DXColorScale________________*/
129 expected.r = 0.06f; expected.g = 0.225f; expected.b = 0.123f; expected.a = 0.279f;
130 D3DXColorScale(&got,&color,scale);
131 expect_color(expected,got);
132 /* Test the NULL case */
133 funcpointer = D3DXColorScale(&got,NULL,scale);
134 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
135 funcpointer = D3DXColorScale(NULL,NULL,scale);
136 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
138 /*_______________D3DXColorSubtract_______________*/
139 expected.r = -0.1f; expected.g = 0.25f; expected.b = -0.35f, expected.a = 0.82f;
140 D3DXColorSubtract(&got,&color,&color2);
141 expect_color(expected,got);
142 /* Test the NULL case */
143 funcpointer = D3DXColorSubtract(&got,NULL,&color2);
144 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
145 funcpointer = D3DXColorSubtract(NULL,NULL,&color2);
146 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
147 funcpointer = D3DXColorSubtract(NULL,NULL,NULL);
148 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
151 static void D3DXMatrixTest(void)
153 D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
154 LPD3DXMATRIX funcpointer;
155 D3DXQUATERNION q;
156 D3DXVECTOR3 at, axis, eye;
157 BOOL expected, got;
158 FLOAT angle, determinant, expectedfloat, gotfloat;
160 U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f;
161 U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f;
162 U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f;
163 U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f;
164 U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f;
165 U(mat).m[3][3] = -40.0f;
167 U(mat2).m[0][0] = 1.0f; U(mat2).m[1][0] = 2.0f; U(mat2).m[2][0] = 3.0f;
168 U(mat2).m[3][0] = 4.0f; U(mat2).m[0][1] = 5.0f; U(mat2).m[1][1] = 6.0f;
169 U(mat2).m[2][1] = 7.0f; U(mat2).m[3][1] = 8.0f; U(mat2).m[0][2] = -8.0f;
170 U(mat2).m[1][2] = -7.0f; U(mat2).m[2][2] = -6.0f; U(mat2).m[3][2] = -5.0f;
171 U(mat2).m[0][3] = -4.0f; U(mat2).m[1][3] = -3.0f; U(mat2).m[2][3] = -2.0f;
172 U(mat2).m[3][3] = -1.0f;
174 q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
176 at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
177 axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
178 eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
180 angle = D3DX_PI/3.0f;
182 /*____________D3DXMatrixAffineTransformation______*/
183 expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
184 expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
185 expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
186 expectedmat.m[3][0] = -1239.0f; expectedmat.m[3][1] = 667.0f; expectedmat.m[3][2] = 567.0f; expectedmat.m[3][3] = 1.0f;
187 D3DXMatrixAffineTransformation(&gotmat,3.56f,&at,&q,&axis);
188 expect_mat(expectedmat,gotmat);
189 /* Test the NULL case */
190 expectedmat.m[0][0] = -459.239990f; expectedmat.m[0][1] = -576.719971f; expectedmat.m[0][2] = -263.440002f; expectedmat.m[0][3] = 0.0f;
191 expectedmat.m[1][0] = 519.760010f; expectedmat.m[1][1] = -352.440002f; expectedmat.m[1][2] = -277.679993f; expectedmat.m[1][3] = 0.0f;
192 expectedmat.m[2][0] = 363.119995f; expectedmat.m[2][1] = -121.040001f; expectedmat.m[2][2] = -117.479996f; expectedmat.m[2][3] = 0.0f;
193 expectedmat.m[3][0] = 1.0f; expectedmat.m[3][1] = -3.0f; expectedmat.m[3][2] = 7.0f; expectedmat.m[3][3] = 1.0f;
194 D3DXMatrixAffineTransformation(&gotmat,3.56f,NULL,&q,&axis);
195 expect_mat(expectedmat,gotmat);
197 /*____________D3DXMatrixfDeterminant_____________*/
198 expectedfloat = -147888.0f;
199 gotfloat = D3DXMatrixfDeterminant(&mat);
200 ok(fabs( gotfloat - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, gotfloat);
202 /*____________D3DXMatrixInverse______________*/
203 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;
204 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;
205 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;
206 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;
207 expectedfloat = -147888.0f;
208 D3DXMatrixInverse(&gotmat,&determinant,&mat);
209 expect_mat(expectedmat,gotmat);
210 ok(fabs( determinant - expectedfloat ) < admitted_error, "Expected: %f, Got: %f\n", expectedfloat, determinant);
211 funcpointer = D3DXMatrixInverse(&gotmat,NULL,&mat2);
212 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
214 /*____________D3DXMatrixIsIdentity______________*/
215 expected = FALSE;
216 got = D3DXMatrixIsIdentity(&mat3);
217 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
218 D3DXMatrixIdentity(&mat3);
219 expected = TRUE;
220 got = D3DXMatrixIsIdentity(&mat3);
221 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
222 U(mat3).m[0][0] = 0.000009f;
223 expected = FALSE;
224 got = D3DXMatrixIsIdentity(&mat3);
225 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
226 /* Test the NULL case */
227 expected = FALSE;
228 got = D3DXMatrixIsIdentity(NULL);
229 ok(expected == got, "Expected : %d, Got : %d\n", expected, got);
231 /*____________D3DXMatrixLookatLH_______________*/
232 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;
233 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;
234 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;
235 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;
236 D3DXMatrixLookAtLH(&gotmat,&eye,&at,&axis);
237 expect_mat(expectedmat,gotmat);
239 /*____________D3DXMatrixLookatRH_______________*/
240 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;
241 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;
242 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;
243 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;
244 D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
245 expect_mat(expectedmat,gotmat);
247 /*____________D3DXMatrixMultiply______________*/
248 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;
249 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;
250 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;
251 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;
252 D3DXMatrixMultiply(&gotmat,&mat,&mat2);
253 expect_mat(expectedmat,gotmat);
255 /*____________D3DXMatrixMultiplyTranspose____*/
256 expectedmat.m[0][0] = 73.0f; expectedmat.m[0][1] = 231.0f; expectedmat.m[0][2] = 239.0f; expectedmat.m[0][3] = -164.0f;
257 expectedmat.m[1][0] = 193.0f; expectedmat.m[1][1] = 551.0f; expectedmat.m[1][2] = 523.0f; expectedmat.m[1][3] = -320.0;
258 expectedmat.m[2][0] = -197.0f; expectedmat.m[2][1] = -489.0f; expectedmat.m[2][2] = -400.0f; expectedmat.m[2][3] = 187.0f;
259 expectedmat.m[3][0] = -77.0f; expectedmat.m[3][1] = -169.0f; expectedmat.m[3][2] = -116.0f; expectedmat.m[3][3] = 31.0f;
260 D3DXMatrixMultiplyTranspose(&gotmat,&mat,&mat2);
261 expect_mat(expectedmat,gotmat);
263 /*____________D3DXMatrixOrthoLH_______________*/
264 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;
265 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;
266 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;
267 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;
268 D3DXMatrixOrthoLH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
269 expect_mat(expectedmat,gotmat);
271 /*____________D3DXMatrixOrthoOffCenterLH_______________*/
272 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;
273 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;
274 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;
275 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;
276 D3DXMatrixOrthoOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
277 expect_mat(expectedmat,gotmat);
279 /*____________D3DXMatrixOrthoOffCenterRH_______________*/
280 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;
281 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;
282 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;
283 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;
284 D3DXMatrixOrthoOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 9.3, -12.6);
285 expect_mat(expectedmat,gotmat);
287 /*____________D3DXMatrixOrthoRH_______________*/
288 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;
289 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;
290 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;
291 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;
292 D3DXMatrixOrthoRH(&gotmat, 2.5f, 7.4f, -3.2f, -9.8f);
293 expect_mat(expectedmat,gotmat);
295 /*____________D3DXMatrixPerspectiveFovLH_______________*/
296 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;
297 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;
298 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;
299 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;
300 D3DXMatrixPerspectiveFovLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
301 expect_mat(expectedmat,gotmat);
303 /*____________D3DXMatrixPerspectiveFovRH_______________*/
304 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;
305 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;
306 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;
307 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;
308 D3DXMatrixPerspectiveFovRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
309 expect_mat(expectedmat,gotmat);
311 /*____________D3DXMatrixPerspectiveLH_______________*/
312 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;
313 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;
314 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;
315 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;
316 D3DXMatrixPerspectiveLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
317 expect_mat(expectedmat,gotmat);
319 /*____________D3DXMatrixPerspectiveOffCenterLH_______________*/
320 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;
321 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;
322 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;
323 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;
324 D3DXMatrixPerspectiveOffCenterLH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
325 expect_mat(expectedmat,gotmat);
327 /*____________D3DXMatrixPerspectiveOffCenterRH_______________*/
328 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;
329 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;
330 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;
331 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;
332 D3DXMatrixPerspectiveOffCenterRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f, 3.2f, -16.9f);
333 expect_mat(expectedmat,gotmat);
335 /*____________D3DXMatrixPerspectiveRH_______________*/
336 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;
337 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;
338 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;
339 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;
340 D3DXMatrixPerspectiveRH(&gotmat, 0.2f, 0.75f, -2.4f, 8.7f);
341 expect_mat(expectedmat,gotmat);
343 /*____________D3DXMatrixRotationAxis_____*/
344 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;
345 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;
346 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;
347 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;
348 D3DXMatrixRotationAxis(&gotmat,&axis,angle);
349 expect_mat(expectedmat,gotmat);
351 /*____________D3DXMatrixRotationQuaternion______________*/
352 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;
353 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;
354 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;
355 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;
356 D3DXMatrixRotationQuaternion(&gotmat,&q);
357 expect_mat(expectedmat,gotmat);
359 /*____________D3DXMatrixRotationX______________*/
360 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;
361 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;
362 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;
363 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;
364 D3DXMatrixRotationX(&gotmat,angle);
365 expect_mat(expectedmat,gotmat);
367 /*____________D3DXMatrixRotationY______________*/
368 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;
369 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;
370 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;
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 D3DXMatrixRotationY(&gotmat,angle);
373 expect_mat(expectedmat,gotmat);
375 /*____________D3DXMatrixRotationYawPitchRoll____*/
376 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;
377 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;
378 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;
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 D3DXMatrixRotationYawPitchRoll(&gotmat, 3.0f*angle/5.0f, angle, 3.0f*angle/17.0f);
381 expect_mat(expectedmat,gotmat);
383 /*____________D3DXMatrixRotationZ______________*/
384 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;
385 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;
386 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;
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 D3DXMatrixRotationZ(&gotmat,angle);
389 expect_mat(expectedmat,gotmat);
391 /*____________D3DXMatrixScaling______________*/
392 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;
393 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;
394 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;
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 D3DXMatrixScaling(&gotmat,0.69f,0.53f,4.11f);
397 expect_mat(expectedmat,gotmat);
399 /*____________D3DXMatrixTranslation______________*/
400 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;
401 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;
402 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;
403 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;
404 D3DXMatrixTranslation(&gotmat,0.69f,0.53f,4.11f);
405 expect_mat(expectedmat,gotmat);
407 /*____________D3DXMatrixTranspose______________*/
408 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;
409 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;
410 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;
411 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;
412 D3DXMatrixTranspose(&gotmat,&mat);
413 expect_mat(expectedmat,gotmat);
416 static void D3DXPlaneTest(void)
418 D3DXPLANE expectedplane, gotplane, nulplane, plane;
419 D3DXVECTOR3 expectedvec, gotvec, vec1, vec2;
420 LPD3DXVECTOR3 funcpointer;
421 D3DXVECTOR4 vec;
422 FLOAT expected, got;
424 plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
425 vec.x = 2.0f; vec.y = 5.0f; vec.z = -6.0f; vec.w = 11.0f;
427 /*_______________D3DXPlaneDot________________*/
428 expected = 42.0f;
429 got = D3DXPlaneDot(&plane,&vec),
430 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
431 expected = 0.0f;
432 got = D3DXPlaneDot(NULL,&vec),
433 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
434 expected = 0.0f;
435 got = D3DXPlaneDot(NULL,NULL),
436 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
438 /*_______________D3DXPlaneDotCoord________________*/
439 expected = -28.0f;
440 got = D3DXPlaneDotCoord(&plane,&vec),
441 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
442 expected = 0.0f;
443 got = D3DXPlaneDotCoord(NULL,&vec),
444 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
445 expected = 0.0f;
446 got = D3DXPlaneDotCoord(NULL,NULL),
447 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
449 /*_______________D3DXPlaneDotNormal______________*/
450 expected = -35.0f;
451 got = D3DXPlaneDotNormal(&plane,&vec),
452 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
453 expected = 0.0f;
454 got = D3DXPlaneDotNormal(NULL,&vec),
455 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
456 expected = 0.0f;
457 got = D3DXPlaneDotNormal(NULL,NULL),
458 ok( expected == got, "Expected : %f, Got : %f\n",expected, got);
460 /*_______________D3DXPlaneIntersectLine___________*/
461 vec1.x = 9.0f; vec1.y = 6.0f; vec1.z = 3.0f;
462 vec2.x = 2.0f; vec2.y = 5.0f; vec2.z = 8.0f;
463 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
464 D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
465 expect_vec3(expectedvec, gotvec);
466 /* Test a parallele line */
467 vec1.x = 11.0f; vec1.y = 13.0f; vec1.z = 15.0f;
468 vec2.x = 17.0f; vec2.y = 31.0f; vec2.z = 24.0f;
469 expectedvec.x = 20.0f/3.0f; expectedvec.y = 17.0f/3.0f; expectedvec.z = 14.0f/3.0f;
470 funcpointer = D3DXPlaneIntersectLine(&gotvec,&plane,&vec1,&vec2);
471 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
473 /*_______________D3DXPlaneNormalize______________*/
474 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);
475 D3DXPlaneNormalize(&gotplane, &plane);
476 expect_plane(expectedplane, gotplane);
477 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 0.0f;
478 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
479 D3DXPlaneNormalize(&gotplane, &nulplane);
480 expect_plane(expectedplane, gotplane);
481 nulplane.a = 0.0; nulplane.b = 0.0f, nulplane.c = 0.0f; nulplane.d = 4.3f;
482 expectedplane.a = 0.0f; expectedplane.b = 0.0f; expectedplane.c = 0.0f; expectedplane.d = 0.0f;
483 D3DXPlaneNormalize(&gotplane, &nulplane);
484 expect_plane(expectedplane, gotplane);
487 static void D3X8QuaternionTest(void)
489 D3DXQUATERNION expectedquat, gotquat, nul, q, r, s;
490 LPD3DXQUATERNION funcpointer;
491 FLOAT expected, got;
492 BOOL expectedbool, gotbool;
494 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
495 q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
496 r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
498 /*_______________D3DXQuaternionConjugate________________*/
499 expectedquat.x = -1.0f; expectedquat.y = -2.0f; expectedquat.z = -4.0f; expectedquat.w = 10.0f;
500 D3DXQuaternionConjugate(&gotquat,&q);
501 expect_vec4(expectedquat,gotquat);
502 /* Test the NULL case */
503 funcpointer = D3DXQuaternionConjugate(&gotquat,NULL);
504 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
505 funcpointer = D3DXQuaternionConjugate(NULL,NULL);
506 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
508 /*_______________D3DXQuaternionDot______________________*/
509 expected = 55.0f;
510 got = D3DXQuaternionDot(&q,&r);
511 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
512 /* Tests the case NULL */
513 expected=0.0f;
514 got = D3DXQuaternionDot(NULL,&r);
515 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
516 expected=0.0f;
517 got = D3DXQuaternionDot(NULL,NULL);
518 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
520 /*_______________D3DXQuaternionIdentity________________*/
521 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 1.0f;
522 D3DXQuaternionIdentity(&gotquat);
523 expect_vec4(expectedquat,gotquat);
524 /* Test the NULL case */
525 funcpointer = D3DXQuaternionIdentity(NULL);
526 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
528 /*_______________D3DXQuaternionIsIdentity________________*/
529 s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
530 expectedbool = TRUE;
531 gotbool = D3DXQuaternionIsIdentity(&s);
532 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
533 s.x = 2.3f; s.y = -4.2f; s.z = 1.2f; s.w=0.2f;
534 expectedbool = FALSE;
535 gotbool = D3DXQuaternionIsIdentity(&q);
536 ok( expectedbool == gotbool, "Expected boolean : %d, Got bool : %d\n", expectedbool, gotbool);
537 /* Test the NULL case */
538 gotbool = D3DXQuaternionIsIdentity(NULL);
539 ok(gotbool == FALSE, "Expected boolean: %d, Got boolean: %d\n", FALSE, gotbool);
541 /*_______________D3DXQuaternionLength__________________________*/
542 expected = 11.0f;
543 got = D3DXQuaternionLength(&q);
544 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
545 /* Tests the case NULL */
546 expected=0.0f;
547 got = D3DXQuaternionLength(NULL);
548 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
550 /*_______________D3DXQuaternionLengthSq________________________*/
551 expected = 121.0f;
552 got = D3DXQuaternionLengthSq(&q);
553 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
554 /* Tests the case NULL */
555 expected=0.0f;
556 got = D3DXQuaternionLengthSq(NULL);
557 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
559 /*_______________D3DXQuaternionNormalize________________________*/
560 expectedquat.x = 1.0f/11.0f; expectedquat.y = 2.0f/11.0f; expectedquat.z = 4.0f/11.0f; expectedquat.w = 10.0f/11.0f;
561 D3DXQuaternionNormalize(&gotquat,&q);
562 expect_vec4(expectedquat,gotquat);
563 /* Test the nul quaternion */
564 expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
565 D3DXQuaternionNormalize(&gotquat,&nul);
566 expect_vec4(expectedquat,gotquat);
569 static void D3X8Vector2Test(void)
571 D3DXVECTOR2 expectedvec, gotvec, nul, nulproj, u, v, w, x;
572 LPD3DXVECTOR2 funcpointer;
573 D3DXVECTOR4 expectedtrans, gottrans;
574 D3DXMATRIX mat;
575 FLOAT coeff1, coeff2, expected, got, scale;
577 nul.x = 0.0f; nul.y = 0.0f;
578 u.x = 3.0f; u.y = 4.0f;
579 v.x = -7.0f; v.y = 9.0f;
580 w.x = 4.0f; w.y = -3.0f;
581 x.x = 2.0f; x.y = -11.0f;
583 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;
584 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;
585 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;
586 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;
588 coeff1 = 2.0f; coeff2 = 5.0f;
589 scale = -6.5f;
591 /*_______________D3DXVec2Add__________________________*/
592 expectedvec.x = -4.0f; expectedvec.y = 13.0f;
593 D3DXVec2Add(&gotvec,&u,&v);
594 expect_vec(expectedvec,gotvec);
595 /* Tests the case NULL */
596 funcpointer = D3DXVec2Add(&gotvec,NULL,&v);
597 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
598 funcpointer = D3DXVec2Add(NULL,NULL,NULL);
599 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
601 /*_______________D3DXVec2BaryCentric___________________*/
602 expectedvec.x = -12.0f; expectedvec.y = -21.0f;
603 D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
604 expect_vec(expectedvec,gotvec);
606 /*_______________D3DXVec2CatmullRom____________________*/
607 expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f;
608 D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale);
609 expect_vec(expectedvec,gotvec);
611 /*_______________D3DXVec2CCW__________________________*/
612 expected = 55.0f;
613 got = D3DXVec2CCW(&u,&v);
614 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
615 /* Tests the case NULL */
616 expected=0.0f;
617 got = D3DXVec2CCW(NULL,&v);
618 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
619 expected=0.0f;
620 got = D3DXVec2CCW(NULL,NULL);
621 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
623 /*_______________D3DXVec2Dot__________________________*/
624 expected = 15.0f;
625 got = D3DXVec2Dot(&u,&v);
626 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
627 /* Tests the case NULL */
628 expected=0.0f;
629 got = D3DXVec2Dot(NULL,&v);
630 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
631 expected=0.0f;
632 got = D3DXVec2Dot(NULL,NULL);
633 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
635 /*_______________D3DXVec2Hermite__________________________*/
636 expectedvec.x = 2604.625f; expectedvec.y = -4533.0f;
637 D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale);
638 expect_vec(expectedvec,gotvec);
640 /*_______________D3DXVec2Length__________________________*/
641 expected = 5.0f;
642 got = D3DXVec2Length(&u);
643 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
644 /* Tests the case NULL */
645 expected=0.0f;
646 got = D3DXVec2Length(NULL);
647 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
649 /*_______________D3DXVec2LengthSq________________________*/
650 expected = 25.0f;
651 got = D3DXVec2LengthSq(&u);
652 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
653 /* Tests the case NULL */
654 expected=0.0f;
655 got = D3DXVec2LengthSq(NULL);
656 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
658 /*_______________D3DXVec2Lerp__________________________*/
659 expectedvec.x = 68.0f; expectedvec.y = -28.5f;
660 D3DXVec2Lerp(&gotvec,&u,&v,scale);
661 expect_vec(expectedvec,gotvec);
662 /* Tests the case NULL */
663 funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale);
664 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
665 funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale);
666 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
668 /*_______________D3DXVec2Maximize__________________________*/
669 expectedvec.x = 3.0f; expectedvec.y = 9.0f;
670 D3DXVec2Maximize(&gotvec,&u,&v);
671 expect_vec(expectedvec,gotvec);
672 /* Tests the case NULL */
673 funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v);
674 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
675 funcpointer = D3DXVec2Maximize(NULL,NULL,NULL);
676 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
678 /*_______________D3DXVec2Minimize__________________________*/
679 expectedvec.x = -7.0f; expectedvec.y = 4.0f;
680 D3DXVec2Minimize(&gotvec,&u,&v);
681 expect_vec(expectedvec,gotvec);
682 /* Tests the case NULL */
683 funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v);
684 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
685 funcpointer = D3DXVec2Minimize(NULL,NULL,NULL);
686 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
688 /*_______________D3DXVec2Normalize_________________________*/
689 expectedvec.x = 0.6f; expectedvec.y = 0.8f;
690 D3DXVec2Normalize(&gotvec,&u);
691 expect_vec(expectedvec,gotvec);
692 /* Test the nul vector */
693 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
694 D3DXVec2Normalize(&gotvec,&nul);
695 expect_vec(expectedvec,gotvec);
697 /*_______________D3DXVec2Scale____________________________*/
698 expectedvec.x = -19.5f; expectedvec.y = -26.0f;
699 D3DXVec2Scale(&gotvec,&u,scale);
700 expect_vec(expectedvec,gotvec);
701 /* Tests the case NULL */
702 funcpointer = D3DXVec2Scale(&gotvec,NULL,scale);
703 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
704 funcpointer = D3DXVec2Scale(NULL,NULL,scale);
705 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
707 /*_______________D3DXVec2Subtract__________________________*/
708 expectedvec.x = 10.0f; expectedvec.y = -5.0f;
709 D3DXVec2Subtract(&gotvec,&u,&v);
710 expect_vec(expectedvec,gotvec);
711 /* Tests the case NULL */
712 funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v);
713 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
714 funcpointer = D3DXVec2Subtract(NULL,NULL,NULL);
715 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
717 /*_______________D3DXVec2Transform_______________________*/
718 expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f;
719 D3DXVec2Transform(&gottrans,&u,&mat);
720 expect_vec4(expectedtrans,gottrans);
722 /*_______________D3DXVec2TransformCoord_______________________*/
723 expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f;
724 D3DXVec2TransformCoord(&gotvec,&u,&mat);
725 expect_vec(expectedvec,gotvec);
726 /* Test the nul projected vector */
727 nulproj.x = -2.0f; nulproj.y = -1.0f;
728 expectedvec.x = 0.0f; expectedvec.y = 0.0f;
729 D3DXVec2TransformCoord(&gotvec,&nulproj,&mat);
730 expect_vec(expectedvec,gotvec);
732 /*_______________D3DXVec2TransformNormal______________________*/
733 expectedvec.x = 23.0f; expectedvec.y = 30.0f;
734 D3DXVec2TransformNormal(&gotvec,&u,&mat);
735 expect_vec(expectedvec,gotvec);
738 static void D3X8Vector3Test(void)
740 D3DVIEWPORT8 viewport;
741 D3DXVECTOR3 expectedvec, gotvec, nul, nulproj, u, v, w, x;
742 LPD3DXVECTOR3 funcpointer;
743 D3DXVECTOR4 expectedtrans, gottrans;
744 D3DXMATRIX mat, projection, view, world;
745 FLOAT coeff1, coeff2, expected, got, scale;
747 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f;
748 u.x = 9.0f; u.y = 6.0f; u.z = 2.0f;
749 v.x = 2.0f; v.y = -3.0f; v.z = -4.0;
750 w.x = 3.0f; w.y = -5.0f; w.z = 7.0f;
751 x.x = 4.0f; x.y = 1.0f; x.z = 11.0f;
753 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
754 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
756 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;
757 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;
758 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;
759 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;
761 view.m[0][1] = 5.0f; view.m[0][2] = 7.0f; view.m[0][3] = 8.0f;
762 view.m[1][0] = 11.0f; view.m[1][2] = 16.0f; view.m[1][3] = 33.0f;
763 view.m[2][0] = 19.0f; view.m[2][1] = -21.0f; view.m[2][3] = 43.0f;
764 view.m[3][0] = 2.0f; view.m[3][1] = 3.0f; view.m[3][2] = -4.0f;
765 view.m[0][0] = 10.0f; view.m[1][1] = 20.0f; view.m[2][2] = 30.0f;
766 view.m[3][3] = -40.0f;
768 world.m[0][0] = 21.0f; world.m[0][1] = 2.0f; world.m[0][2] = 3.0f; world.m[0][3] = 4.0;
769 world.m[1][0] = 5.0f; world.m[1][1] = 23.0f; world.m[1][2] = 7.0f; world.m[1][3] = 8.0f;
770 world.m[2][0] = -8.0f; world.m[2][1] = -7.0f; world.m[2][2] = 25.0f; world.m[2][3] = -5.0f;
771 world.m[3][0] = -4.0f; world.m[3][1] = -3.0f; world.m[3][2] = -2.0f; world.m[3][3] = 27.0f;
773 coeff1 = 2.0f; coeff2 = 5.0f;
774 scale = -6.5f;
776 /*_______________D3DXVec3Add__________________________*/
777 expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f;
778 D3DXVec3Add(&gotvec,&u,&v);
779 expect_vec3(expectedvec,gotvec);
780 /* Tests the case NULL */
781 funcpointer = D3DXVec3Add(&gotvec,NULL,&v);
782 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
783 funcpointer = D3DXVec3Add(NULL,NULL,NULL);
784 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
786 /*_______________D3DXVec3BaryCentric___________________*/
787 expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f;
788 D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
790 expect_vec3(expectedvec,gotvec);
792 /*_______________D3DXVec3CatmullRom____________________*/
793 expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f;
794 D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale);
795 expect_vec3(expectedvec,gotvec);
797 /*_______________D3DXVec3Cross________________________*/
798 expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f;
799 D3DXVec3Cross(&gotvec,&u,&v);
800 expect_vec3(expectedvec,gotvec);
801 /* Tests the case NULL */
802 funcpointer = D3DXVec3Cross(&gotvec,NULL,&v);
803 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
804 funcpointer = D3DXVec3Cross(NULL,NULL,NULL);
805 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
807 /*_______________D3DXVec3Dot__________________________*/
808 expected = -8.0f;
809 got = D3DXVec3Dot(&u,&v);
810 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
811 /* Tests the case NULL */
812 expected=0.0f;
813 got = D3DXVec3Dot(NULL,&v);
814 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
815 expected=0.0f;
816 got = D3DXVec3Dot(NULL,NULL);
817 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
819 /*_______________D3DXVec3Hermite__________________________*/
820 expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f;
821 D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale);
822 expect_vec3(expectedvec,gotvec);
824 /*_______________D3DXVec3Length__________________________*/
825 expected = 11.0f;
826 got = D3DXVec3Length(&u);
827 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
828 /* Tests the case NULL */
829 expected=0.0f;
830 got = D3DXVec3Length(NULL);
831 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
833 /*_______________D3DXVec3LengthSq________________________*/
834 expected = 121.0f;
835 got = D3DXVec3LengthSq(&u);
836 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
837 /* Tests the case NULL */
838 expected=0.0f;
839 got = D3DXVec3LengthSq(NULL);
840 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
842 /*_______________D3DXVec3Lerp__________________________*/
843 expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ;
844 D3DXVec3Lerp(&gotvec,&u,&v,scale);
845 expect_vec3(expectedvec,gotvec);
846 /* Tests the case NULL */
847 funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale);
848 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
849 funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale);
850 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
852 /*_______________D3DXVec3Maximize__________________________*/
853 expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f;
854 D3DXVec3Maximize(&gotvec,&u,&v);
855 expect_vec3(expectedvec,gotvec);
856 /* Tests the case NULL */
857 funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v);
858 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
859 funcpointer = D3DXVec3Maximize(NULL,NULL,NULL);
860 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
862 /*_______________D3DXVec3Minimize__________________________*/
863 expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f;
864 D3DXVec3Minimize(&gotvec,&u,&v);
865 expect_vec3(expectedvec,gotvec);
866 /* Tests the case NULL */
867 funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v);
868 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
869 funcpointer = D3DXVec3Minimize(NULL,NULL,NULL);
870 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
872 /*_______________D3DXVec3Normalize_________________________*/
873 expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f;
874 D3DXVec3Normalize(&gotvec,&u);
875 expect_vec3(expectedvec,gotvec);
876 /* Test the nul vector */
877 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
878 D3DXVec3Normalize(&gotvec,&nul);
879 expect_vec3(expectedvec,gotvec);
881 /*_______________D3DXVec3Project_________________________*/
882 expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
883 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
884 D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
885 expect_vec3(expectedvec,gotvec);
887 /*_______________D3DXVec3Scale____________________________*/
888 expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
889 D3DXVec3Scale(&gotvec,&u,scale);
890 expect_vec3(expectedvec,gotvec);
891 /* Tests the case NULL */
892 funcpointer = D3DXVec3Scale(&gotvec,NULL,scale);
893 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
894 funcpointer = D3DXVec3Scale(NULL,NULL,scale);
895 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
897 /*_______________D3DXVec3Subtract_______________________*/
898 expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f;
899 D3DXVec3Subtract(&gotvec,&u,&v);
900 expect_vec3(expectedvec,gotvec);
901 /* Tests the case NULL */
902 funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v);
903 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
904 funcpointer = D3DXVec3Subtract(NULL,NULL,NULL);
905 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
907 /*_______________D3DXVec3Transform_______________________*/
908 expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f;
909 D3DXVec3Transform(&gottrans,&u,&mat);
910 expect_vec4(expectedtrans,gottrans);
912 /*_______________D3DXVec3TransformCoord_______________________*/
913 expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f;
914 D3DXVec3TransformCoord(&gotvec,&u,&mat);
915 expect_vec3(expectedvec,gotvec);
916 /* Test the nul projected vector */
917 nulproj.x = 1.0f; nulproj.y = -1.0f, nulproj.z = -1.0f;
918 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f;
919 D3DXVec3TransformCoord(&gotvec,&nulproj,&mat);
920 expect_vec3(expectedvec,gotvec);
922 /*_______________D3DXVec3TransformNormal______________________*/
923 expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f;
924 D3DXVec3TransformNormal(&gotvec,&u,&mat);
925 expect_vec3(expectedvec,gotvec);
927 /*_______________D3DXVec3Unproject_________________________*/
928 expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
929 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
930 D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world);
931 expect_vec3(expectedvec,gotvec);
934 static void D3X8Vector4Test(void)
936 D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x;
937 LPD3DXVECTOR4 funcpointer;
938 D3DXVECTOR4 expectedtrans, gottrans;
939 D3DXMATRIX mat;
940 FLOAT coeff1, coeff2, expected, got, scale;
942 nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
943 u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0;
944 v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0;
945 w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f;
946 x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f;
948 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;
949 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;
950 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;
951 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;
953 coeff1 = 2.0f; coeff2 = 5.0;
954 scale = -6.5f;
956 /*_______________D3DXVec4Add__________________________*/
957 expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f;
958 D3DXVec4Add(&gotvec,&u,&v);
959 expect_vec4(expectedvec,gotvec);
960 /* Tests the case NULL */
961 funcpointer = D3DXVec4Add(&gotvec,NULL,&v);
962 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
963 funcpointer = D3DXVec4Add(NULL,NULL,NULL);
964 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
966 /*_______________D3DXVec4BaryCentric____________________*/
967 expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f;
968 D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2);
969 expect_vec4(expectedvec,gotvec);
971 /*_______________D3DXVec4CatmullRom____________________*/
972 expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f;
973 D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale);
974 expect_vec4(expectedvec,gotvec);
976 /*_______________D3DXVec4Cross_________________________*/
977 expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f;
978 D3DXVec4Cross(&gotvec,&u,&v,&w);
979 expect_vec4(expectedvec,gotvec);
981 /*_______________D3DXVec4Dot__________________________*/
982 expected = 55.0f;
983 got = D3DXVec4Dot(&u,&v);
984 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
985 /* Tests the case NULL */
986 expected=0.0f;
987 got = D3DXVec4Dot(NULL,&v);
988 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
989 expected=0.0f;
990 got = D3DXVec4Dot(NULL,NULL);
991 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
993 /*_______________D3DXVec4Hermite_________________________*/
994 expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f;
995 D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale);
996 expect_vec4(expectedvec,gotvec);
998 /*_______________D3DXVec4Length__________________________*/
999 expected = 11.0f;
1000 got = D3DXVec4Length(&u);
1001 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1002 /* Tests the case NULL */
1003 expected=0.0f;
1004 got = D3DXVec4Length(NULL);
1005 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1007 /*_______________D3DXVec4LengthSq________________________*/
1008 expected = 121.0f;
1009 got = D3DXVec4LengthSq(&u);
1010 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1011 /* Tests the case NULL */
1012 expected=0.0f;
1013 got = D3DXVec4LengthSq(NULL);
1014 ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
1016 /*_______________D3DXVec4Lerp__________________________*/
1017 expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;
1018 D3DXVec4Lerp(&gotvec,&u,&v,scale);
1019 expect_vec4(expectedvec,gotvec);
1020 /* Tests the case NULL */
1021 funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale);
1022 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1023 funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale);
1024 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1026 /*_______________D3DXVec4Maximize__________________________*/
1027 expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0;
1028 D3DXVec4Maximize(&gotvec,&u,&v);
1029 expect_vec4(expectedvec,gotvec);
1030 /* Tests the case NULL */
1031 funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v);
1032 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1033 funcpointer = D3DXVec4Maximize(NULL,NULL,NULL);
1034 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1036 /*_______________D3DXVec4Minimize__________________________*/
1037 expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0;
1038 D3DXVec4Minimize(&gotvec,&u,&v);
1039 expect_vec4(expectedvec,gotvec);
1040 /* Tests the case NULL */
1041 funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v);
1042 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1043 funcpointer = D3DXVec4Minimize(NULL,NULL,NULL);
1044 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1046 /*_______________D3DXVec4Normalize_________________________*/
1047 expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f;
1048 D3DXVec4Normalize(&gotvec,&u);
1049 expect_vec4(expectedvec,gotvec);
1050 /* Test the nul vector */
1051 expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expectedvec.w = 0.0f;
1052 D3DXVec4Normalize(&gotvec,&nul);
1053 expect_vec4(expectedvec,gotvec);
1055 /*_______________D3DXVec4Scale____________________________*/
1056 expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f;
1057 D3DXVec4Scale(&gotvec,&u,scale);
1058 expect_vec4(expectedvec,gotvec);
1059 /* Tests the case NULL */
1060 funcpointer = D3DXVec4Scale(&gotvec,NULL,scale);
1061 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1062 funcpointer = D3DXVec4Scale(NULL,NULL,scale);
1063 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1065 /*_______________D3DXVec4Subtract__________________________*/
1066 expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f;
1067 D3DXVec4Subtract(&gotvec,&u,&v);
1068 expect_vec4(expectedvec,gotvec);
1069 /* Tests the case NULL */
1070 funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v);
1071 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1072 funcpointer = D3DXVec4Subtract(NULL,NULL,NULL);
1073 ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
1075 /*_______________D3DXVec4Transform_______________________*/
1076 expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f;
1077 D3DXVec4Transform(&gottrans,&u,&mat);
1078 expect_vec4(expectedtrans,gottrans);
1081 START_TEST(math)
1083 D3DXColorTest();
1084 D3DXMatrixTest();
1085 D3DXPlaneTest();
1086 D3X8QuaternionTest();
1087 D3X8Vector2Test();
1088 D3X8Vector3Test();
1089 D3X8Vector4Test();