d3dx8: Implement D3DXBoxBoundProbe
H. Verbeet
hverbeet at gmail.com
Wed Jul 30 02:52:26 CDT 2008
Looks good in principle, but I've still got a few comments:
> + if ( praydirection->x >= 0.0f )
> + {
> + tmin = ( pmin->x - prayposition->x ) / praydirection->x;
> + tmax = ( pmax->x - prayposition->x ) / praydirection->x;
> + }
...
> + if ( tmax < 0.0f ) return FALSE;
This will break if praydirection->x is -0.0, because in that case
you'll end up with -INF for positive values of tmin and tmax, and INF
for negative values. One way to solve this is to do the division
before the if. Ie:
float div;
...
div = 1.0 / praydirection->x;
if (div >= 0.0f)
{
tmin = (pmin->x - prayposition->x) * div;
tmax = (pmax->x - prayposition->x) * div;
}
...
That way you'll test against INF or -INF rather than 0.0 or -0.0
(which are considered equal).
I don't think this one is right:
> + if ( tymax > tmax ) tmax = tymax;
if ( tymax < tmax ) tmax = tymax;
would work better I think.
> + if ( tzmin > tmin ) tmin = tzmin;
> + if ( tzmax > tmax ) tmax = tzmax;
These are redundant.
Although the code looks pretty clear to me, in general it might make
sense to briefly describe the algorithm. Something along the lines of
"Consider the box as the intersection of three slabs. Clip the ray
against each slab, if there's anything left of the ray after we're
done we've got an intersection of the ray with the box."
More information about the wine-devel
mailing list