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
OPC_MeshInterface.h
Go to the documentation of this file.
1 /*
3  * OPCODE - Optimized Collision Detection
4  * Copyright (C) 2001 Pierre Terdiman
5  * Homepage: http://www.codercorner.com/Opcode.htm
6  */
8 
10 
16 
19 // Include Guard
20 #ifndef __OPC_MESHINTERFACE_H__
21 #define __OPC_MESHINTERFACE_H__
22 
24  {
25  const Point* Vertex[3];
26 
27  bool BackfaceCulling(const Point& source)
28  {
29  const Point& p0 = *Vertex[0];
30  const Point& p1 = *Vertex[1];
31  const Point& p2 = *Vertex[2];
32 
33  // Compute normal direction
34  Point Normal = (p2 - p1)^(p0 - p1);
35 
36  // Backface culling
37  return (Normal | (source - p0)) >= 0.0f;
38  }
39  };
40 
41 #ifdef OPC_USE_CALLBACKS
42 
49  typedef void (*RequestCallback) (udword triangle_index, VertexPointers& triangle, void* user_data);
51 #endif
52 
54  {
55  public:
56  // Constructor / Destructor
57  MeshInterface();
58  ~MeshInterface();
59  // Common settings
60  inline_ udword GetNbTriangles() const { return mNbTris; }
61  inline_ udword GetNbVertices() const { return mNbVerts; }
62  inline_ void SetNbTriangles(udword nb) { mNbTris = nb; }
63  inline_ void SetNbVertices(udword nb) { mNbVerts = nb; }
64 
65 #ifdef OPC_USE_CALLBACKS
66  // Callback settings
67 
69 
75  bool SetCallback(RequestCallback callback, void* user_data);
77  inline_ void* GetUserData() const { return mUserData; }
78  inline_ RequestCallback GetCallback() const { return mObjCallback; }
79 #else
80  // Pointers settings
81 
83 
89  bool SetPointers(const IndexedTriangle* tris, const Point* verts);
91  inline_ const IndexedTriangle* GetTris() const { return mTris; }
92  inline_ const Point* GetVerts() const { return mVerts; }
93 
94  #ifdef OPC_USE_STRIDE
95  // Strides settings
96 
98 
104  bool SetStrides(udword tri_stride=sizeof(IndexedTriangle), udword vertex_stride=sizeof(Point));
106  inline_ udword GetTriStride() const { return mTriStride; }
107  inline_ udword GetVertexStride() const { return mVertexStride; }
108  #endif
109 #endif
110 
112 
117  inline_ void GetTriangle(VertexPointers& vp, udword index) const
119  {
120 #ifdef OPC_USE_CALLBACKS
121  (mObjCallback)(index, vp, mUserData);
122 #else
123  #ifdef OPC_USE_STRIDE
124  const IndexedTriangle* T = (const IndexedTriangle*)(((ubyte*)mTris) + index * mTriStride);
125  vp.Vertex[0] = (const Point*)(((ubyte*)mVerts) + T->mVRef[0] * mVertexStride);
126  vp.Vertex[1] = (const Point*)(((ubyte*)mVerts) + T->mVRef[1] * mVertexStride);
127  vp.Vertex[2] = (const Point*)(((ubyte*)mVerts) + T->mVRef[2] * mVertexStride);
128  #else
129  const IndexedTriangle* T = &mTris[index];
130  vp.Vertex[0] = &mVerts[T->mVRef[0]];
131  vp.Vertex[1] = &mVerts[T->mVRef[1]];
132  vp.Vertex[2] = &mVerts[T->mVRef[2]];
133  #endif
134 #endif
135  }
136 
138 
144  bool RemapClient(udword nb_indices, const udword* permutation) const;
146 
148 
152  bool IsValid() const;
154 
156 
161  udword CheckTopology() const;
163  private:
164 
165 #ifdef OPC_USE_CALLBACKS
166  // User callback
167  void* mUserData;
168  RequestCallback mObjCallback;
169 #else
170  // User pointers
171  const IndexedTriangle* mTris;
172  const Point* mVerts;
173  #ifdef OPC_USE_STRIDE
174  udword mTriStride;
175  udword mVertexStride;
176  #endif
177 #endif
178  udword mNbTris;
179  udword mNbVerts;
180  };
181 
182 #endif //__OPC_MESHINTERFACE_H__