2 * Copyright 2008 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
21 #include "wine/test.h"
23 #define admitted_error 0.0001f
25 static BOOL
compare(FLOAT u
, FLOAT v
)
27 return (fabs(u
-v
) < admitted_error
);
30 static void D3DXBoundProbeTest(void)
33 D3DXVECTOR3 bottom_point
, center
, top_point
, raydirection
, rayposition
;
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
;
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");
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");
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");
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");
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
;
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");
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
;
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");
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");
82 /*____________Test the Sphere case________________________*/
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
;
87 rayposition
.x
= 5.0f
; rayposition
.y
= 5.0f
; rayposition
.z
= 9.0f
;
88 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
89 ok(result
== TRUE
, "expected TRUE, received FALSE\n");
91 rayposition
.x
= 45.0f
; rayposition
.y
= -75.0f
; rayposition
.z
= 49.0f
;
92 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
93 ok(result
== FALSE
, "expected FALSE, received TRUE\n");
95 rayposition
.x
= 5.0f
; rayposition
.y
= 7.0f
; rayposition
.z
= 9.0f
;
96 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
97 ok(result
== FALSE
, "expected FALSE, received TRUE\n");
99 rayposition
.x
= 5.0f
; rayposition
.y
= 11.0f
; rayposition
.z
= 9.0f
;
100 result
= D3DXSphereBoundProbe(¢er
, radius
, &rayposition
, &raydirection
);
101 ok(result
== FALSE
, "expected FALSE, received TRUE\n");
104 static void D3DXIntersectTriTest(void)
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
;
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
;
114 position
.x
= -14.5f
; position
.y
= -23.75f
; position
.z
= -32.0f
;
116 ray
.x
= 2.0f
; ray
.y
= 3.0f
; ray
.z
= 4.0f
;
118 exp_res
= TRUE
; exp_u
= 0.5f
; exp_v
= 0.25f
; exp_dist
= 8.0f
;
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
);
126 /*Only positive ray is taken in account*/
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
;
132 position
.x
= 17.5f
; position
.y
= 24.25f
; position
.z
= 32.0f
;
134 ray
.x
= 2.0f
; ray
.y
= 3.0f
; ray
.z
= 4.0f
;
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
);
141 /*Intersection between ray and triangle in a same plane is considered as empty*/
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
;
147 position
.x
= 1.0f
; position
.y
= 1.0f
; position
.z
= 0.0f
;
149 ray
.x
= 1.0f
; ray
.y
= 0.0f
; ray
.z
= 0.0f
;
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
);
159 D3DXBoundProbeTest();
160 D3DXIntersectTriTest();