[ODE] plane class with half space aabb - version with use of gflags

Tim Schmidt tisch at uni-paderborn.de
Wed Jul 2 13:17:02 2003


Hi!

Here is my announced second version of axis alignment detection in the 
plane geom. I now use the gflags member instead of an additional integer 
member. What do you think?
If everything is ok with this version and there are no objections to use 
the gflags for such things in the future (Russ?), then somebody with CVS 
access may eventually add these modified functions to the CVS 
(->collision_std.cpp).

-Tim

------------

#define AXIS_ALIGNMENT_MASK (7<<29)
// results in 11100000 00000000 00000000 00000000

static void detectAxisAlignment (dxPlane *g)
{
   if (g->p[0] == -1)
   {
     // set three most significant bits to 0=000
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 0<<29;
   }
   else if (g->p[0] == 1)
   {
     // set three most significant bits to 1=100
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 1<<29;
   }
   else if (g->p[1] == -1)
   {
     // set three most significant bits to 2=010
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 2<<29;
   }
   else if (g->p[1] == 1)
   {
     // set three most significant bits to 3=110
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 3<<29;
   }
   else if (g->p[2] == -1)
   {
     // set three most significant bits to 4=001
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 4<<29;
   }
   else if (g->p[2] == 1)
   {
     // set three most significant bits to 5=101
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | 5<<29;
   }
   else    // ==> not aligned
   {
     // set three most significant bits to -1=111 (2's complement!!)
     g->gflags = (g->gflags & ~AXIS_ALIGNMENT_MASK) | -1<<29;
   }
}

dxPlane::dxPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d) :
   dxGeom (space,0)
{
   type = dPlaneClass;
   p[0] = a;
   p[1] = b;
   p[2] = c;
   p[3] = d;
   make_sure_plane_normal_has_unit_length (this);
   detectAxisAlignment(this);
}

void dxPlane::computeAABB()
{
   aabb[0] = -dInfinity;
   aabb[1] = dInfinity;
   aabb[2] = -dInfinity;
   aabb[3] = dInfinity;
   aabb[4] = -dInfinity;
   aabb[5] = dInfinity;
   if ((gflags>>29) >= 0) // if three most significant bits are >0
   {
     aabb[(gflags>>29)] = p[3];
   }
}

void dGeomPlaneSetParams (dGeomID g, dReal a, dReal b, dReal c, dReal d)
{
   dUASSERT (g && g->type == dPlaneClass,"argument not a plane");
   dxPlane *p = (dxPlane*) g;
   p->p[0] = a;
   p->p[1] = b;
   p->p[2] = c;
   p->p[3] = d;
   make_sure_plane_normal_has_unit_length (p);
   detectAxisAlignment(p);
   dGeomMoved (g);
}