OPC_MeshInterface.cpp
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 
29 
32 
115 
118 // Precompiled Header
119 #include "Stdafx.h"
120 
121 using namespace Opcode;
122 
124 
126 
131  mNbTris (0),
132  mNbVerts (0),
133 #ifdef OPC_USE_CALLBACKS
134  mUserData (null),
135  mObjCallback (null),
136 #else
137  mTris (null),
138  mVerts (null),
139  #ifdef OPC_USE_STRIDE
140  mTriStride (sizeof(IndexedTriangle)),
141  mVertexStride (sizeof(Point)),
142  #endif
143 #endif
144 
145  Single(true)
146 {
147 }
148 
150 
155 {
156 }
157 
159 
163 bool MeshInterface::IsValid() const
165 {
166  if(!mNbTris || !mNbVerts) return false;
167 #ifdef OPC_USE_CALLBACKS
168  if(!mObjCallback) return false;
169 #else
170  if(!mTris || !mVerts) return false;
171 #endif
172  return true;
173 }
174 
176 
183 {
184  // Check topology. If the model contains degenerate faces, collision report can be wrong in some cases.
185  // e.g. it happens with the standard MAX teapot. So clean your meshes first... If you don't have a mesh cleaner
186  // you can try this: www.codercorner.com/Consolidation.zip
187 
188  udword NbDegenerate = 0;
189 
190  VertexPointers VP;
191 
192  // Using callbacks, we don't have access to vertex indices. Nevertheless we still can check for
193  // redundant vertex pointers, which cover all possibilities (callbacks/pointers/strides).
194  for(udword i=0;i<mNbTris;i++)
195  {
196  GetTriangle(VP, i);
197 
198  if( (VP.Vertex[0]==VP.Vertex[1])
199  || (VP.Vertex[1]==VP.Vertex[2])
200  || (VP.Vertex[2]==VP.Vertex[0])) NbDegenerate++;
201  }
202 
203  return NbDegenerate;
204 }
205 
206 #ifdef OPC_USE_CALLBACKS
207 
214 bool MeshInterface::SetCallback(RequestCallback callback, void* user_data)
216 {
217  if(!callback) return SetIceError("MeshInterface::SetCallback: callback pointer is null");
218 
219  mObjCallback = callback;
220  mUserData = user_data;
221  return true;
222 }
223 #else
224 
231 bool MeshInterface::SetPointers(const IndexedTriangle* tris, const Point* verts)
233 {
234  if(!tris || !verts) return SetIceError("MeshInterface::SetPointers: pointer is null", null);
235 
236  mTris = tris;
237  mVerts = verts;
238  return true;
239 }
240 #ifdef OPC_USE_STRIDE
241 
248 bool MeshInterface::SetStrides(udword tri_stride, udword vertex_stride)
250 {
251  if(tri_stride<sizeof(IndexedTriangle)) return SetIceError("MeshInterface::SetStrides: invalid triangle stride", null);
252  if(vertex_stride<sizeof(Point)) return SetIceError("MeshInterface::SetStrides: invalid vertex stride", null);
253 
254  mTriStride = tri_stride;
255  mVertexStride = vertex_stride;
256  return true;
257 }
258 #endif
259 #endif
260 
262 
268 bool MeshInterface::RemapClient(udword nb_indices, const udword* permutation) const
270 {
271  // Checkings
272  if(!nb_indices || !permutation) return false;
273  if(nb_indices!=mNbTris) return false;
274 
275 #ifdef OPC_USE_CALLBACKS
276  // We can't really do that using callbacks
277  return false;
278 #else
279  IndexedTriangle* Tmp = new IndexedTriangle[mNbTris];
280  CHECKALLOC(Tmp);
281 
282  #ifdef OPC_USE_STRIDE
283  udword Stride = mTriStride;
284  #else
285  udword Stride = sizeof(IndexedTriangle);
286  #endif
287 
288  for(udword i=0;i<mNbTris;i++)
289  {
290  const IndexedTriangle* T = (const IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
291  Tmp[i] = *T;
292  }
293 
294  for(udword i=0;i<mNbTris;i++)
295  {
296  IndexedTriangle* T = (IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
297  *T = Tmp[permutation[i]];
298  }
299 
300  DELETEARRAY(Tmp);
301 #endif
302  return true;
303 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
bool SetPointers(const IndexedTriangle *tris, const Point *verts)
#define DELETEARRAY(x)
Deletes an array.
#define SetIceError(a, b)
Definition: OPC_IceHook.h:29
const Point * Vertex[3]
Definition: Opcode.h:26
png_uint_32 i
Definition: png.h:2735
static Point VertexCache[3]
Definition: Opcode.h:196
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:65
#define CHECKALLOC(x)
unsigned char ubyte
sizeof(ubyte) must be 1
Definition: IceTypes.h:61
udword CheckTopology() const
bool RemapClient(udword nb_indices, const udword *permutation) const
bool IsValid() const


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:04