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 
126  if (Single){
127  vp.Vertex[0] = (const Point*)(((ubyte*)mVerts) + T->mVRef[0] * mVertexStride);
128  vp.Vertex[1] = (const Point*)(((ubyte*)mVerts) + T->mVRef[1] * mVertexStride);
129  vp.Vertex[2] = (const Point*)(((ubyte*)mVerts) + T->mVRef[2] * mVertexStride);
130  }
131  else{
132  for (int i = 0; i < 3; i++){
133  const double* v = (const double*)(((ubyte*)mVerts) + T->mVRef[i] * mVertexStride);
134 
135  VertexCache[i].x = (float)v[0];
136  VertexCache[i].y = (float)v[1];
137  VertexCache[i].z = (float)v[2];
138  vp.Vertex[i] = &VertexCache[i];
139  }
140  }
141  #else
142  const IndexedTriangle* T = &mTris[index];
143  vp.Vertex[0] = &mVerts[T->mVRef[0]];
144  vp.Vertex[1] = &mVerts[T->mVRef[1]];
145  vp.Vertex[2] = &mVerts[T->mVRef[2]];
146  #endif
147 #endif
148  }
149 
151 
157  bool RemapClient(udword nb_indices, const udword* permutation) const;
159 
161 
165  bool IsValid() const;
167 
169 
174  udword CheckTopology() const;
176  private:
177 
180 #ifdef OPC_USE_CALLBACKS
181  // User callback
182  void* mUserData;
183  RequestCallback mObjCallback;
184 #else
185  // User pointers
187  const Point* mVerts;
188  #ifdef OPC_USE_STRIDE
189  udword mTriStride;
190  udword mVertexStride;
191  #endif
192  public:
193  bool Single;
194  private:
195  static Point VertexCache[3];
196 #endif
197  };
198 
199 #endif //__OPC_MESHINTERFACE_H__
bool BackfaceCulling(const Point &source)
const IndexedTriangle * mTris
Array of indexed triangles.
udword mNbTris
Number of triangles in the input model.
inline_ udword GetNbVertices() const
udword mVRef[3]
Vertex-references.
inline_ void SetNbVertices(udword nb)
#define inline_
const Point * Vertex[3]
png_uint_32 i
Definition: png.h:2735
Definition: IcePoint.h:25
const Point * mVerts
Array of vertices.
#define OPCODE_API
Definition: Opcode.h:68
udword mNbVerts
Number of vertices in the input model.
float x
Definition: IcePoint.h:524
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
inline_ void SetNbTriangles(udword nb)
inline_ udword GetNbTriangles() const
list index
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
unsigned char ubyte
sizeof(ubyte) must be 1
Definition: IceTypes.h:61
inline_ const Point * GetVerts() const
inline_ const IndexedTriangle * GetTris() const
bool Single
Use single or double precision vertices.


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:24