[1809] | 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 | dTriMeshDataID dGeomTriMeshDataCreate();
|
---|
| 52 | void dGeomTriMeshDataDestroy(dTriMeshDataID g);
|
---|
| 53 |
|
---|
| 54 | enum { TRIMESH_FACE_NORMALS, TRIMESH_LAST_TRANSFORMATION };
|
---|
| 55 | void dGeomTriMeshDataSet(dTriMeshDataID g, int data_id, void* data);
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | /*
|
---|
| 59 | * Build TriMesh data with single pricision used in vertex data .
|
---|
| 60 | */
|
---|
| 61 | void dGeomTriMeshDataBuildSingle(dTriMeshDataID g,
|
---|
| 62 | const void* Vertices, int VertexStride, int VertexCount,
|
---|
| 63 | const void* Indices, int IndexCount, int TriStride);
|
---|
| 64 | /* same again with a normals array (used as trimesh-trimesh optimization) */
|
---|
| 65 | void dGeomTriMeshDataBuildSingle1(dTriMeshDataID g,
|
---|
| 66 | const void* Vertices, int VertexStride, int VertexCount,
|
---|
| 67 | const void* Indices, int IndexCount, int TriStride,
|
---|
| 68 | const void* Normals);
|
---|
| 69 | /*
|
---|
| 70 | * Build TriMesh data with double pricision used in vertex data .
|
---|
| 71 | */
|
---|
| 72 | void dGeomTriMeshDataBuildDouble(dTriMeshDataID g,
|
---|
| 73 | const void* Vertices, int VertexStride, int VertexCount,
|
---|
| 74 | const void* Indices, int IndexCount, int TriStride);
|
---|
| 75 | /* same again with a normals array (used as trimesh-trimesh optimization) */
|
---|
| 76 | void dGeomTriMeshDataBuildDouble1(dTriMeshDataID g,
|
---|
| 77 | const void* Vertices, int VertexStride, int VertexCount,
|
---|
| 78 | const void* Indices, int IndexCount, int TriStride,
|
---|
| 79 | const void* Normals);
|
---|
| 80 |
|
---|
| 81 | /*
|
---|
| 82 | * Simple build. Single/double precision based on dSINGLE/dDOUBLE!
|
---|
| 83 | */
|
---|
| 84 | void dGeomTriMeshDataBuildSimple(dTriMeshDataID g,
|
---|
| 85 | const dReal* Vertices, int VertexCount,
|
---|
| 86 | const int* Indices, int IndexCount);
|
---|
| 87 | /* same again with a normals array (used as trimesh-trimesh optimization) */
|
---|
| 88 | void dGeomTriMeshDataBuildSimple1(dTriMeshDataID g,
|
---|
| 89 | const dReal* Vertices, int VertexCount,
|
---|
| 90 | const int* Indices, int IndexCount,
|
---|
| 91 | const int* Normals);
|
---|
| 92 | /*
|
---|
| 93 | * Per triangle callback. Allows the user to say if he wants a collision with
|
---|
| 94 | * a particular triangle.
|
---|
| 95 | */
|
---|
| 96 | typedef int dTriCallback(dGeomID TriMesh, dGeomID RefObject, int TriangleIndex);
|
---|
| 97 | void dGeomTriMeshSetCallback(dGeomID g, dTriCallback* Callback);
|
---|
| 98 | dTriCallback* dGeomTriMeshGetCallback(dGeomID g);
|
---|
| 99 |
|
---|
| 100 | /*
|
---|
| 101 | * Per object callback. Allows the user to get the list of triangles in 1
|
---|
| 102 | * shot. Maybe we should remove this one.
|
---|
| 103 | */
|
---|
| 104 | typedef void dTriArrayCallback(dGeomID TriMesh, dGeomID RefObject, const int* TriIndices, int TriCount);
|
---|
| 105 | void dGeomTriMeshSetArrayCallback(dGeomID g, dTriArrayCallback* ArrayCallback);
|
---|
| 106 | dTriArrayCallback* dGeomTriMeshGetArrayCallback(dGeomID g);
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | * Ray callback.
|
---|
| 110 | * Allows the user to say if a ray collides with a triangle on barycentric
|
---|
| 111 | * coords. The user can for example sample a texture with alpha transparency
|
---|
| 112 | * to determine if a collision should occur.
|
---|
| 113 | */
|
---|
| 114 | typedef int dTriRayCallback(dGeomID TriMesh, dGeomID Ray, int TriangleIndex, dReal u, dReal v);
|
---|
| 115 | void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback);
|
---|
| 116 | dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g);
|
---|
| 117 |
|
---|
| 118 | /*
|
---|
| 119 | * Trimesh class
|
---|
| 120 | * Construction. Callbacks are optional.
|
---|
| 121 | */
|
---|
| 122 | dGeomID dCreateTriMesh(dSpaceID space, dTriMeshDataID Data, dTriCallback* Callback, dTriArrayCallback* ArrayCallback, dTriRayCallback* RayCallback);
|
---|
| 123 |
|
---|
| 124 | void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data);
|
---|
| 125 |
|
---|
| 126 | // enable/disable/check temporal coherence
|
---|
| 127 | void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable);
|
---|
| 128 | int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass);
|
---|
| 129 |
|
---|
| 130 | /*
|
---|
| 131 | * Clears the internal temporal coherence caches. When a geom has its
|
---|
| 132 | * collision checked with a trimesh once, data is stored inside the trimesh.
|
---|
| 133 | * With large worlds with lots of seperate objects this list could get huge.
|
---|
| 134 | * We should be able to do this automagically.
|
---|
| 135 | */
|
---|
| 136 | void dGeomTriMeshClearTCCache(dGeomID g);
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | /*
|
---|
| 140 | * returns the TriMeshDataID
|
---|
| 141 | */
|
---|
| 142 | dTriMeshDataID dGeomTriMeshGetTriMeshDataID(dGeomID g);
|
---|
| 143 |
|
---|
| 144 | /*
|
---|
| 145 | * Gets a triangle.
|
---|
| 146 | */
|
---|
| 147 | void dGeomTriMeshGetTriangle(dGeomID g, int Index, dVector3* v0, dVector3* v1, dVector3* v2);
|
---|
| 148 |
|
---|
| 149 | /*
|
---|
| 150 | * Gets the point on the requested triangle and the given barycentric
|
---|
| 151 | * coordinates.
|
---|
| 152 | */
|
---|
| 153 | void dGeomTriMeshGetPoint(dGeomID g, int Index, dReal u, dReal v, dVector3 Out);
|
---|
| 154 |
|
---|
| 155 | /*
|
---|
| 156 |
|
---|
| 157 | This is how the strided data works:
|
---|
| 158 |
|
---|
| 159 | struct StridedVertex{
|
---|
| 160 | dVector3 Vertex;
|
---|
| 161 | // Userdata
|
---|
| 162 | };
|
---|
| 163 | int VertexStride = sizeof(StridedVertex);
|
---|
| 164 |
|
---|
| 165 | struct StridedTri{
|
---|
| 166 | int Indices[3];
|
---|
| 167 | // Userdata
|
---|
| 168 | };
|
---|
| 169 | int TriStride = sizeof(StridedTri);
|
---|
| 170 |
|
---|
| 171 | */
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | #ifdef __cplusplus
|
---|
| 177 | }
|
---|
| 178 | #endif
|
---|
| 179 |
|
---|
| 180 | #endif /* _ODE_COLLISION_TRIMESH_H_ */
|
---|
| 181 |
|
---|