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
Opcode::MeshInterface Class Reference

#include <Opcode.h>

Public Member Functions

 MeshInterface ()
 
 ~MeshInterface ()
 
inline_ udword GetNbTriangles () const
 
inline_ udword GetNbVertices () const
 
inline_ void SetNbTriangles (udword nb)
 
inline_ void SetNbVertices (udword nb)
 
bool SetCallback (RequestCallback callback, void *user_data)
 
inline_ void * GetUserData () const
 
inline_ RequestCallback GetCallback () const
 
inline_ void GetTriangle (VertexPointers &vp, udword index) const
 
bool RemapClient (udword nb_indices, const udword *permutation) const
 
bool IsValid () const
 
udword CheckTopology () const
 

Detailed Description

Definition at line 54 of file Opcode.h.

Constructor & Destructor Documentation

MeshInterface::MeshInterface ( )

Constructor.

Definition at line 129 of file OPC_MeshInterface.cpp.

129  :
130 #ifdef OPC_USE_CALLBACKS
131  mUserData (null),
132  mObjCallback (null),
133 #else
134  mTris (null),
135  mVerts (null),
136  #ifdef OPC_USE_STRIDE
137  mTriStride (sizeof(IndexedTriangle)),
138  mVertexStride (sizeof(Point)),
139  #endif
140 #endif
141  mNbTris (0),
142  mNbVerts (0)
143 {
144 }
MeshInterface::~MeshInterface ( )

Destructor.

Definition at line 151 of file OPC_MeshInterface.cpp.

152 {
153 }

Member Function Documentation

udword MeshInterface::CheckTopology ( ) const

Checks the mesh itself is valid. Currently we only look for degenerate faces.

Returns
number of degenerate faces

Definition at line 179 of file OPC_MeshInterface.cpp.

180 {
181  // Check topology. If the model contains degenerate faces, collision report can be wrong in some cases.
182  // e.g. it happens with the standard MAX teapot. So clean your meshes first... If you don't have a mesh cleaner
183  // you can try this: www.codercorner.com/Consolidation.zip
184 
185  udword NbDegenerate = 0;
186 
187  VertexPointers VP;
188 
189  // Using callbacks, we don't have access to vertex indices. Nevertheless we still can check for
190  // redundant vertex pointers, which cover all possibilities (callbacks/pointers/strides).
191  for(udword i=0;i<mNbTris;i++)
192  {
193  GetTriangle(VP, i);
194 
195  if( (VP.Vertex[0]==VP.Vertex[1])
196  || (VP.Vertex[1]==VP.Vertex[2])
197  || (VP.Vertex[2]==VP.Vertex[0])) NbDegenerate++;
198  }
199 
200  return NbDegenerate;
201 }
inline_ RequestCallback Opcode::MeshInterface::GetCallback ( ) const
inline

Definition at line 79 of file Opcode.h.

inline_ udword Opcode::MeshInterface::GetNbVertices ( ) const
inline

Definition at line 62 of file Opcode.h.

Referenced by csOPCODECollider::getNumVertex().

inline_ void Opcode::MeshInterface::GetTriangle ( VertexPointers vp,
udword  index 
) const
inline

Fetches a triangle given a triangle index.

Parameters
vp[out] required triangle's vertex pointers
index[in] triangle index

Definition at line 119 of file Opcode.h.

inline_ void* Opcode::MeshInterface::GetUserData ( ) const
inline

Definition at line 78 of file Opcode.h.

bool MeshInterface::IsValid ( ) const

Checks the mesh interface is valid, i.e. things have been setup correctly.

Returns
true if valid

Definition at line 161 of file OPC_MeshInterface.cpp.

162 {
163  if(!mNbTris || !mNbVerts) return false;
164 #ifdef OPC_USE_CALLBACKS
165  if(!mObjCallback) return false;
166 #else
167  if(!mTris || !mVerts) return false;
168 #endif
169  return true;
170 }
bool MeshInterface::RemapClient ( udword  nb_indices,
const udword permutation 
) const

Remaps client's mesh according to a permutation.

Parameters
nb_indices[in] number of indices in the permutation (will be checked against number of triangles)
permutation[in] list of triangle indices
Returns
true if success

Definition at line 267 of file OPC_MeshInterface.cpp.

268 {
269  // Checkings
270  if(!nb_indices || !permutation) return false;
271  if(nb_indices!=mNbTris) return false;
272 
273 #ifdef OPC_USE_CALLBACKS
274  // We can't really do that using callbacks
275  return false;
276 #else
277  IndexedTriangle* Tmp = new IndexedTriangle[mNbTris];
278  CHECKALLOC(Tmp);
279 
280  #ifdef OPC_USE_STRIDE
281  udword Stride = mTriStride;
282  #else
283  udword Stride = sizeof(IndexedTriangle);
284  #endif
285 
286  for(udword i=0;i<mNbTris;i++)
287  {
288  const IndexedTriangle* T = (const IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
289  Tmp[i] = *T;
290  }
291 
292  for(udword i=0;i<mNbTris;i++)
293  {
294  IndexedTriangle* T = (IndexedTriangle*)(((ubyte*)mTris) + i * Stride);
295  *T = Tmp[permutation[i]];
296  }
297 
298  DELETEARRAY(Tmp);
299 #endif
300  return true;
301 }
bool MeshInterface::SetCallback ( RequestCallback  callback,
void *  user_data 
)

Callback control: setups object callback. Must provide triangle-vertices for a given triangle index.

Parameters
callback[in] user-defined callback
user_data[in] user-defined data
Returns
true if success

Definition at line 212 of file OPC_MeshInterface.cpp.

213 {
214 // if(!callback) return SetIceError("MeshInterface::SetCallback: callback pointer is null");
215  if(!callback) return(false);
216  mObjCallback = callback;
217  mUserData = user_data;
218  return true;
219 }
inline_ void Opcode::MeshInterface::SetNbTriangles ( udword  nb)
inline

Definition at line 63 of file Opcode.h.

inline_ void Opcode::MeshInterface::SetNbVertices ( udword  nb)
inline

Definition at line 64 of file Opcode.h.


The documentation for this class was generated from the following files: