Open Dynamics Engine
|
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 a TriMesh data object with single precision 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 a TriMesh data object with double precision 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 dTriIndex* 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 dTriIndex* 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 * Triangle merging callback. 00140 * Allows the user to generate a fake triangle index for a new contact generated 00141 * from merging of two other contacts. That index could later be used by the 00142 * user to determine attributes of original triangles used as sources for a 00143 * merged contact. 00144 */ 00145 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex); 00146 ODE_API void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback); 00147 ODE_API dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g); 00148 00149 /* 00150 * Trimesh class 00151 * Construction. Callbacks are optional. 00152 */ 00153 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback); 00154 00155 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data); 00156 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g); 00157 00158 00159 // enable/disable/check temporal coherence 00160 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable); 00161 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass); 00162 00163 /* 00164 * Clears the internal temporal coherence caches. When a geom has its 00165 * collision checked with a trimesh once, data is stored inside the trimesh. 00166 * With large worlds with lots of seperate objects this list could get huge. 00167 * We should be able to do this automagically. 00168 */ 00169 ODE_API void dGeomTriMeshClearTCCache(dGeomID g); 00170 00171 00172 /* 00173 * returns the TriMeshDataID 00174 */ 00175 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g); 00176 00177 /* 00178 * Gets a triangle. 00179 */ 00180 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2); 00181 00182 /* 00183 * Gets the point on the requested triangle and the given barycentric 00184 * coordinates. 00185 */ 00186 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out); 00187 00188 /* 00189 00190 This is how the strided data works: 00191 00192 struct StridedVertex{ 00193 dVector3 Vertex; 00194 // Userdata 00195 }; 00196 int VertexStride = sizeof(StridedVertex); 00197 00198 struct StridedTri{ 00199 int Indices[3]; 00200 // Userdata 00201 }; 00202 int TriStride = sizeof(StridedTri); 00203 00204 */ 00205 00206 00207 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g); 00208 00209 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g); 00210 00211 #ifdef __cplusplus 00212 } 00213 #endif 00214 00215 #endif /* _ODE_COLLISION_TRIMESH_H_ */ 00216