mapi32/tests: Fix typo.
[wine] / dlls / d3dx8 / tests / mesh.c
1 /*
2  * Copyright 2008 David Adam
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "d3dx8.h"
20
21 #include "wine/test.h"
22
23 #define admitted_error 0.0001f
24
25 BOOL compare(FLOAT u, FLOAT v)
26 {
27     return (fabs(u-v) < admitted_error);
28 }
29
30 static void D3DXBoundProbeTest(void)
31 {
32     BOOL result;
33     D3DXVECTOR3 bottom_point, center, top_point, raydirection, rayposition;
34     FLOAT radius;
35
36 /*____________Test the Box case___________________________*/
37     bottom_point.x = -3.0f; bottom_point.y = -2.0f; bottom_point.z = -1.0f;
38     top_point.x = 7.0f; top_point.y = 8.0f; top_point.z = 9.0f;
39
40     raydirection.x = -4.0f; raydirection.y = -5.0f; raydirection.z = -6.0f;
41     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
42     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
43     ok(result == TRUE, "expected TRUE, received FALSE\n");
44
45     raydirection.x = 4.0f; raydirection.y = 5.0f; raydirection.z = 6.0f;
46     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
47     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
48     ok(result == FALSE, "expected FALSE, received TRUE\n");
49
50     rayposition.x = -4.0f; rayposition.y = 1.0f; rayposition.z = -2.0f;
51     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
52     ok(result == TRUE, "expected TRUE, received FALSE\n");
53
54     bottom_point.x = 1.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
55     top_point.x = 1.0f; top_point.y = 0.0f; top_point.z = 0.0f;
56     rayposition.x = 0.0f; rayposition.y = 1.0f; rayposition.z = 0.0f;
57     raydirection.x = 0.0f; raydirection.y = 3.0f; raydirection.z = 0.0f;
58     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
59     ok(result == FALSE, "expected FALSE, received TRUE\n");
60
61     bottom_point.x = 1.0f; bottom_point.y = 2.0f; bottom_point.z = 3.0f;
62     top_point.x = 10.0f; top_point.y = 15.0f; top_point.z = 20.0f;
63
64     raydirection.x = 7.0f; raydirection.y = 8.0f; raydirection.z = 9.0f;
65     rayposition.x = 3.0f; rayposition.y = 7.0f; rayposition.z = -6.0f;
66     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
67     ok(result == TRUE, "expected TRUE, received FALSE\n");
68
69     bottom_point.x = 0.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
70     top_point.x = 1.0f; top_point.y = 1.0f; top_point.z = 1.0f;
71
72     raydirection.x = 0.0f; raydirection.y = 1.0f; raydirection.z = .0f;
73     rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
74     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
75     ok(result == FALSE, "expected FALSE, received TRUE\n");
76
77     raydirection.x = 1.0f; raydirection.y = 0.0f; raydirection.z = .0f;
78     rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
79     result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
80     ok(result == TRUE, "expected TRUE, received FALSE\n");
81
82 /*____________Test the Sphere case________________________*/
83     radius = sqrt(77.0f);
84     center.x = 1.0f; center.y = 2.0f; center.z = 3.0f;
85     raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f;
86
87     rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f;
88     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
89     ok(result == TRUE, "expected TRUE, received FALSE\n");
90
91     rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f;
92     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
93     ok(result == FALSE, "expected FALSE, received TRUE\n");
94
95     rayposition.x = 5.0f; rayposition.y = 7.0f; rayposition.z = 9.0f;
96     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
97     ok(result == FALSE, "expected FALSE, received TRUE\n");
98
99     rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f;
100     result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
101     ok(result == FALSE, "expected FALSE, received TRUE\n");
102 }
103
104 static void D3DXIntersectTriTest(void)
105 {
106     BOOL exp_res, got_res;
107     D3DXVECTOR3 position, ray, vertex[3];
108     FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;
109
110     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
111     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
112     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
113
114     position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;
115
116     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
117
118     exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;
119
120     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
121     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
122     ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
123     ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
124     ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);
125
126 /*Only positive ray is taken in account*/
127
128     vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
129     vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
130     vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
131
132     position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;
133
134     ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
135
136     exp_res = FALSE;
137
138     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
139     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
140
141 /*Intersection between ray and triangle in a same plane is considered as empty*/
142
143     vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
144     vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
145     vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;
146
147     position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;
148
149     ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;
150
151     exp_res = FALSE;
152
153     got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
154     ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
155 }
156
157 START_TEST(mesh)
158 {
159     D3DXBoundProbeTest();
160     D3DXIntersectTriTest();
161 }