OPC_RayCollider.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_RAYCOLLIDER_H__
00021 #define __OPC_RAYCOLLIDER_H__
00022 
00023         class OPCODE_API CollisionFace
00024         {
00025                 public:
00027                 inline_                         CollisionFace()                 {}
00029                 inline_                         ~CollisionFace()                {}
00030 
00031                                 udword          mFaceID;                                
00032                                 float           mDistance;                              
00033                                 float           mU, mV;                                 
00034         };
00035 
00036         class OPCODE_API CollisionFaces : private Container
00037         {
00038                 public:
00040                                                                                 CollisionFaces()                                                {}
00042                                                                                 ~CollisionFaces()                                               {}
00043 
00044                 inline_ udword                                  GetNbFaces()                                    const   { return GetNbEntries()>>2;                                             }
00045                 inline_ const CollisionFace*    GetFaces()                                              const   { return (const CollisionFace*)GetEntries();    }
00046 
00047                 inline_ void                                    Reset()                                                                 { Container::Reset();                                                   }
00048 
00049                 inline_ void                                    AddFace(const CollisionFace& face)              { Add(face.mFaceID).Add(face.mDistance).Add(face.mU).Add(face.mV);      }
00050         };
00051 
00052 #ifdef OPC_RAYHIT_CALLBACK
00053 
00054 
00059 
00060         typedef void    (*HitCallback)  (const CollisionFace& hit, void* user_data);
00061 #endif
00062 
00063         class OPCODE_API RayCollider : public Collider
00064         {
00065                 public:
00066                 // Constructor / Destructor
00067                                                                                         RayCollider();
00068                 virtual                                                         ~RayCollider();
00069 
00071 
00083 
00084                                                         bool                    Collide(const Ray& world_ray, const Model& model, const Matrix4x4* world=null, udword* cache=null);
00085                 //
00086                                                         bool                    Collide(const Ray& world_ray, const AABBTree* tree, Container& box_indices);
00087                 // Settings
00088 
00089 #ifndef OPC_RAYHIT_CALLBACK
00090 
00091 
00098 
00099                 inline_                         void                    SetClosestHit(bool flag)                                { mClosestHit   = flag;         }
00100 #endif
00101 
00102 
00109 
00110                 inline_                         void                    SetCulling(bool flag)                                   { mCulling              = flag;         }
00111 
00113 
00120 
00121                 inline_                         void                    SetMaxDist(float max_dist=MAX_FLOAT)    { mMaxDist              = max_dist;     }
00122 
00123 #ifdef OPC_RAYHIT_CALLBACK
00124                 inline_                         void                    SetHitCallback(HitCallback cb)                  { mHitCallback  = cb;                   }
00125                 inline_                         void                    SetUserData(void* user_data)                    { mUserData             = user_data;    }
00126 #else
00127 
00128 
00135 
00136                 inline_                         void                    SetDestination(CollisionFaces* cf)              { mStabbedFaces = cf;           }
00137 #endif
00138                 // Stats
00140 
00146 
00147                 inline_                         udword                  GetNbRayBVTests()                               const   { return mNbRayBVTests;         }
00148 
00150 
00156 
00157                 inline_                         udword                  GetNbRayPrimTests()                             const   { return mNbRayPrimTests;       }
00158 
00159                 // In-out test
00161 
00167 
00168                 inline_                         udword                  GetNbIntersections()                    const   { return mNbIntersections;      }
00169 
00171 
00175 
00176                 override(Collider)      const char*             ValidateSettings();
00177 
00178                 protected:
00179                 // Ray in local space
00180                                                         Point                   mOrigin;                        
00181                                                         Point                   mDir;                           
00182                                                         Point                   mFDir;                          
00183                                                         Point                   mData, mData2;
00184                 // Stabbed faces
00185                                                         CollisionFace   mStabbedFace;           
00186 #ifdef OPC_RAYHIT_CALLBACK
00187                                                         HitCallback             mHitCallback;           
00188                                                         void*                   mUserData;                      
00189 #else
00190                                                         CollisionFaces* mStabbedFaces;          
00191 #endif
00192                 // Stats
00193                                                         udword                  mNbRayBVTests;          
00194                                                         udword                  mNbRayPrimTests;        
00195                 // In-out test
00196                                                         udword                  mNbIntersections;       
00197                 // Dequantization coeffs
00198                                                         Point                   mCenterCoeff;
00199                                                         Point                   mExtentsCoeff;
00200                 // Settings
00201                                                         float                   mMaxDist;                       
00202 #ifndef OPC_RAYHIT_CALLBACK
00203                                                         bool                    mClosestHit;            
00204 #endif
00205                                                         bool                    mCulling;                       
00206                 // Internal methods
00207                                                         void                    _SegmentStab(const AABBCollisionNode* node);
00208                                                         void                    _SegmentStab(const AABBNoLeafNode* node);
00209                                                         void                    _SegmentStab(const AABBQuantizedNode* node);
00210                                                         void                    _SegmentStab(const AABBQuantizedNoLeafNode* node);
00211                                                         void                    _SegmentStab(const AABBTreeNode* node, Container& box_indices);
00212                                                         void                    _RayStab(const AABBCollisionNode* node);
00213                                                         void                    _RayStab(const AABBNoLeafNode* node);
00214                                                         void                    _RayStab(const AABBQuantizedNode* node);
00215                                                         void                    _RayStab(const AABBQuantizedNoLeafNode* node);
00216                                                         void                    _RayStab(const AABBTreeNode* node, Container& box_indices);
00217                         // Overlap tests
00218                 inline_                         BOOL                    RayAABBOverlap(const Point& center, const Point& extents);
00219                 inline_                         BOOL                    SegmentAABBOverlap(const Point& center, const Point& extents);
00220                 inline_                         BOOL                    RayTriOverlap(const Point& vert0, const Point& vert1, const Point& vert2);
00221                         // Init methods
00222                                                         BOOL                    InitQuery(const Ray& world_ray, const Matrix4x4* world=null, udword* face_id=null);
00223         };
00224 
00225 #endif // __OPC_RAYCOLLIDER_H__


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:56