[ODE] plane class with half space aabb - version with use of
gflags
Tim Schmidt
tisch at uni-paderborn.de
Wed Jul 2 19:43:02 2003
Erwin de Vries wrote:
> Looks great. Havent tested if it works, but if it does (which i guess we can
> assume) we should get this code inside ODE.
hmmm, I should make more comprehensive tests before I post something.
Unfortunately I do NOT account for the case that a plane has a normal
that points to the negativ direction of an axis and has a positiv
d-parameter. Such a plane does not intersect the axis at p[3] but
actually at -p[3]. But here the corresponding collide function would be
triggered not until a geom has deeply (depending on the of p[3]) sunk
into the plane.
Hence I have to provide additional tests in computeAABB(), if it was the
negativ side of which axis. Or I have to encode that information into
the three gflag bits beforehand, which results in corresponding decoding
(some shifting and masking of bits, I think) in computeAABB().
In the end I wonder if it was not much easier and even faster to
relocate these tests completely into computeAABB() without using any
precomputed gflag bits at all.
... not to mention the fact that a plane is actually meant to be
unplaceable anyway. So normally computeAABB() is called only at the
beginning.
With the following we have only two tests for '== 0' and one
for '> 0' (at least mostly).
Also it is much easier to understand.
After all I have at least learned much (again ;-) ) about bitwise
operators, shifting, 2's complement ... and that things need not
necessarily to be complicated ;-)
>> Much ado about nothing << *sigh*
-Tim
------
void dxPlane::computeAABB()
{
aabb[0] = -dInfinity;
aabb[1] = dInfinity;
aabb[2] = -dInfinity;
aabb[3] = dInfinity;
aabb[4] = -dInfinity;
aabb[5] = dInfinity;
if (p[0] == 0.0)
{
if (p[2] == 0.0) // plane is xz-plane ... (which is most probable)
{
if (p[1] > 0) // ... and points upwards
{
aabb[3] = p[3];
}
else // ... and points downwards
{
aabb[2] = -p[3];
}
}
else if (p[1] == 0.0) // plane is xy-plane
{
if (p[2] > 0) // ... and points towards the viewer
{
aabb[5] = p[3];
}
else // ... and points away from the viewer
{
aabb[4] = -p[3];
}
}
}
else if (p[1] == 0.0)
{
if (p[2] == 0.0) // plane is yz-plane ...
{
if (p[0] > 0) // ... and points to the right
{
aabb[1] = p[3];
}
else // ... and points to the left
{
aabb[0] = -p[3];
}
}
}
}