- Main Page
- Modules
- Data Structures
- Files

# 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 enum { TRIMESH_FACE_NORMALS, TRIMESH_LAST_TRANSFORMATION };
    00055 ODE_API void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void* in_data);
    00056 ODE_API void* dGeomTriMeshDataGet(dTriMeshDataID g, int data_id);
    00057
    00058 /*
    00059  * Build TriMesh data with single pricision used in vertex data .
    00060  */
    00061 ODE_API void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
    00062                                  const void* Vertices, int VertexStride, int VertexCount,
    00063                                  const void* Indices, int IndexCount, int TriStride);
    00064 /* same again with a normals array (used as trimesh-trimesh optimization) */
    00065 ODE_API void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
    00066                                   const void* Vertices, int VertexStride, int VertexCount,
    00067                                   const void* Indices, int IndexCount, int TriStride,
    00068                                   const void* Normals);
    00069 /*
    00070 * Build TriMesh data with double pricision used in vertex data .
    00071 */
    00072 ODE_API void dGeomTriMeshDataBuildDouble(dTriMeshDataID g,
    00073                                  const void* Vertices,  int VertexStride, int VertexCount,
    00074                                  const void* Indices, int IndexCount, int TriStride);
    00075 /* same again with a normals array (used as trimesh-trimesh optimization) */
    00076 ODE_API void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g,
    00077                                   const void* Vertices,  int VertexStride, int VertexCount,
    00078                                   const void* Indices, int IndexCount, int TriStride,
    00079                                   const void* Normals);
    00080
    00081 /*
    00082  * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
    00083  */
    00084 ODE_API void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
    00085                                  const dReal* Vertices, int VertexCount,
    00086                                  const int* Indices, int IndexCount);
    00087 /* same again with a normals array (used as trimesh-trimesh optimization) */
    00088 ODE_API void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
    00089                                   const dReal* Vertices, int VertexCount,
    00090                                   const int* Indices, int IndexCount,
    00091                                   const int* Normals);
    00092
    00093 /* Preprocess the trimesh data to remove mark unnecessary edges and vertices */
    00094 ODE_API void dGeomTriMeshDataPreprocess(dTriMeshDataID g);
    00095 /* Get and set the internal preprocessed trimesh data buffer, for loading and saving */
    00096 ODE_API void dGeomTriMeshDataGetBuffer(dTriMeshDataID g, unsigned char** buf, int* bufLen);
    00097 ODE_API void dGeomTriMeshDataSetBuffer(dTriMeshDataID g, unsigned char* buf);
    00098
    00099
    00100 /*
    00101  * Per triangle callback. Allows the user to say if he wants a collision with
    00102  * a particular triangle.
    00103  */
    00104 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
    00105 ODE_API void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
    00106 ODE_API dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
    00107
    00108 /*
    00109  * Per object callback. Allows the user to get the list of triangles in 1
    00110  * shot. Maybe we should remove this one.
    00111  */
    00112 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
    00113 ODE_API void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
    00114 ODE_API dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
    00115
    00116 /*
    00117  * Ray callback.
    00118  * Allows the user to say if a ray collides with a triangle on barycentric
    00119  * coords. The user can for example sample a texture with alpha transparency
    00120  * to determine if a collision should occur.
    00121  */
    00122 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
    00123 ODE_API void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
    00124 ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
    00125
    00126 /*
    00127  * Trimesh class
    00128  * Construction. Callbacks are optional.
    00129  */
    00130 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
    00131
    00132 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
    00133 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g);
    00134
    00135
    00136 // enable/disable/check temporal coherence
    00137 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
    00138 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
    00139
    00140 /*
    00141  * Clears the internal temporal coherence caches. When a geom has its
    00142  * collision checked with a trimesh once, data is stored inside the trimesh.
    00143  * With large worlds with lots of seperate objects this list could get huge.
    00144  * We should be able to do this automagically.
    00145  */
    00146 ODE_API void dGeomTriMeshClearTCCache(dGeomID g);
    00147
    00148
    00149 /*
    00150  * returns the TriMeshDataID
    00151  */
    00152 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
    00153
    00154 /*
    00155  * Gets a triangle.
    00156  */
    00157 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
    00158
    00159 /*
    00160  * Gets the point on the requested triangle and the given barycentric
    00161  * coordinates.
    00162  */
    00163 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
    00164
    00165 /*
    00166
    00167 This is how the strided data works:
    00168
    00169 struct StridedVertex{
    00170    dVector3 Vertex;
    00171    // Userdata
    00172 };
    00173 int VertexStride = sizeof(StridedVertex);
    00174
    00175 struct StridedTri{
    00176    int Indices[3];
    00177    // Userdata
    00178 };
    00179 int TriStride = sizeof(StridedTri);
    00180
    00181 */
    00182
    00183
    00184 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g);
    00185
    00186 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g);
    00187
    00188 #ifdef __cplusplus
    00189 }
    00190 #endif
    00191
    00192 #endif   /* _ODE_COLLISION_TRIMESH_H_ */
    00193