push ac694015ba9a1d7cf8fc6346c6e51d4c35a62962
[wine/hacks.git] / dlls / d3dx8 / tests / mesh.c
blob04e8bf2e32576c8dd7f977f6415c630ce6b4d8b2
1 /*
2 * Copyright 2008 David Adam
3 * Copyright 2008 Luis Busquets
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "d3dx8.h"
22 #include "wine/test.h"
24 #define admitted_error 0.0001f
26 #define compare_vertex_sizes(type, exp) \
27 got=D3DXGetFVFVertexSize(type); \
28 ok(got==exp, "Expected: %d, Got: %d\n", exp, got);
30 static BOOL compare(FLOAT u, FLOAT v)
32 return (fabs(u-v) < admitted_error);
35 static BOOL compare_vec3(D3DXVECTOR3 u, D3DXVECTOR3 v)
37 return ( compare(u.x, v.x) && compare(u.y, v.y) && compare(u.z, v.z) );
40 static void D3DXBoundProbeTest(void)
42 BOOL result;
43 D3DXVECTOR3 bottom_point, center, top_point, raydirection, rayposition;
44 FLOAT radius;
46 /*____________Test the Box case___________________________*/
47 bottom_point.x = -3.0f; bottom_point.y = -2.0f; bottom_point.z = -1.0f;
48 top_point.x = 7.0f; top_point.y = 8.0f; top_point.z = 9.0f;
50 raydirection.x = -4.0f; raydirection.y = -5.0f; raydirection.z = -6.0f;
51 rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
52 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
53 ok(result == TRUE, "expected TRUE, received FALSE\n");
55 raydirection.x = 4.0f; raydirection.y = 5.0f; raydirection.z = 6.0f;
56 rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
57 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
58 ok(result == FALSE, "expected FALSE, received TRUE\n");
60 rayposition.x = -4.0f; rayposition.y = 1.0f; rayposition.z = -2.0f;
61 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
62 ok(result == TRUE, "expected TRUE, received FALSE\n");
64 bottom_point.x = 1.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
65 top_point.x = 1.0f; top_point.y = 0.0f; top_point.z = 0.0f;
66 rayposition.x = 0.0f; rayposition.y = 1.0f; rayposition.z = 0.0f;
67 raydirection.x = 0.0f; raydirection.y = 3.0f; raydirection.z = 0.0f;
68 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
69 ok(result == FALSE, "expected FALSE, received TRUE\n");
71 bottom_point.x = 1.0f; bottom_point.y = 2.0f; bottom_point.z = 3.0f;
72 top_point.x = 10.0f; top_point.y = 15.0f; top_point.z = 20.0f;
74 raydirection.x = 7.0f; raydirection.y = 8.0f; raydirection.z = 9.0f;
75 rayposition.x = 3.0f; rayposition.y = 7.0f; rayposition.z = -6.0f;
76 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
77 ok(result == TRUE, "expected TRUE, received FALSE\n");
79 bottom_point.x = 0.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
80 top_point.x = 1.0f; top_point.y = 1.0f; top_point.z = 1.0f;
82 raydirection.x = 0.0f; raydirection.y = 1.0f; raydirection.z = .0f;
83 rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
84 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
85 ok(result == FALSE, "expected FALSE, received TRUE\n");
87 raydirection.x = 1.0f; raydirection.y = 0.0f; raydirection.z = .0f;
88 rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
89 result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
90 ok(result == TRUE, "expected TRUE, received FALSE\n");
92 /*____________Test the Sphere case________________________*/
93 radius = sqrt(77.0f);
94 center.x = 1.0f; center.y = 2.0f; center.z = 3.0f;
95 raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f;
97 rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f;
98 result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
99 ok(result == TRUE, "expected TRUE, received FALSE\n");
101 rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f;
102 result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
103 ok(result == FALSE, "expected FALSE, received TRUE\n");
105 rayposition.x = 5.0f; rayposition.y = 7.0f; rayposition.z = 9.0f;
106 result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
107 ok(result == FALSE, "expected FALSE, received TRUE\n");
109 rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f;
110 result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
111 ok(result == FALSE, "expected FALSE, received TRUE\n");
114 static void D3DXComputeBoundingBoxTest(void)
116 D3DXVECTOR3 exp_max, exp_min, got_max, got_min, vertex[5];
117 HRESULT hr;
119 vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
120 vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
121 vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
122 vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
123 vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;
125 exp_min.x = 1.0f; exp_min.y = 1.0f; exp_min.z = 1.0f;
126 exp_max.x = 1.0f; exp_max.y = 1.0f; exp_max.z = 1.0f;
128 hr = D3DXComputeBoundingBox(&vertex[3],2,D3DFVF_XYZ,&got_min,&got_max);
130 ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
131 ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
132 ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
134 /*________________________*/
136 vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
137 vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
138 vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
139 vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
140 vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
142 exp_min.x = -6.92f; exp_min.y = -0.90f; exp_min.z = -3.80f;
143 exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;
145 hr = D3DXComputeBoundingBox(&vertex[0],5,D3DFVF_XYZ,&got_min,&got_max);
147 ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
148 ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
149 ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
151 /*________________________*/
153 vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
154 vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
155 vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
156 vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
157 vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
159 exp_min.x = -1.87f; exp_min.y = -0.90f; exp_min.z = -1.20f;
160 exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;
162 hr = D3DXComputeBoundingBox(&vertex[0],4,D3DFVF_XYZ,&got_min,&got_max);
164 ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
165 ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
166 ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
168 /*________________________*/
169 hr = D3DXComputeBoundingBox(NULL,5,D3DFVF_XYZ,&got_min,&got_max);
170 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
172 /*________________________*/
173 hr = D3DXComputeBoundingBox(&vertex[3],5,D3DFVF_XYZ,NULL,&got_max);
174 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
176 /*________________________*/
177 hr = D3DXComputeBoundingBox(&vertex[3],5,D3DFVF_XYZ,&got_min,NULL);
178 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
181 static void D3DXComputeBoundingSphereTest(void)
183 D3DXVECTOR3 exp_cen, got_cen, vertex[5];
184 FLOAT exp_rad, got_rad;
185 HRESULT hr;
187 vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
188 vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
189 vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
190 vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
191 vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;
193 exp_rad = 6.928203f;
194 exp_cen.x = 5.0; exp_cen.y = 5.0; exp_cen.z = 5.0;
196 hr = D3DXComputeBoundingSphere(&vertex[3],2,D3DFVF_XYZ,&got_cen,&got_rad);
198 ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
199 ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
200 ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);
202 /*________________________*/
204 vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
205 vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
206 vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
207 vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
208 vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
210 exp_rad = 13.707883f;
211 exp_cen.x = 2.408f; exp_cen.y = 2.22f; exp_cen.z = 3.76f;
213 hr = D3DXComputeBoundingSphere(&vertex[0],5,D3DFVF_XYZ,&got_cen,&got_rad);
215 ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
216 ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
217 ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);
219 /*________________________*/
220 hr = D3DXComputeBoundingSphere(NULL,5,D3DFVF_XYZ,&got_cen,&got_rad);
221 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
223 /*________________________*/
224 hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DFVF_XYZ,NULL,&got_rad);
225 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
227 /*________________________*/
228 hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DFVF_XYZ,&got_cen,NULL);
229 ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
232 static void D3DXGetFVFVertexSizeTest(void)
234 UINT got;
236 compare_vertex_sizes (D3DFVF_XYZ, 12);
238 compare_vertex_sizes (D3DFVF_XYZB3, 24);
240 compare_vertex_sizes (D3DFVF_XYZB5, 32);
242 compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_NORMAL, 24);
244 compare_vertex_sizes (D3DFVF_XYZ | D3DFVF_DIFFUSE, 16);
246 compare_vertex_sizes (
247 D3DFVF_XYZ |
248 D3DFVF_TEX1 |
249 D3DFVF_TEXCOORDSIZE1(0), 16);
250 compare_vertex_sizes (
251 D3DFVF_XYZ |
252 D3DFVF_TEX2 |
253 D3DFVF_TEXCOORDSIZE1(0) |
254 D3DFVF_TEXCOORDSIZE1(1), 20);
256 compare_vertex_sizes (
257 D3DFVF_XYZ |
258 D3DFVF_TEX1 |
259 D3DFVF_TEXCOORDSIZE2(0), 20);
261 compare_vertex_sizes (
262 D3DFVF_XYZ |
263 D3DFVF_TEX2 |
264 D3DFVF_TEXCOORDSIZE2(0) |
265 D3DFVF_TEXCOORDSIZE2(1), 28);
267 compare_vertex_sizes (
268 D3DFVF_XYZ |
269 D3DFVF_TEX6 |
270 D3DFVF_TEXCOORDSIZE2(0) |
271 D3DFVF_TEXCOORDSIZE2(1) |
272 D3DFVF_TEXCOORDSIZE2(2) |
273 D3DFVF_TEXCOORDSIZE2(3) |
274 D3DFVF_TEXCOORDSIZE2(4) |
275 D3DFVF_TEXCOORDSIZE2(5), 60);
277 compare_vertex_sizes (
278 D3DFVF_XYZ |
279 D3DFVF_TEX8 |
280 D3DFVF_TEXCOORDSIZE2(0) |
281 D3DFVF_TEXCOORDSIZE2(1) |
282 D3DFVF_TEXCOORDSIZE2(2) |
283 D3DFVF_TEXCOORDSIZE2(3) |
284 D3DFVF_TEXCOORDSIZE2(4) |
285 D3DFVF_TEXCOORDSIZE2(5) |
286 D3DFVF_TEXCOORDSIZE2(6) |
287 D3DFVF_TEXCOORDSIZE2(7), 76);
289 compare_vertex_sizes (
290 D3DFVF_XYZ |
291 D3DFVF_TEX1 |
292 D3DFVF_TEXCOORDSIZE3(0), 24);
294 compare_vertex_sizes (
295 D3DFVF_XYZ |
296 D3DFVF_TEX4 |
297 D3DFVF_TEXCOORDSIZE3(0) |
298 D3DFVF_TEXCOORDSIZE3(1) |
299 D3DFVF_TEXCOORDSIZE3(2) |
300 D3DFVF_TEXCOORDSIZE3(3), 60);
302 compare_vertex_sizes (
303 D3DFVF_XYZ |
304 D3DFVF_TEX1 |
305 D3DFVF_TEXCOORDSIZE4(0), 28);
307 compare_vertex_sizes (
308 D3DFVF_XYZ |
309 D3DFVF_TEX2 |
310 D3DFVF_TEXCOORDSIZE4(0) |
311 D3DFVF_TEXCOORDSIZE4(1), 44);
313 compare_vertex_sizes (
314 D3DFVF_XYZ |
315 D3DFVF_TEX3 |
316 D3DFVF_TEXCOORDSIZE4(0) |
317 D3DFVF_TEXCOORDSIZE4(1) |
318 D3DFVF_TEXCOORDSIZE4(2), 60);
320 compare_vertex_sizes (
321 D3DFVF_XYZB5 |
322 D3DFVF_NORMAL |
323 D3DFVF_DIFFUSE |
324 D3DFVF_SPECULAR |
325 D3DFVF_TEX8 |
326 D3DFVF_TEXCOORDSIZE4(0) |
327 D3DFVF_TEXCOORDSIZE4(1) |
328 D3DFVF_TEXCOORDSIZE4(2) |
329 D3DFVF_TEXCOORDSIZE4(3) |
330 D3DFVF_TEXCOORDSIZE4(4) |
331 D3DFVF_TEXCOORDSIZE4(5) |
332 D3DFVF_TEXCOORDSIZE4(6) |
333 D3DFVF_TEXCOORDSIZE4(7), 180);
336 static void D3DXIntersectTriTest(void)
338 BOOL exp_res, got_res;
339 D3DXVECTOR3 position, ray, vertex[3];
340 FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;
342 vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
343 vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
344 vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
346 position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;
348 ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
350 exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;
352 got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
353 ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
354 ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
355 ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
356 ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);
358 /*Only positive ray is taken in account*/
360 vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
361 vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
362 vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
364 position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;
366 ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
368 exp_res = FALSE;
370 got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
371 ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
373 /*Intersection between ray and triangle in a same plane is considered as empty*/
375 vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
376 vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
377 vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;
379 position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;
381 ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;
383 exp_res = FALSE;
385 got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
386 ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
389 START_TEST(mesh)
391 D3DXBoundProbeTest();
392 D3DXComputeBoundingBoxTest();
393 D3DXComputeBoundingSphereTest();
394 D3DXGetFVFVertexSizeTest();
395 D3DXIntersectTriTest();