]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/builddeps/linux64/ode/include/ode/collision_trimesh.h
aa8f6245cad9573757f1d5cd2b01903acb0b1df7
[xonotic/xonotic.git] / misc / builddeps / linux64 / ode / include / ode / 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 typedef enum 
49 {
50     dMTV__MIN,
51
52     dMTV_FIRST = dMTV__MIN,
53     dMTV_SECOND,
54     dMTV_THIRD,
55
56     dMTV__MAX,
57
58 } dMeshTriangleVertex;
59
60 /*
61  * These don't make much sense now, but they will later when we add more
62  * features.
63  */
64 ODE_API dTriMeshDataID dGeomTriMeshDataCreate(void);
65 ODE_API void dGeomTriMeshDataDestroy(dTriMeshDataID g);
66
67
68 /*
69  * The values of data_id that can be used with dGeomTriMeshDataSet/dGeomTriMeshDataGet
70  */
71 enum 
72 {
73     dTRIMESHDATA__MIN,
74
75     dTRIMESHDATA_FACE_NORMALS = dTRIMESHDATA__MIN,
76     dTRIMESHDATA_USE_FLAGS,
77
78     dTRIMESHDATA__MAX,
79
80 #ifndef TRIMESH_FACE_NORMALS // Define this name during the header inclusion if you need it for something else
81     // Included for backward compatibility -- please use the corrected name above. Sorry.
82     TRIMESH_FACE_NORMALS = dTRIMESHDATA_FACE_NORMALS,
83 #endif
84 };
85
86 /*
87  * The flags of the dTRIMESHDATA_USE_FLAGS data elements
88  */
89 enum 
90 {
91     dMESHDATAUSE_EDGE1      = 0x01,
92     dMESHDATAUSE_EDGE2      = 0x02,
93     dMESHDATAUSE_EDGE3      = 0x04,
94     dMESHDATAUSE_VERTEX1    = 0x08,
95     dMESHDATAUSE_VERTEX2    = 0x10,
96     dMESHDATAUSE_VERTEX3    = 0x20,
97 };
98
99 /*
100  *      Set and get the TriMeshData additional data
101  * Note: The data is NOT COPIED on assignment
102  */
103 ODE_API void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void *in_data);
104 ODE_API void *dGeomTriMeshDataGet(dTriMeshDataID g, int data_id);
105 ODE_API void *dGeomTriMeshDataGet2(dTriMeshDataID g, int data_id, dsizeint *pout_size/*=NULL*/);
106
107
108
109 /**
110  * We need to set the last transform after each time step for 
111  * accurate collision response. These functions get and set that transform.
112  * It is stored per geom instance, rather than per dTriMeshDataID.
113  */
114 ODE_API void dGeomTriMeshSetLastTransform( dGeomID g, const dMatrix4 last_trans );
115 ODE_API const dReal* dGeomTriMeshGetLastTransform( dGeomID g );
116
117 /*
118  * Build a TriMesh data object with single precision vertex data.
119  */
120 ODE_API void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
121                                  const void* Vertices, int VertexStride, int VertexCount, 
122                                  const void* Indices, int IndexCount, int TriStride);
123 /* same again with a normals array (used as trimesh-trimesh optimization) */
124 ODE_API void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
125                                   const void* Vertices, int VertexStride, int VertexCount, 
126                                   const void* Indices, int IndexCount, int TriStride,
127                                   const void* Normals);
128 /*
129 * Build a TriMesh data object with double precision vertex data.
130 */
131 ODE_API void dGeomTriMeshDataBuildDouble(dTriMeshDataID g, 
132                                  const void* Vertices,  int VertexStride, int VertexCount, 
133                                  const void* Indices, int IndexCount, int TriStride);
134 /* same again with a normals array (used as trimesh-trimesh optimization) */
135 ODE_API void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g, 
136                                   const void* Vertices,  int VertexStride, int VertexCount, 
137                                   const void* Indices, int IndexCount, int TriStride,
138                                   const void* Normals);
139
140 /*
141  * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
142  */
143 ODE_API void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
144                                  const dReal* Vertices, int VertexCount,
145                                  const dTriIndex* Indices, int IndexCount);
146 /* same again with a normals array (used as trimesh-trimesh optimization) */
147 ODE_API void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
148                                   const dReal* Vertices, int VertexCount,
149                                   const dTriIndex* Indices, int IndexCount,
150                                   const int* Normals);
151
152
153 /*
154  * Data preprocessing build request flags.
155  */
156 enum
157 {
158     dTRIDATAPREPROCESS_BUILD__MIN,
159
160     dTRIDATAPREPROCESS_BUILD_CONCAVE_EDGES = dTRIDATAPREPROCESS_BUILD__MIN, // Used to optimize OPCODE trimesh-capsule collisions; allocates 1 byte per triangle; no extra data associated
161     dTRIDATAPREPROCESS_BUILD_FACE_ANGLES,   // Used to aid trimesh-convex collisions; memory requirements depend on extra data
162     
163     dTRIDATAPREPROCESS_BUILD__MAX,
164 };
165
166 /*
167  * Data preprocessing extra values for dTRIDATAPREPROCESS_BUILD_FACE_ANGLES.
168  */
169 enum 
170 {
171     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA__MIN,
172
173     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA_BYTE_POSITIVE = dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA__MIN, // Build angles for convex edges only and store as bytes; allocates 3 bytes per triangle; stores angles (0..180] in 1/254 fractions leaving two values for the flat and all the concaves
174     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA_BYTE_ALL, // Build angles for all the edges and store in bytes; allocates 3 bytes per triangle; stores angles [-180..0) and (0..180] in 1/127 fractions plus a value for the flat angle
175     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA_WORD_ALL, // Build angles for all the edges and store in words; allocates 6 bytes per triangle; stores angles [-180..0) and (0..180] in 1/32767 fractions plus a value for the flat angle
176
177     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA__MAX,
178
179     dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA__DEFAULT = dTRIDATAPREPROCESS_FACE_ANGLES_EXTRA_BYTE_POSITIVE, // The default value assumed if the extra data is not provided
180 };
181
182
183 /*
184  * Pre-process the trimesh data according to the request flags.
185  *
186  * buildRequestFlags is a bitmask of 1U << dTRIDATAPREPROCESS_BUILD_...
187  * It is allowed to call the function multiple times provided the bitmasks are different each time.
188  *
189  * requestExtraData is an optional pointer to array of extra parameters per bitmask bits 
190  * (only the elements indexed by positions of raised bits are examined; 
191  * defaults are assumed if the pointer is NULL)
192  *
193  * The function returns a boolean status the only failure reason being insufficient memory.
194  */
195 ODE_API int dGeomTriMeshDataPreprocess2(dTriMeshDataID g, unsigned int buildRequestFlags, const dintptr *requestExtraData/*=NULL | const dintptr (*)[dTRIDATAPREPROCESS_BUILD__MAX]*/);
196
197 /*
198  * Obsolete. Equivalent to calling dGeomTriMeshDataPreprocess2(g, (1U << dTRIDATAPREPROCESS_BUILD_CONCAVE_EDGES), NULL)
199  */
200 ODE_API int dGeomTriMeshDataPreprocess(dTriMeshDataID g);
201
202
203
204 /*
205  * Get and set the internal preprocessed trimesh data buffer (see the enumerated type above), for loading and saving 
206  * These functions are deprecated. Use dGeomTriMeshDataSet/dGeomTriMeshDataGet2 with dTRIMESHDATA_USE_FLAGS instead.
207  */
208 ODE_API_DEPRECATED ODE_API void dGeomTriMeshDataGetBuffer(dTriMeshDataID g, unsigned char** buf, int* bufLen);
209 ODE_API_DEPRECATED ODE_API void dGeomTriMeshDataSetBuffer(dTriMeshDataID g, unsigned char* buf);
210
211
212 /*
213  * Per triangle callback. Allows the user to say if he wants a collision with
214  * a particular triangle.
215  */
216 typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
217 ODE_API void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
218 ODE_API dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
219
220 /*
221  * Per object callback. Allows the user to get the list of triangles in 1
222  * shot. Maybe we should remove this one.
223  */
224 typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
225 ODE_API void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
226 ODE_API dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
227
228 /*
229  * Ray callback.
230  * Allows the user to say if a ray collides with a triangle on barycentric
231  * coords. The user can for example sample a texture with alpha transparency
232  * to determine if a collision should occur.
233  */
234 typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
235 ODE_API void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
236 ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
237
238 /*
239  * Triangle merging callback.
240  * Allows the user to generate a fake triangle index for a new contact generated
241  * from merging of two other contacts. That index could later be used by the 
242  * user to determine attributes of original triangles used as sources for a 
243  * merged contact.
244  */
245 typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex);
246 ODE_API void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback);
247 ODE_API dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g);
248
249 /*
250  * Trimesh class
251  * Construction. Callbacks are optional.
252  */
253 ODE_API dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
254
255 ODE_API void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
256 ODE_API dTriMeshDataID dGeomTriMeshGetData(dGeomID g);
257
258
259 /* enable/disable/check temporal coherence*/
260 ODE_API void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
261 ODE_API int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
262
263 /*
264  * Clears the internal temporal coherence caches. When a geom has its
265  * collision checked with a trimesh once, data is stored inside the trimesh.
266  * With large worlds with lots of seperate objects this list could get huge.
267  * We should be able to do this automagically.
268  */
269 ODE_API void dGeomTriMeshClearTCCache(dGeomID g);
270
271
272 /*
273  * returns the TriMeshDataID
274  */
275 ODE_API dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
276
277 /*
278  * Gets a triangle.
279  */
280 ODE_API void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
281
282 /*
283  * Gets the point on the requested triangle and the given barycentric
284  * coordinates.
285  */
286 ODE_API void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
287
288 /*
289
290 This is how the strided data works:
291
292 struct StridedVertex{
293         dVector3 Vertex;
294         // Userdata
295 };
296 int VertexStride = sizeof(StridedVertex);
297
298 struct StridedTri{
299         int Indices[3];
300         // Userdata
301 };
302 int TriStride = sizeof(StridedTri);
303
304 */
305
306
307 ODE_API int dGeomTriMeshGetTriangleCount (dGeomID g);
308
309 ODE_API void dGeomTriMeshDataUpdate(dTriMeshDataID g);
310
311 #ifdef __cplusplus
312 }
313 #endif
314
315 #endif  /* _ODE_COLLISION_TRIMESH_H_ */
316