OPC_PlanesAABBOverlap.h
Go to the documentation of this file.
1 
13 inline_ BOOL PlanesCollider::PlanesAABBOverlap(const Point& center, const Point& extents, udword& out_clip_mask, udword in_clip_mask)
15 {
16  // Stats
18 
19  const Plane* p = mPlanes;
20 
21  // Evaluate through all active frustum planes. We determine the relation
22  // between the AABB and a plane by using the concept of "near" and "far"
23  // vertices originally described by Zhang (and later by Moller). Our
24  // variant here uses 3 fabs ops, 6 muls, 7 adds and two floating point
25  // comparisons per plane. The routine early-exits if the AABB is found
26  // to be outside any of the planes. The loop also constructs a new output
27  // clip mask. Most FPUs have a native single-cycle fabsf() operation.
28 
29  udword Mask = 1; // current mask index (1,2,4,8,..)
30  udword TmpOutClipMask = 0; // initialize output clip mask into empty.
31 
32  while(Mask<=in_clip_mask) // keep looping while we have active planes left...
33  {
34  if(in_clip_mask & Mask) // if clip plane is active, process it..
35  {
36  float NP = extents.x*fabsf(p->n.x) + extents.y*fabsf(p->n.y) + extents.z*fabsf(p->n.z); // ### fabsf could be precomputed
37  float MP = center.x*p->n.x + center.y*p->n.y + center.z*p->n.z + p->d;
38 
39  if(NP < MP) // near vertex behind the clip plane...
40  return FALSE; // .. so there is no intersection..
41  if((-NP) < MP) // near and far vertices on different sides of plane..
42  TmpOutClipMask |= Mask; // .. so update the clip mask...
43  }
44  Mask+=Mask; // mk = (1<<plane)
45  p++; // advance to next plane
46  }
47 
48  out_clip_mask = TmpOutClipMask; // copy output value (temp used to resolve aliasing!)
49  return TRUE; // indicate that AABB intersects frustum
50 }
Point::z
float z
Definition: IcePoint.h:524
VolumeCollider::mNbVolumeBVTests
udword mNbVolumeBVTests
Number of Volume-BV tests.
Definition: OPC_VolumeCollider.h:99
udword
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
BOOL
int BOOL
Another boolean type.
Definition: IceTypes.h:102
Point::x
float x
Definition: IcePoint.h:524
Plane::n
Point n
The normal to the plane.
Definition: IcePlane.h:53
Plane::d
float d
The distance from the origin.
Definition: IcePlane.h:54
PlanesCollider::PlanesAABBOverlap
inline_ BOOL PlanesAABBOverlap(const Point &center, const Point &extents, udword &out_clip_mask, udword in_clip_mask)
Definition: OPC_PlanesAABBOverlap.h:14
TRUE
#define TRUE
Definition: OPC_IceHook.h:13
FALSE
#define FALSE
Definition: OPC_IceHook.h:9
Point
Definition: IcePoint.h:25
Plane
Definition: IcePlane.h:17
Point::y
float y
Definition: IcePoint.h:524
inline_
#define inline_
Definition: IcePreprocessor.h:103
PlanesCollider::mPlanes
Plane * mPlanes
Definition: OPC_PlanesCollider.h:94


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:03