OPC_TreeCollider.h
Go to the documentation of this file.
00001 
00002 /*
00003  *      OPCODE - Optimized Collision Detection
00004  *      Copyright (C) 2001 Pierre Terdiman
00005  *      Homepage: http://www.codercorner.com/Opcode.htm
00006  */
00008 
00010 
00016 
00017 
00019 // Include Guard
00020 #ifndef __OPC_TREECOLLIDER_H__
00021 #define __OPC_TREECOLLIDER_H__
00022 
00023 #include"../config.h"
00030         struct OPCODE_API BVTCache : Pair
00031         {
00033                 inline_                         BVTCache()
00034                                                         {
00035                                                                 ResetCache();
00036                                                                 ResetCountDown();
00037                                                         }
00038 
00039                                         void    ResetCache()
00040                                                         {
00041                                                                 Model0                  = null;
00042                                                                 Model1                  = null;
00043                                                                 id0                             = 0;
00044                                                                 id1                             = 1;
00045 #ifdef __MESHMERIZER_H__                // Collision hulls only supported within ICE !
00046                                                                 HullTest                = true;
00047                                                                 SepVector.pid   = 0;
00048                                                                 SepVector.qid   = 0;
00049                                                                 SepVector.SV    = Point(1.0f, 0.0f, 0.0f);
00050 #endif // __MESHMERIZER_H__
00051                                                         }
00052 
00053                 inline_         void    ResetCountDown()
00054                                                         {
00055 #ifdef __MESHMERIZER_H__                // Collision hulls only supported within ICE !
00056                                                                 CountDown               = 50;
00057 #endif // __MESHMERIZER_H__
00058                                                         }
00059 
00060                 const Model*            Model0; 
00061                 const Model*            Model1; 
00062 
00063 #ifdef __MESHMERIZER_H__        // Collision hulls only supported within ICE !
00064                 SVCache                         SepVector;
00065                 udword                          CountDown;
00066                 bool                            HullTest;
00067 #endif // __MESHMERIZER_H__
00068         };
00069 
00070         class OPCODE_API AABBTreeCollider : public Collider
00071         {
00072                 public:
00073                 // Constructor / Destructor
00074                 AABBTreeCollider();
00075                 virtual                                                         ~AABBTreeCollider();
00076 
00077                 inline void setCollisionPairInserter(hrp::CollisionPairInserterBase* collisionPairInserter) {
00078                     this->collisionPairInserter = collisionPairInserter;
00079                 }
00080 
00081                 
00082                 // Generic collision query
00083 
00085 
00097 
00098                                                         bool                    Collide(BVTCache& cache, const Matrix4x4* world0=null, const Matrix4x4* world1=null);
00099 
00100                 // Collision queries
00101                                                         bool                    Collide(const AABBCollisionTree* tree0, const AABBCollisionTree* tree1,                         const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
00102                                                         bool                    Collide(const AABBNoLeafTree* tree0, const AABBNoLeafTree* tree1,                                       const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
00103                                                         bool                    Collide(const AABBQuantizedTree* tree0, const AABBQuantizedTree* tree1,                         const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
00104                                                         bool                    Collide(const AABBQuantizedNoLeafTree* tree0, const AABBQuantizedNoLeafTree* tree1,     const Matrix4x4* world0=null, const Matrix4x4* world1=null, Pair* cache=null);
00105                 // Settings
00106 
00108 
00113 
00114                 inline_                         void                    SetFullBoxBoxTest(bool flag)                    { mFullBoxBoxTest               = flag;                                 }
00115 
00117 
00122 
00123                 inline_                         void                    SetFullPrimBoxTest(bool flag)                   { mFullPrimBoxTest              = flag;                                 }
00124 
00125                 // Stats
00126 
00128 
00134 
00135                 inline_                         udword                  GetNbBVBVTests()                                const   { return mNbBVBVTests;                                                  }
00136 
00138 
00144 
00145                 inline_                         udword                  GetNbPrimPrimTests()                    const   { return mNbPrimPrimTests;                                              }
00146 
00148 
00154 
00155                 inline_                         udword                  GetNbBVPrimTests()                              const   { return mNbBVPrimTests;                                                }
00156 
00157                 // Data access
00158 
00160 
00166 
00167                 inline_                         udword                  GetNbPairs()                                    const   { return mPairs.GetNbEntries()>>1;                              }
00168 
00170 
00176 
00177                 inline_                         const Pair*             GetPairs()                                              const   { return (const Pair*)mPairs.GetEntries();              }
00178 
00180 
00184 
00185                 override(Collider)      HRP_COLLISION_EXPORT const char*                ValidateSettings();
00186 
00187                 protected:
00188                 // Colliding pairs
00189                                                         Container               mPairs;                         
00190                 // User mesh interfaces
00191                                         const   MeshInterface*  mIMesh0;                        
00192                                         const   MeshInterface*  mIMesh1;                        
00193                 // Stats
00194                                                         udword                  mNbBVBVTests;           
00195                                                         udword                  mNbPrimPrimTests;       
00196                                                         udword                  mNbBVPrimTests;         
00197                 // Precomputed data
00198                                                         Matrix3x3               mAR;                            
00199                                                         Matrix3x3               mR0to1;                         
00200                                                         Matrix3x3               mR1to0;                         
00201                                                         Point                   mT0to1;                         
00202                                                         Point                   mT1to0;                         
00203                 // Dequantization coeffs
00204                                                         Point                   mCenterCoeff0;
00205                                                         Point                   mExtentsCoeff0;
00206                                                         Point                   mCenterCoeff1;
00207                                                         Point                   mExtentsCoeff1;
00208                 // Modified!!
00209             // For normal vector detection
00210                                                         udword          mId0;
00211                                                         udword          mId1;
00212                                                         const AABBCollisionNode*   mNowNode0;
00213                                                         const AABBCollisionNode*   mNowNode1;
00214                 // Leaf description
00215                                                         Point                   mLeafVerts[3];          
00216                                                         udword                  mLeafIndex;                     
00217                 // Settings
00218                                                         bool                    mFullBoxBoxTest;        
00219                                                         bool                    mFullPrimBoxTest;       
00220                                                         hrp::CollisionPairInserterBase* collisionPairInserter;
00221                 // Internal methods
00222 
00223                         // Standard AABB trees
00224                                                         void                    _Collide(const AABBCollisionNode* b0, const AABBCollisionNode* b1);
00225                         // Quantized AABB trees
00226                                                         void                    _Collide(const AABBQuantizedNode* b0, const AABBQuantizedNode* b1, const Point& a, const Point& Pa, const Point& b, const Point& Pb);
00227                         // No-leaf AABB trees
00228                                                         void                    _CollideTriBox(const AABBNoLeafNode* b);
00229                                                         void                    _CollideBoxTri(const AABBNoLeafNode* b);
00230                                                         void                    _Collide(const AABBNoLeafNode* a, const AABBNoLeafNode* b);
00231                         // Quantized no-leaf AABB trees
00232                                                         void                    _CollideTriBox(const AABBQuantizedNoLeafNode* b);
00233                                                         void                    _CollideBoxTri(const AABBQuantizedNoLeafNode* b);
00234                                                         void                    _Collide(const AABBQuantizedNoLeafNode* a, const AABBQuantizedNoLeafNode* b);
00235                         // Overlap tests
00236                                                         void                    PrimTest(udword id0, udword id1);
00237                         inline_                 void                    PrimTestTriIndex(udword id1);
00238                         inline_                 void                    PrimTestIndexTri(udword id0);
00239 
00240                         inline_                 BOOL                    BoxBoxOverlap(const Point& ea, const Point& ca, const Point& eb, const Point& cb);
00241                         inline_                 BOOL                    TriBoxOverlap(const Point& center, const Point& extents);
00242                                                 BOOL                    TriTriOverlap(const Point& V0, const Point& V1, const Point& V2, const Point& U0, const Point& U1, const Point& U2);
00243                         // Init methods
00244                         HRP_COLLISION_EXPORT    void    InitQuery(const Matrix4x4* world0=null, const Matrix4x4* world1=null);
00245                                                         bool                    CheckTemporalCoherence(Pair* cache);
00246 
00247                 inline_                         BOOL                    Setup(const MeshInterface* mi0, const MeshInterface* mi1)
00248                                                                                         {
00249                                                                                                 mIMesh0 = mi0;
00250                                                                                                 mIMesh1 = mi1;
00251 
00252                                                                                                 if(!mIMesh0 || !mIMesh1)        return FALSE;
00253 
00254                                                                                                 return TRUE;
00255                                                                                         }
00256         };
00257 
00258 #endif // __OPC_TREECOLLIDER_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:18