OPC_MeshInterface.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_MESHINTERFACE_H__
00021 #define __OPC_MESHINTERFACE_H__
00022 
00023         struct VertexPointers
00024         {
00025                 const Point*    Vertex[3];
00026 
00027                 bool BackfaceCulling(const Point& source)
00028                 {
00029                         const Point& p0 = *Vertex[0];
00030                         const Point& p1 = *Vertex[1];
00031                         const Point& p2 = *Vertex[2];
00032 
00033                         // Compute normal direction
00034                         Point Normal = (p2 - p1)^(p0 - p1);
00035 
00036                         // Backface culling
00037                         return (Normal | (source - p0)) >= 0.0f;
00038                 }
00039         };
00040 
00041 #ifdef OPC_USE_CALLBACKS
00042 
00043 
00049 
00050         typedef void    (*RequestCallback)      (udword triangle_index, VertexPointers& triangle, void* user_data);
00051 #endif
00052 
00053         class OPCODE_API MeshInterface
00054         {
00055                 public:
00056                 // Constructor / Destructor
00057                                                                                         MeshInterface();
00058                                                                                         ~MeshInterface();
00059                 // Common settings
00060                 inline_                 udword                          GetNbTriangles()        const   { return mNbTris;       }
00061                 inline_                 udword                          GetNbVertices()         const   { return mNbVerts;      }
00062                 inline_                 void                            SetNbTriangles(udword nb)       { mNbTris = nb;         }
00063                 inline_                 void                            SetNbVertices(udword nb)        { mNbVerts = nb;        }
00064 
00065 #ifdef OPC_USE_CALLBACKS
00066                 // Callback settings
00067 
00069 
00075 
00076                                                 bool                            SetCallback(RequestCallback callback, void* user_data);
00077                 inline_                 void*                           GetUserData()           const   { return mUserData;             }
00078                 inline_                 RequestCallback         GetCallback()           const   { return mObjCallback;  }
00079 #else
00080                 // Pointers settings
00081 
00083 
00089 
00090                                                 bool                            SetPointers(const IndexedTriangle* tris, const Point* verts);
00091                 inline_ const   IndexedTriangle*        GetTris()                       const   { return mTris;                 }
00092                 inline_ const   Point*                          GetVerts()                      const   { return mVerts;                }
00093 
00094         #ifdef OPC_USE_STRIDE
00095                 // Strides settings
00096 
00098 
00104 
00105                                                 bool                            SetStrides(udword tri_stride=sizeof(IndexedTriangle), udword vertex_stride=sizeof(Point));
00106                 inline_                 udword                          GetTriStride()          const   { return mTriStride;    }
00107                 inline_                 udword                          GetVertexStride()       const   { return mVertexStride; }
00108         #endif
00109 #endif
00110 
00112 
00117 
00118                 inline_                 void                            GetTriangle(VertexPointers& vp, udword index)   const
00119                                                                                         {
00120 #ifdef OPC_USE_CALLBACKS
00121                                                                                                 (mObjCallback)(index, vp, mUserData);
00122 #else
00123         #ifdef OPC_USE_STRIDE
00124                                                                                                 const IndexedTriangle* T = (const IndexedTriangle*)(((ubyte*)mTris) + index * mTriStride);
00125 
00126                                                                                                 if (Single){
00127                                                                                                         vp.Vertex[0] = (const Point*)(((ubyte*)mVerts) + T->mVRef[0] * mVertexStride);
00128                                                                                                         vp.Vertex[1] = (const Point*)(((ubyte*)mVerts) + T->mVRef[1] * mVertexStride);
00129                                                                                                         vp.Vertex[2] = (const Point*)(((ubyte*)mVerts) + T->mVRef[2] * mVertexStride);
00130                                                                                                 }
00131                                                                                                 else{
00132                                                                                                         for (int i = 0; i < 3; i++){
00133                                                                                                                 const double* v = (const double*)(((ubyte*)mVerts) + T->mVRef[i] * mVertexStride);
00134 
00135                                                                                                                 VertexCache[i].x = (float)v[0];
00136                                                                                                                 VertexCache[i].y = (float)v[1];
00137                                                                                                                 VertexCache[i].z = (float)v[2];
00138                                                                                                                 vp.Vertex[i] = &VertexCache[i];
00139                                                                                                         }
00140                                                                                                 }
00141         #else
00142                                                                                                 const IndexedTriangle* T = &mTris[index];
00143                                                                                                 vp.Vertex[0] = &mVerts[T->mVRef[0]];
00144                                                                                                 vp.Vertex[1] = &mVerts[T->mVRef[1]];
00145                                                                                                 vp.Vertex[2] = &mVerts[T->mVRef[2]];
00146         #endif
00147 #endif
00148                                                                                         }
00149 
00151 
00157 
00158                 bool                            RemapClient(udword nb_indices, const udword* permutation)       const;
00159 
00161 
00165 
00166                                                 bool                            IsValid()               const;
00167 
00169 
00174 
00175                                                 udword                          CheckTopology() const;
00176                 private:
00177 
00178                                                 udword                          mNbTris;                        
00179                                                 udword                          mNbVerts;                       
00180 #ifdef OPC_USE_CALLBACKS
00181                 // User callback
00182                                                 void*                           mUserData;                      
00183                                                 RequestCallback         mObjCallback;           
00184 #else
00185                 // User pointers
00186                                 const   IndexedTriangle*        mTris;                          
00187                                 const   Point*                          mVerts;                         
00188         #ifdef OPC_USE_STRIDE
00189                                                 udword                          mTriStride;                     
00190                                                 udword                          mVertexStride;          
00191         #endif
00192                 public:
00193                                                 bool Single;                                                    
00194                 private:
00195                                                 static Point VertexCache[3];
00196 #endif
00197         };
00198 
00199 #endif //__OPC_MESHINTERFACE_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:55