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
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
27 BOOL WINAPI
D3DXBoxBoundProbe(CONST D3DXVECTOR3
*pmin
, CONST D3DXVECTOR3
*pmax
, CONST D3DXVECTOR3
*prayposition
, CONST D3DXVECTOR3
*praydirection
)
29 /* Algorithm taken from the article: An Efficient and Robust Ray-Box Intersection Algoritm
30 Amy Williams University of Utah
31 Steve Barrus University of Utah
32 R. Keith Morley University of Utah
33 Peter Shirley University of Utah
35 International Conference on Computer Graphics and Interactive Techniques archive
36 ACM SIGGRAPH 2005 Courses
37 Los Angeles, California
39 This algorithm is free of patents or of copyrights, as confirmed by Peter Shirley himself.
41 Algorithm: Consider the box as the intersection of three slabs. Clip the ray
42 against each slab, if there's anything left of the ray after we're
43 done we've got an intersection of the ray with the box.
47 FLOAT div
, tmin
, tmax
, tymin
, tymax
, tzmin
, tzmax
;
49 div
= 1.0f
/ praydirection
->x
;
52 tmin
= ( pmin
->x
- prayposition
->x
) * div
;
53 tmax
= ( pmax
->x
- prayposition
->x
) * div
;
57 tmin
= ( pmax
->x
- prayposition
->x
) * div
;
58 tmax
= ( pmin
->x
- prayposition
->x
) * div
;
61 if ( tmax
< 0.0f
) return FALSE
;
63 div
= 1.0f
/ praydirection
->y
;
66 tymin
= ( pmin
->y
- prayposition
->y
) * div
;
67 tymax
= ( pmax
->y
- prayposition
->y
) * div
;
71 tymin
= ( pmax
->y
- prayposition
->y
) * div
;
72 tymax
= ( pmin
->y
- prayposition
->y
) * div
;
75 if ( ( tymax
< 0.0f
) || ( tmin
> tymax
) || ( tymin
> tmax
) ) return FALSE
;
77 if ( tymin
> tmin
) tmin
= tymin
;
78 if ( tymax
< tmax
) tmax
= tymax
;
80 div
= 1.0f
/ praydirection
->z
;
83 tzmin
= ( pmin
->z
- prayposition
->z
) * div
;
84 tzmax
= ( pmax
->z
- prayposition
->z
) * div
;
88 tzmin
= ( pmax
->z
- prayposition
->z
) * div
;
89 tzmax
= ( pmin
->z
- prayposition
->z
) * div
;
92 if ( (tzmax
< 0.0f
) || ( tmin
> tzmax
) || ( tzmin
> tmax
) ) return FALSE
;
97 BOOL WINAPI
D3DXSphereBoundProbe(CONST D3DXVECTOR3
*pcenter
, FLOAT radius
, CONST D3DXVECTOR3
*prayposition
, CONST D3DXVECTOR3
*praydirection
)
99 D3DXVECTOR3 difference
;
102 a
= D3DXVec3LengthSq(praydirection
);
103 if (!D3DXVec3Subtract(&difference
, prayposition
, pcenter
)) return FALSE
;
104 b
= D3DXVec3Dot(&difference
, praydirection
);
105 c
= D3DXVec3LengthSq(&difference
) - radius
* radius
;
108 if ( ( d
<= 0.0f
) || ( sqrt(d
) <= b
) ) return FALSE
;