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__
MeshInterface::SetNbTriangles
inline_ void SetNbTriangles(udword nb)
Definition: OPC_MeshInterface.h:62
i
png_uint_32 i
Definition: png.h:2732
VertexPointers
Definition: OPC_MeshInterface.h:23
IndexedTriangle::mVRef
udword mVRef[3]
Vertex-references.
Definition: IceIndexedTriangle.h:40
MeshInterface::SetNbVertices
inline_ void SetNbVertices(udword nb)
Definition: OPC_MeshInterface.h:63
udword
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
MeshInterface::mNbVerts
udword mNbVerts
Number of vertices in the input model.
Definition: OPC_MeshInterface.h:179
swingTest.f
f
Definition: swingTest.py:6
ubyte
unsigned char ubyte
sizeof(ubyte) must be 1
Definition: IceTypes.h:61
MeshInterface::GetVerts
const inline_ Point * GetVerts() const
Definition: OPC_MeshInterface.h:92
Point::x
float x
Definition: IcePoint.h:524
MeshInterface::GetNbVertices
inline_ udword GetNbVertices() const
Definition: OPC_MeshInterface.h:61
MeshInterface::mVerts
const Point * mVerts
Array of vertices.
Definition: OPC_MeshInterface.h:187
VertexPointers::Vertex
const Point * Vertex[3]
Definition: OPC_MeshInterface.h:25
MeshInterface::GetTris
const inline_ IndexedTriangle * GetTris() const
Definition: OPC_MeshInterface.h:91
MeshInterface::Single
bool Single
Use single or double precision vertices.
Definition: OPC_MeshInterface.h:193
OPCODE_API
#define OPCODE_API
Definition: Opcode.h:68
void
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
Point
Definition: IcePoint.h:25
IndexedTriangle
Definition: IceIndexedTriangle.h:23
MeshInterface
Definition: OPC_MeshInterface.h:53
VertexPointers::BackfaceCulling
bool BackfaceCulling(const Point &source)
Definition: OPC_MeshInterface.h:27
MeshInterface::mTris
const IndexedTriangle * mTris
Array of indexed triangles.
Definition: OPC_MeshInterface.h:186
inline_
#define inline_
Definition: IcePreprocessor.h:103
MeshInterface::mNbTris
udword mNbTris
Number of triangles in the input model.
Definition: OPC_MeshInterface.h:178
MeshInterface::GetNbTriangles
inline_ udword GetNbTriangles() const
Definition: OPC_MeshInterface.h:60


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:03