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
Opcode::HybridSphereCollider Class Reference

#include <Opcode.h>

Inheritance diagram for Opcode::HybridSphereCollider:
Opcode::SphereCollider Opcode::VolumeCollider Opcode::Collider

Public Member Functions

 HybridSphereCollider ()
 
virtual ~HybridSphereCollider ()
 
bool Collide (SphereCache &cache, const Sphere &sphere, const HybridModel &model, const Matrix4x4 *worlds=null, const Matrix4x4 *worldm=null)
 
- Public Member Functions inherited from Opcode::SphereCollider
 SphereCollider ()
 
virtual ~SphereCollider ()
 
bool Collide (SphereCache &cache, const Sphere &sphere, const Model &model, const Matrix4x4 *worlds=null, const Matrix4x4 *worldm=null)
 
bool Collide (SphereCache &cache, const Sphere &sphere, const AABBTree *tree)
 
- Public Member Functions inherited from Opcode::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 Opcode::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 Attributes

Container mTouchedBoxes
 
- Protected Attributes inherited from Opcode::SphereCollider
Point mCenter
 Sphere center. More...
 
float mRadius2
 Sphere radius squared. More...
 
- Protected Attributes inherited from Opcode::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 Opcode::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...
 

Additional Inherited Members

- Protected Member Functions inherited from Opcode::SphereCollider
void _Collide (const AABBCollisionNode *node)
 
void _Collide (const AABBNoLeafNode *node)
 
void _Collide (const AABBQuantizedNode *node)
 
void _Collide (const AABBQuantizedNoLeafNode *node)
 
void _Collide (const AABBTreeNode *node)
 
void _CollideNoPrimitiveTest (const AABBCollisionNode *node)
 
void _CollideNoPrimitiveTest (const AABBNoLeafNode *node)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNode *node)
 
void _CollideNoPrimitiveTest (const AABBQuantizedNoLeafNode *node)
 
inline_ bool SphereContainsBox (const Point &bc, const Point &be)
 
inline_ bool SphereAABBOverlap (const Point &center, const Point &extents)
 
bool SphereTriOverlap (const Point &vert0, const Point &vert1, const Point &vert2)
 
bool InitQuery (SphereCache &cache, const Sphere &sphere, const Matrix4x4 *worlds=null, const Matrix4x4 *worldm=null)
 

Detailed Description

Definition at line 85 of file Opcode.h.

Constructor & Destructor Documentation

HybridSphereCollider::HybridSphereCollider ( )

Constructor.

Definition at line 591 of file OPC_SphereCollider.cpp.

592 {
593 }
HybridSphereCollider::~HybridSphereCollider ( )
virtual

Destructor.

Definition at line 600 of file OPC_SphereCollider.cpp.

601 {
602 }

Member Function Documentation

bool HybridSphereCollider::Collide ( SphereCache cache,
const Sphere sphere,
const HybridModel model,
const Matrix4x4 worlds = null,
const Matrix4x4 worldm = null 
)

Definition at line 604 of file OPC_SphereCollider.cpp.

References Opcode::SphereCollider::_CollideNoPrimitiveTest(), Opcode::Collider::GetContactStatus(), Opcode::HybridModel::GetIndices(), Opcode::HybridModel::GetLeafTriangles(), Container::GetNbEntries(), Opcode::LeafTriangles::GetNbTriangles(), Opcode::MeshInterface::GetNbTriangles(), Opcode::BaseModel::GetTree(), Opcode::LeafTriangles::GetTriangleIndex(), Opcode::BaseModel::HasLeafNodes(), Opcode::BaseModel::HasSingleNode(), i, Opcode::Collider::InitQuery(), Opcode::BaseModel::IsQuantized(), Opcode::VolumeCollider::mCenterCoeff, Opcode::AABBQuantizedTree::mCenterCoeff, Opcode::AABBQuantizedNoLeafTree::mCenterCoeff, Opcode::Collider::mCurrentModel, Opcode::VolumeCollider::mExtentsCoeff, Opcode::AABBQuantizedTree::mExtentsCoeff, Opcode::AABBQuantizedNoLeafTree::mExtentsCoeff, Opcode::Collider::mFlags, Opcode::Collider::mIMesh, Opcode::VolumeCollider::mTouchedPrimitives, Opcode::OPC_CONTACT, Opcode::OPC_NO_PRIMITIVE_TESTS, Container::Reset(), Opcode::Collider::Setup(), SPHERE_PRIM, and Opcode::VolumeCache::TouchedPrimitives.

605 {
606  // We don't want primitive tests here!
608 
609  // Checkings
610  if(!Setup(&model)) return false;
611 
612  // Init collision query
613  if(InitQuery(cache, sphere, worlds, worldm)) return true;
614 
615  // Special case for 1-leaf trees
617  {
618  // Here we're supposed to perform a normal query, except our tree has a single node, i.e. just a few triangles
619  udword Nb = mIMesh->GetNbTriangles();
620 
621  // Loop through all triangles
622  for(udword i=0;i<Nb;i++)
623  {
625  }
626  return true;
627  }
628 
629  // Override destination array since we're only going to get leaf boxes here
632 
633  // Now, do the actual query against leaf boxes
634  if(!model.HasLeafNodes())
635  {
636  if(model.IsQuantized())
637  {
638  const AABBQuantizedNoLeafTree* Tree = (const AABBQuantizedNoLeafTree*)model.GetTree();
639 
640  // Setup dequantization coeffs
641  mCenterCoeff = Tree->mCenterCoeff;
643 
644  // Perform collision query - we don't want primitive tests here!
645  _CollideNoPrimitiveTest(Tree->GetNodes());
646  }
647  else
648  {
649  const AABBNoLeafTree* Tree = (const AABBNoLeafTree*)model.GetTree();
650 
651  // Perform collision query - we don't want primitive tests here!
652  _CollideNoPrimitiveTest(Tree->GetNodes());
653  }
654  }
655  else
656  {
657  if(model.IsQuantized())
658  {
659  const AABBQuantizedTree* Tree = (const AABBQuantizedTree*)model.GetTree();
660 
661  // Setup dequantization coeffs
662  mCenterCoeff = Tree->mCenterCoeff;
664 
665  // Perform collision query - we don't want primitive tests here!
666  _CollideNoPrimitiveTest(Tree->GetNodes());
667  }
668  else
669  {
670  const AABBCollisionTree* Tree = (const AABBCollisionTree*)model.GetTree();
671 
672  // Perform collision query - we don't want primitive tests here!
673  _CollideNoPrimitiveTest(Tree->GetNodes());
674  }
675  }
676 
677  // We only have a list of boxes so far
678  if(GetContactStatus())
679  {
680  // Reset contact status, since it currently only reflects collisions with leaf boxes
682 
683  // Change dest container so that we can use built-in overlap tests and get collided primitives
684  cache.TouchedPrimitives.Reset();
686 
687  // Read touched leaf boxes
689  const udword* Touched = mTouchedBoxes.GetEntries();
690 
691  const LeafTriangles* LT = model.GetLeafTriangles();
692  const udword* Indices = model.GetIndices();
693 
694  // Loop through touched leaves
695  while(Nb--)
696  {
697  const LeafTriangles& CurrentLeaf = LT[*Touched++];
698 
699  // Each leaf box has a set of triangles
700  udword NbTris = CurrentLeaf.GetNbTriangles();
701  if(Indices)
702  {
703  const udword* T = &Indices[CurrentLeaf.GetTriangleIndex()];
704 
705  // Loop through triangles and test each of them
706  while(NbTris--)
707  {
708  udword TriangleIndex = *T++;
709  SPHERE_PRIM(TriangleIndex, OPC_CONTACT)
710  }
711  }
712  else
713  {
714  udword BaseIndex = CurrentLeaf.GetTriangleIndex();
715 
716  // Loop through triangles and test each of them
717  while(NbTris--)
718  {
719  udword TriangleIndex = BaseIndex++;
720  SPHERE_PRIM(TriangleIndex, OPC_CONTACT)
721  }
722  }
723  }
724  }
725 
726  return true;
727 }

Member Data Documentation

Container Opcode::HybridSphereCollider::mTouchedBoxes
protected

Definition at line 94 of file Opcode.h.


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