collision_trimesh.h

00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith.       *
00004  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
00005  *                                                                       *
00006  * This library is free software; you can redistribute it and/or         *
00007  * modify it under the terms of EITHER:                                  *
00008  *   (1) The GNU Lesser General Public License as published by the Free  *
00009  *       Software Foundation; either version 2.1 of the License, or (at  *
00010  *       your option) any later version. The text of the GNU Lesser      *
00011  *       General Public License is included with this library in the     *
00012  *       file LICENSE.TXT.                                               *
00013  *   (2) The BSD-style license that is included with this library in     *
00014  *       the file LICENSE-BSD.TXT.                                       *
00015  *                                                                       *
00016  * This library is distributed in the hope that it will be useful,       *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00019  * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
00020  *                                                                       *
00021  *************************************************************************/
00022 
00023 /*
00024  * TriMesh code by Erwin de Vries.
00025  *
00026  * Trimesh data.
00027  * This is where the actual vertexdata (pointers), and BV tree is stored.
00028  * Vertices should be single precision!
00029  * This should be more sophisticated, so that the user can easyly implement
00030  * another collision library, but this is a lot of work, and also costs some
00031  * performance because some data has to be copied.
00032  */
00033 
00034 #ifndef _ODE_COLLISION_TRIMESH_H_
00035 #define _ODE_COLLISION_TRIMESH_H_
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 /*
00042  * Data storage for triangle meshes.
00043  */
00044 struct dxTriMeshData;
00045 typedef struct dxTriMeshData* dTriMeshDataID;
00046 
00047 /*
00048  * These dont make much sense now, but they will later when we add more
00049  * features.
00050  */
00051 ODE_API dTriMeshDataID dGeomTriMeshDataCreate(void);
00052 ODE_API void dGeomTriMeshDataDestroy(dTriMeshDataID g);
00053 
00054 
00055 
00056 enum { TRIMESH_FACE_NORMALS };
00057 ODE_API void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void* in_data);
00058 ODE_API void* dGeomTriMeshDataGet(dTriMeshDataID g, int data_id);
00059 
00060 
00061 
00067 ODE_API void dGeomTriMeshSetLastTransform( dGeomID g, dMatrix4 last_trans );
00068 ODE_API dReal* dGeomTriMeshGetLastTransform( dGeomID g );
00069 
00070 /*
00071  * Build TriMesh data with single precision used in vertex data .
00072  */
00073 ODE_API void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
00074                                  const void* Vertices, int VertexStride, int VertexCount, 
00075                                  const void* Indices, int IndexCount, int TriStride);
00076 /* same again with a normals array (used as trimesh-trimesh optimization) */
00077 ODE_API void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
00078                                   const void* Vertices, int VertexStride, int VertexCount, 
00079                                   const void* Indices, int IndexCount, int TriStride,
00080                                   const void* Normals);
00081 /*
00082 * Build TriMesh data with double pricision used in vertex data .
00083 */
00084 ODE_API void dGeomTriMeshDataBuildDouble(dTriMeshDataID g, 
00085                                  const void* Vertices,  int VertexStride, int VertexCount, 
00086                                  const void* Indices, int IndexCount, int TriStride);
00087 /* same again with a normals array (used as trimesh-trimesh optimization) */
00088 ODE_API void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g, 
00089                                   const void* Vertices,  int VertexStride, int VertexCount, 
00090                                   const void* Indices, int IndexCount, int TriStride,
00091                                   const void* Normals);
00092 
00093 /*
00094  * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
00095  */
00096 ODE_API void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
00097                                  const dReal* Vertices, int VertexCount,
00098                                  const int* Indices, int IndexCount);
00099 /* same again with a normals array (used as trimesh-trimesh optimization) */
00100 ODE_API void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
00101                                   const dReal* Vertices, int VertexCount,
00102                                   const int* Indices, int IndexCount,
00103                                   const int* Normals);
00104 
00105 /* Preprocess the trimesh data to remove mark unnecessary edges and vertices */
00106 ODE_API void dGeomTriMeshDataPreprocess(dTriMeshDataID g);
00107 /* Get and set the internal preprocessed trimesh data buffer, for loading and saving */
00108 ODE_API void dGeomTriMeshDataGetBuffer(dTriMeshDataID g, unsigned char** buf, int* bufLen);
00109 ODE_API void dGeomTriMeshDataSetBuffer(dTriMeshDataID g, unsigned char* buf);
00110 
00111 
00112 /*
00113  * Per triangle callback. Allows the user to say if he wants a collision with
00114  * a particular triangle.
00115  */
00116 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
00117 ODE_API void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
00118 ODE_API dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
00119 
00120 /*
00121  * Per object callback. Allows the user to get the list of triangles in 1
00122  * shot. Maybe we should remove this one.
00123  */
00124 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
00125 ODE_API void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
00126 ODE_API dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
00127 
00128 /*
00129  * Ray callback.
00130  * Allows the user to say if a ray collides with a triangle on barycentric
00131  * coords. The user can for example sample a texture with alpha transparency
00132  * to determine if a collision should occur.
00133  */
00134 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
00135 ODE_API void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
00136 ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
00137 
00138 /*
00139  * Trimesh class
00140  * Construction. Callbacks are optional.
00141  */
00142 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
00143 
00144 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
00145 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g);
00146 
00147 
00148 // enable/disable/check temporal coherence
00149 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
00150 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
00151 
00152 /*
00153  * Clears the internal temporal coherence caches. When a geom has its
00154  * collision checked with a trimesh once, data is stored inside the trimesh.
00155  * With large worlds with lots of seperate objects this list could get huge.
00156  * We should be able to do this automagically.
00157  */
00158 ODE_API void dGeomTriMeshClearTCCache(dGeomID g);
00159 
00160 
00161 /*
00162  * returns the TriMeshDataID
00163  */
00164 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
00165 
00166 /*
00167  * Gets a triangle.
00168  */
00169 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
00170 
00171 /*
00172  * Gets the point on the requested triangle and the given barycentric
00173  * coordinates.
00174  */
00175 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
00176 
00177 /*
00178 
00179 This is how the strided data works:
00180 
00181 struct StridedVertex{
00182    dVector3 Vertex;
00183    // Userdata
00184 };
00185 int VertexStride = sizeof(StridedVertex);
00186 
00187 struct StridedTri{
00188    int Indices[3];
00189    // Userdata
00190 };
00191 int TriStride = sizeof(StridedTri);
00192 
00193 */
00194 
00195 
00196 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g);
00197 
00198 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g);
00199 
00200 #ifdef __cplusplus
00201 }
00202 #endif
00203 
00204 #endif   /* _ODE_COLLISION_TRIMESH_H_ */
00205 

Generated on Fri Oct 12 08:36:51 2007 for Open Dynamics Engine by  doxygen 1.5.3