[ODE] plane class with half space aabb

Tim Schmidt tisch at uni-paderborn.de
Fri Jun 27 07:16:02 2003


This is a multi-part message in MIME format.
--------------050700030003060100030802
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi!

I have just come across the following comment in
collision_std.cpp (line 319):

void dxPlane::computeAABB()
{
   // @@@ planes that have normal vectors aligned along an axis can use a
   // @@@ less comprehensive (half space) bounding box.
   .....


So, here is my approach to this comparatively small problem for those 
who may find it useful.
I have attached a 'diff -r -C 2' text-file for convenience.

regards,
	Tim

#############################################################

// I have added an integer to the plane class that shows the
// open side of the half space.

struct dxPlane : public dxGeom {
   dReal p[4];
   int halfSpaceOpenSide;              // added
   dxPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
   void computeAABB();
};

// This function detects a possible alignment of the normal
// vector and an axis.

static void detectAxisAlignment(dxPlane *g)
{
   if (g->p[0] == -1)
   {
     g->halfSpaceOpenSide = 0;
   }
   else if (g->p[0] == 1)
   {
     g->halfSpaceOpenSide = 1;
   }
   else if (g->p[1] == -1)
   {
     g->halfSpaceOpenSide = 2;
   }
   else if (g->p[1] == 1)
   {
     g->halfSpaceOpenSide = 3;
   }
   else if (g->p[2] == -1)
   {
     g->halfSpaceOpenSide = 4;
   }
   else if (g->p[2] == 1)
   {
     g->halfSpaceOpenSide = 5;
   }
   else             // not aligned
   {
     g->halfSpaceOpenSide = -1;
   }
}

// The axis alignment must be computed when the parameters
// of the plane are initially set.

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);               // added
}

void dxPlane::computeAABB()
{
   aabb[0] = -dInfinity;
   aabb[1] = dInfinity;
   aabb[2] = -dInfinity;
   aabb[3] = dInfinity;
   aabb[4] = -dInfinity;
   aabb[5] = dInfinity;
   if (halfSpaceOpenSide >= 0)          // added
   {
     // set the open side of the half space to the
     // fourth parameter of the plane
     aabb[halfSpaceOpenSide] = p[3];    // added
   }
}

// The axis alignment must be recomputed when the parameters
// of the plane are changed.

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);                // added
   dGeomMoved (g);
}


--------------050700030003060100030802
Content-Type: text/plain;
 name="planeWithHalfSpaceAABB.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="planeWithHalfSpaceAABB.txt"

diff -r -C 2 ode/ode/src/collision_std.cpp odenew/ode/src/collision_std.cpp
*** ode/ode/src/collision_std.cpp	Fri Jun 27 15:49:06 2003
--- odenew/ode/src/collision_std.cpp	Fri Jun 27 16:07:32 2003
***************
*** 65,68 ****
--- 65,69 ----
  struct dxPlane : public dxGeom {
    dReal p[4];
+   int halfSpaceOpenSide;
    dxPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
    void computeAABB();
***************
*** 303,306 ****
--- 304,343 ----
  
  
+ // This function detects a possible alignment of the normal 
+ // vector and an axis.
+ 
+ static void detectAxisAlignment (dxPlane *g)
+ {
+   if (g->p[0] == -1)
+   {
+     g->m_halfSpaceOpenSide = 0;
+   }
+   else if (g->p[0] == 1)
+   {
+     g->m_halfSpaceOpenSide = 1;
+   }
+   else if (g->p[1] == -1)
+   {
+     g->m_halfSpaceOpenSide = 2;
+   }
+   else if (g->p[1] == 1)
+   {
+     g->m_halfSpaceOpenSide = 3;
+   }
+   else if (g->p[2] == -1)
+   {
+     g->m_halfSpaceOpenSide = 4;
+   }
+   else if (g->p[2] == 1)
+   {
+     g->m_halfSpaceOpenSide = 5;
+   }
+   else    // not aligned
+   {
+     g->m_halfSpaceOpenSide = -1;
+   }
+ }
+ 
+ 
  dxPlane::dxPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d) :
    dxGeom (space,0)
***************
*** 312,315 ****
--- 349,353 ----
    p[3] = d;
    make_sure_plane_normal_has_unit_length (this);
+   detectAxisAlignment(this);
  }
  
***************
*** 317,322 ****
  void dxPlane::computeAABB()
  {
-   // @@@ planes that have normal vectors aligned along an axis can use a
-   // @@@ less comprehensive (half space) bounding box.
    aabb[0] = -dInfinity;
    aabb[1] = dInfinity;
--- 355,358 ----
***************
*** 325,328 ****
--- 361,368 ----
    aabb[4] = -dInfinity;
    aabb[5] = dInfinity;
+   if (halfSpaceOpenSide >= 0)
+   {
+     aabb[halfSpaceOpenSide] = p[3];
+   }
  }
  
***************
*** 344,347 ****
--- 384,388 ----
    p->p[3] = d;
    make_sure_plane_normal_has_unit_length (p);
+   detectAxisAlignment(p);
    dGeomMoved (g);
  }

--------------050700030003060100030802--