[ODE] dCreateBox() inputs halfsizes? And bug in geom.cpp?

Ruud van Gaal ruud at marketgraph.nl
Wed Dec 12 19:01:01 2001


> Ruud van Gaal wrote:
...
> > However, at collision time, I need the bounding box of the *geometry*
> > instead,
> > which is shifted with respect to it's dynamics counterpart. In other words,
> > the
> > space geomID box and the world bodyID box are related in size, but their
> > centers don't match.
>
> I think you want to use the dCreateGeomTransform() function, which
> lets you apply a local transform to your bounding box.

Thanks for that tip. Hadn't seen that function yet.
In the meantime, I've got it to work, but yet with an addition of a '-' sign 
(these little buggers!) ;-)

Here's my view: a plane is normally defined by 'n dot p+d' where n is the plane 
normal, p is a point on a plane, and d is a distance shift. To get a distance 
to a plane, you just evaluate this formula, and voila, out comes the distance. 
If it's positive, the point is IN FRONT of the plane. It's supposed to be like 
this in ODE, right?

Now look at dCollideBP() in geom.cpp, it uses:
  depth=plane->p[3]+0.5*(B1+B2+B3)-dDOT(n,o1->pos);

Where p[3] is the 'd' of the plane (ax+by+cz+d=0), (B1+B2+B3) is the vector 
from the center of box to one of the corner points, the 0.5 is there because 
B1/B2/B3 are all full sizes, and you need halfsizes (if you've ever done 
separating axes methods you know why). The dDOT is the n*p from above.
The thing Russ is trying to get is the penetration depth into the plane; which 
is simply 'n dot p+d' combined (read: added) with the length of the box in the 
direction of the plane. As penetration means the distance to the plane is <0, 
to get a positive penetration depth Russ negates the formula. So, directly 
writing:
dDOT(n,o1->pos)+plane->p[3]-0.5*(B1+B2+B3) => would give negative depths, so we 
negate and shuffle:
-plane->p[3]+0.5*(B1+B2+B3)-dDOT(n,o1->pos).

Note the '-' sign in front of plane->p[3]. I assume this is a bug (which works 
ok ofcourse for ground planes where d or p[3]=0); I've corrected it and voila, 
suddenly my code started working. I've put quite some hours into tracing this 
and did a lot of manual calculations to make sure my plane equation was ok (I'm 
also using the same righthanded system as ODE), so I'm convinced at the moment 
that the '-' must be there.

What do you think, Russ?

Ruud