Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlanesCollider Class Reference

#include <OPC_PlanesCollider.h>

Inheritance diagram for PlanesCollider:
VolumeCollider Collider HybridPlanesCollider

Public Member Functions

 PlanesCollider ()
 
virtual ~PlanesCollider ()
 
bool Collide (PlanesCache &cache, const Plane *planes, udword nb_planes, const Model &model, const Matrix4x4 *worldm=null)
 
inline_ bool Collide (PlanesCache &cache, const OBB &box, const Model &model, const Matrix4x4 *worldb=null, const Matrix4x4 *worldm=null)
 
 override (Collider) const char *ValidateSettings()
 
- Public Member Functions inherited from VolumeCollider
 VolumeCollider ()
 
virtual ~VolumeCollider ()=0
 
inline_ udword GetNbTouchedPrimitives () const
 
inline_ const udwordGetTouchedPrimitives () const
 
inline_ udword GetNbVolumeBVTests () const
 
inline_ udword GetNbVolumePrimTests () const
 
 override (Collider) const char *ValidateSettings()
 
- Public Member Functions inherited from Collider
 Collider ()
 
virtual ~Collider ()
 
inline_ BOOL GetContactStatus () const
 
inline_ BOOL FirstContactEnabled () const
 
inline_ BOOL TemporalCoherenceEnabled () const
 
inline_ BOOL ContactFound () const
 
inline_ BOOL TemporalHit () const
 
inline_ BOOL SkipPrimitiveTests () const
 
inline_ void SetFirstContact (bool flag)
 
inline_ void SetTemporalCoherence (bool flag)
 
inline_ void SetPrimitiveTests (bool flag)
 
virtual const char * ValidateSettings ()=0
 

Protected Member Functions

void _Collide (const AABBCollisionNode *node, udword clip_mask)
 
void _Collide (const AABBNoLeafNode *node, udword clip_mask)
 
void _Collide (const AABBQuantizedNode *node, udword clip_mask)
 
void _Collide (const AABBQuantizedNoLeafNode *node, udword clip_mask)
 
void _CollideNoPrimitiveTest (const AABBCollisionNode *node, udword clip_mask)
 
void _CollideNoPrimitiveTest (const AABBNoLeafNode *node, udword clip_mask)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNode *node, udword clip_mask)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNoLeafNode *node, udword clip_mask)
 
inline_ bool PlanesAABBOverlap (const Point &center, const Point &extents, udword &out_clip_mask, udword in_clip_mask)
 
inline_ bool PlanesTriOverlap (udword in_clip_mask)
 
bool InitQuery (PlanesCache &cache, const Plane *planes, udword nb_planes, const Matrix4x4 *worldm=null)
 
- Protected Member Functions inherited from VolumeCollider
void _Dump (const AABBCollisionNode *node)
 
void _Dump (const AABBNoLeafNode *node)
 
void _Dump (const AABBQuantizedNode *node)
 
void _Dump (const AABBQuantizedNoLeafNode *node)
 
 override (Collider) inline_ void InitQuery()
 
inline_ BOOL IsCacheValid (VolumeCache &cache)
 
- Protected Member Functions inherited from Collider
inline_ BOOL Setup (const BaseModel *model)
 
virtual inline_ void InitQuery ()
 

Protected Attributes

udword mNbPlanes
 
PlanemPlanes
 
VertexPointers mVP
 
- Protected Attributes inherited from VolumeCollider
ContainermTouchedPrimitives
 List of touched primitives. More...
 
Point mCenterCoeff
 
Point mExtentsCoeff
 
udword mNbVolumeBVTests
 Number of Volume-BV tests. More...
 
udword mNbVolumePrimTests
 Number of Volume-Primitive tests. More...
 
- Protected Attributes inherited from Collider
udword mFlags
 Bit flags. More...
 
const BaseModelmCurrentModel
 Current model for collision query (owner of touched faces) More...
 
const MeshInterfacemIMesh
 User-defined mesh interface. More...
 

Detailed Description

Contains a Planes-vs-tree collider.

Author
Pierre Terdiman
Version
1.3
Date
January, 1st, 2002

Definition at line 30 of file OPC_PlanesCollider.h.

Constructor & Destructor Documentation

PlanesCollider::PlanesCollider ( )
virtual PlanesCollider::~PlanesCollider ( )
virtual

Member Function Documentation

void PlanesCollider::_Collide ( const AABBCollisionNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_Collide ( const AABBNoLeafNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_Collide ( const AABBQuantizedNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_Collide ( const AABBQuantizedNoLeafNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_CollideNoPrimitiveTest ( const AABBCollisionNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_CollideNoPrimitiveTest ( const AABBNoLeafNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_CollideNoPrimitiveTest ( const AABBQuantizedNode node,
udword  clip_mask 
)
protected
void PlanesCollider::_CollideNoPrimitiveTest ( const AABBQuantizedNoLeafNode node,
udword  clip_mask 
)
protected
bool PlanesCollider::Collide ( PlanesCache cache,
const Plane planes,
udword  nb_planes,
const Model model,
const Matrix4x4 worldm = null 
)

Generic collision query for generic OPCODE models. After the call, access the results:

Parameters
cache[in/out] a planes cache
planes[in] list of planes in world space
nb_planes[in] number of planes
model[in] Opcode model to collide with
worldm[in] model's world matrix, or null
Returns
true if success
Warning
SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.
inline_ bool PlanesCollider::Collide ( PlanesCache cache,
const OBB box,
const Model model,
const Matrix4x4 worldb = null,
const Matrix4x4 worldm = null 
)
inline

Definition at line 56 of file OPC_PlanesCollider.h.

References OBB::ComputePlanes(), and OBB::Rotate().

57  {
58  Plane PL[6];
59 
60  if(worldb)
61  {
62  // Create a new OBB in world space
63  OBB WorldBox;
64  box.Rotate(*worldb, WorldBox);
65  // Compute planes from the sides of the box
66  WorldBox.ComputePlanes(PL);
67  }
68  else
69  {
70  // Compute planes from the sides of the box
71  box.ComputePlanes(PL);
72  }
73 
74  // Collide with box planes
75  return Collide(cache, PL, 6, model, worldm);
76  }
bool PlanesCollider::InitQuery ( PlanesCache cache,
const Plane planes,
udword  nb_planes,
const Matrix4x4 worldm = null 
)
protected
PlanesCollider::override ( Collider  ) const

Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider.

Returns
null if everything is ok, else a string describing the problem
inline_ bool PlanesCollider::PlanesAABBOverlap ( const Point center,
const Point extents,
udword out_clip_mask,
udword  in_clip_mask 
)
protected

Planes-AABB overlap test.

  • original code by Ville Miettinen, from Umbra/dPVS (released on the GD-Algorithms mailing list)
  • almost used "as-is", I even left the comments (hence the frustum-related notes)
Parameters
center[in] box center
extents[in] box extents
out_clip_mask[out] bitmask for active planes
in_clip_mask[in] bitmask for active planes
Returns
TRUE if boxes overlap planes

Definition at line 14 of file OPC_PlanesAABBOverlap.h.

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 Möller). 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 }
inline_ bool PlanesCollider::PlanesTriOverlap ( udword  in_clip_mask)
protected

Planes-triangle overlap test.

Parameters
in_clip_mask[in] bitmask for active planes
Returns
TRUE if triangle overlap planes
Warning
THIS IS A CONSERVATIVE TEST !! Some triangles will be returned as intersecting, while they're not!

Definition at line 9 of file OPC_PlanesTriOverlap.h.

10 {
11  // Stats
13 
14  const Plane* p = mPlanes;
15  udword Mask = 1;
16 
17  while(Mask<=in_clip_mask)
18  {
19  if(in_clip_mask & Mask)
20  {
21  float d0 = p->Distance(*mVP.Vertex[0]);
22  float d1 = p->Distance(*mVP.Vertex[1]);
23  float d2 = p->Distance(*mVP.Vertex[2]);
24  if(d0>0.0f && d1>0.0f && d2>0.0f) return FALSE;
25 // if(!(IR(d0)&SIGN_BITMASK) && !(IR(d1)&SIGN_BITMASK) && !(IR(d2)&SIGN_BITMASK)) return FALSE;
26  }
27  Mask+=Mask;
28  p++;
29  }
30 /*
31  for(udword i=0;i<6;i++)
32  {
33  float d0 = p[i].Distance(mLeafVerts[0]);
34  float d1 = p[i].Distance(mLeafVerts[1]);
35  float d2 = p[i].Distance(mLeafVerts[2]);
36  if(d0>0.0f && d1>0.0f && d2>0.0f) return false;
37  }
38 */
39  return TRUE;
40 }

Member Data Documentation

udword PlanesCollider::mNbPlanes
protected

Definition at line 89 of file OPC_PlanesCollider.h.

Plane* PlanesCollider::mPlanes
protected

Definition at line 90 of file OPC_PlanesCollider.h.

VertexPointers PlanesCollider::mVP
protected

Definition at line 92 of file OPC_PlanesCollider.h.


The documentation for this class was generated from the following files: