ODE  0.13.1
 All Data Structures Functions Variables Typedefs Enumerations Groups
collision_trimesh.h
1 /*************************************************************************
2  * *
3  * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4  * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of EITHER: *
8  * (1) The GNU Lesser General Public License as published by the Free *
9  * Software Foundation; either version 2.1 of the License, or (at *
10  * your option) any later version. The text of the GNU Lesser *
11  * General Public License is included with this library in the *
12  * file LICENSE.TXT. *
13  * (2) The BSD-style license that is included with this library in *
14  * the file LICENSE-BSD.TXT. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19  * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20  * *
21  *************************************************************************/
22 
23 /*
24  * TriMesh code by Erwin de Vries.
25  *
26  * Trimesh data.
27  * This is where the actual vertexdata (pointers), and BV tree is stored.
28  * Vertices should be single precision!
29  * This should be more sophisticated, so that the user can easyly implement
30  * another collision library, but this is a lot of work, and also costs some
31  * performance because some data has to be copied.
32  */
33 
34 #ifndef _ODE_COLLISION_TRIMESH_H_
35 #define _ODE_COLLISION_TRIMESH_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Data storage for triangle meshes.
43  */
44 struct dxTriMeshData;
45 typedef struct dxTriMeshData* dTriMeshDataID;
46 
47 /*
48  * These dont make much sense now, but they will later when we add more
49  * features.
50  */
51 ODE_API dTriMeshDataID dGeomTriMeshDataCreate(void);
52 ODE_API void dGeomTriMeshDataDestroy(dTriMeshDataID g);
53 
54 
55 
56 enum { TRIMESH_FACE_NORMALS };
57 ODE_API void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void* in_data);
58 ODE_API void* dGeomTriMeshDataGet(dTriMeshDataID g, int data_id);
59 
60 
61 
67 ODE_API void dGeomTriMeshSetLastTransform( dGeomID g, dMatrix4 last_trans );
68 ODE_API dReal* dGeomTriMeshGetLastTransform( dGeomID g );
69 
70 /*
71  * Build a TriMesh data object with single precision vertex data.
72  */
73 ODE_API void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
74  const void* Vertices, int VertexStride, int VertexCount,
75  const void* Indices, int IndexCount, int TriStride);
76 /* same again with a normals array (used as trimesh-trimesh optimization) */
77 ODE_API void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
78  const void* Vertices, int VertexStride, int VertexCount,
79  const void* Indices, int IndexCount, int TriStride,
80  const void* Normals);
81 /*
82 * Build a TriMesh data object with double precision vertex data.
83 */
84 ODE_API void dGeomTriMeshDataBuildDouble(dTriMeshDataID g,
85  const void* Vertices, int VertexStride, int VertexCount,
86  const void* Indices, int IndexCount, int TriStride);
87 /* same again with a normals array (used as trimesh-trimesh optimization) */
88 ODE_API void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g,
89  const void* Vertices, int VertexStride, int VertexCount,
90  const void* Indices, int IndexCount, int TriStride,
91  const void* Normals);
92 
93 /*
94  * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
95  */
96 ODE_API void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
97  const dReal* Vertices, int VertexCount,
98  const dTriIndex* Indices, int IndexCount);
99 /* same again with a normals array (used as trimesh-trimesh optimization) */
100 ODE_API void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
101  const dReal* Vertices, int VertexCount,
102  const dTriIndex* Indices, int IndexCount,
103  const int* Normals);
104 
105 /* Preprocess the trimesh data to remove mark unnecessary edges and vertices */
106 ODE_API void dGeomTriMeshDataPreprocess(dTriMeshDataID g);
107 /* Get and set the internal preprocessed trimesh data buffer, for loading and saving */
108 ODE_API void dGeomTriMeshDataGetBuffer(dTriMeshDataID g, unsigned char** buf, int* bufLen);
109 ODE_API void dGeomTriMeshDataSetBuffer(dTriMeshDataID g, unsigned char* buf);
110 
111 
112 /*
113  * Per triangle callback. Allows the user to say if he wants a collision with
114  * a particular triangle.
115  */
116 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
117 ODE_API void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
118 ODE_API dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
119 
120 /*
121  * Per object callback. Allows the user to get the list of triangles in 1
122  * shot. Maybe we should remove this one.
123  */
124 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
125 ODE_API void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
126 ODE_API dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
127 
128 /*
129  * Ray callback.
130  * Allows the user to say if a ray collides with a triangle on barycentric
131  * coords. The user can for example sample a texture with alpha transparency
132  * to determine if a collision should occur.
133  */
134 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
135 ODE_API void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
136 ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
137 
138 /*
139  * Triangle merging callback.
140  * Allows the user to generate a fake triangle index for a new contact generated
141  * from merging of two other contacts. That index could later be used by the
142  * user to determine attributes of original triangles used as sources for a
143  * merged contact.
144  */
145 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex);
146 ODE_API void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback);
147 ODE_API dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g);
148 
149 /*
150  * Trimesh class
151  * Construction. Callbacks are optional.
152  */
153 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
154 
155 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
156 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g);
157 
158 
159 /* enable/disable/check temporal coherence*/
160 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
161 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
162 
163 /*
164  * Clears the internal temporal coherence caches. When a geom has its
165  * collision checked with a trimesh once, data is stored inside the trimesh.
166  * With large worlds with lots of seperate objects this list could get huge.
167  * We should be able to do this automagically.
168  */
169 ODE_API void dGeomTriMeshClearTCCache(dGeomID g);
170 
171 
172 /*
173  * returns the TriMeshDataID
174  */
175 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
176 
177 /*
178  * Gets a triangle.
179  */
180 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
181 
182 /*
183  * Gets the point on the requested triangle and the given barycentric
184  * coordinates.
185  */
186 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
187 
188 /*
189 
190 This is how the strided data works:
191 
192 struct StridedVertex{
193  dVector3 Vertex;
194  // Userdata
195 };
196 int VertexStride = sizeof(StridedVertex);
197 
198 struct StridedTri{
199  int Indices[3];
200  // Userdata
201 };
202 int TriStride = sizeof(StridedTri);
203 
204 */
205 
206 
207 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g);
208 
209 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g);
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif /* _ODE_COLLISION_TRIMESH_H_ */
216