Open Dynamics Engine

collision_space_internal.h

00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith.       *
00004  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
00005  *                                                                       *
00006  * This library is free software; you can redistribute it and/or         *
00007  * modify it under the terms of EITHER:                                  *
00008  *   (1) The GNU Lesser General Public License as published by the Free  *
00009  *       Software Foundation; either version 2.1 of the License, or (at  *
00010  *       your option) any later version. The text of the GNU Lesser      *
00011  *       General Public License is included with this library in the     *
00012  *       file LICENSE.TXT.                                               *
00013  *   (2) The BSD-style license that is included with this library in     *
00014  *       the file LICENSE-BSD.TXT.                                       *
00015  *                                                                       *
00016  * This library is distributed in the hope that it will be useful,       *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00019  * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
00020  *                                                                       *
00021  *************************************************************************/
00022 
00023 /*
00024 
00025 stuff common to all spaces
00026 
00027 */
00028 
00029 #ifndef _ODE_COLLISION_SPACE_INTERNAL_H_
00030 #define _ODE_COLLISION_SPACE_INTERNAL_H_
00031 
00032 #define ALLOCA(x) dALLOCA16(x)
00033 
00034 #define CHECK_NOT_LOCKED(space) \
00035   dUASSERT ((space)==0 || (space)->lock_count==0, \
00036        "invalid operation for locked space");
00037 
00038 
00039 // collide two geoms together. for the hash table space, this is
00040 // called if the two AABBs inhabit the same hash table cells.
00041 // this only calls the callback function if the AABBs actually
00042 // intersect. if a geom has an AABB test function, that is called to
00043 // provide a further refinement of the intersection.
00044 //
00045 // NOTE: this assumes that the geom AABBs are valid on entry
00046 // and that both geoms are enabled.
00047 
00048 static inline void collideAABBs (dxGeom *g1, dxGeom *g2,
00049            void *data, dNearCallback *callback)
00050 {
00051   dIASSERT((g1->gflags & GEOM_AABB_BAD)==0);
00052   dIASSERT((g2->gflags & GEOM_AABB_BAD)==0);
00053 
00054   // no contacts if both geoms on the same body, and the body is not 0
00055   if (g1->body == g2->body && g1->body) return;
00056 
00057   // test if the category and collide bitfields match
00058   if ( ((g1->category_bits & g2->collide_bits) ||
00059    (g2->category_bits & g1->collide_bits)) == 0) {
00060     return;
00061   }
00062 
00063   // if the bounding boxes are disjoint then don't do anything
00064   dReal *bounds1 = g1->aabb;
00065   dReal *bounds2 = g2->aabb;
00066   if (bounds1[0] > bounds2[1] ||
00067       bounds1[1] < bounds2[0] ||
00068       bounds1[2] > bounds2[3] ||
00069       bounds1[3] < bounds2[2] ||
00070       bounds1[4] > bounds2[5] ||
00071       bounds1[5] < bounds2[4]) {
00072     return;
00073   }
00074 
00075   // check if either object is able to prove that it doesn't intersect the
00076   // AABB of the other
00077   if (g1->AABBTest (g2,bounds2) == 0) return;
00078   if (g2->AABBTest (g1,bounds1) == 0) return;
00079 
00080   // the objects might actually intersect - call the space callback function
00081   callback (data,g1,g2);
00082 }
00083 
00084 #endif