1 | #ifndef NX_COLLISION_NXTRIANGLEMESHDESC
|
---|
2 | #define NX_COLLISION_NXTRIANGLEMESHDESC
|
---|
3 | /*----------------------------------------------------------------------------*\
|
---|
4 | |
|
---|
5 | | Public Interface to NovodeX Technology
|
---|
6 | |
|
---|
7 | | www.novodex.com
|
---|
8 | |
|
---|
9 | \*----------------------------------------------------------------------------*/
|
---|
10 | /** \addtogroup physics
|
---|
11 | @{
|
---|
12 | */
|
---|
13 |
|
---|
14 | #include "NxTriangleMesh.h"
|
---|
15 | #include "NxSimpleTriangleMesh.h"
|
---|
16 |
|
---|
17 | /**
|
---|
18 | \brief Descriptor class for #NxTriangleMesh.
|
---|
19 |
|
---|
20 | Note that this class is derived from NxSimpleTriangleMesh which contains the members that describe the basic mesh.
|
---|
21 | The mesh data is *copied* when an NxTriangleMesh object is created from this descriptor. After the call the
|
---|
22 | user may discard the triangle data.
|
---|
23 |
|
---|
24 | @see NxTriangleMesh NxTriangleMeshShape
|
---|
25 | */
|
---|
26 | class NxTriangleMeshDesc : public NxSimpleTriangleMesh
|
---|
27 | {
|
---|
28 | public:
|
---|
29 | /**
|
---|
30 | If materialIndices is NULL (not used) then this should be zero. Otherwise this is the
|
---|
31 | offset between material indices in bytes. This is at least sizeof(NxMaterialIndex).
|
---|
32 |
|
---|
33 | <b>Default:</b> 0
|
---|
34 |
|
---|
35 | <b>Platform:</b>
|
---|
36 | \li PC SW: Yes
|
---|
37 | \li PPU : No
|
---|
38 | \li PS3 : Yes
|
---|
39 | \li XB360: Yes
|
---|
40 |
|
---|
41 | @see materialIndices
|
---|
42 | */
|
---|
43 | NxU32 materialIndexStride;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | Optional pointer to first material index, or NULL. There are NxSimpleTriangleMesh::numTriangles indices in total.
|
---|
47 | Caller may add materialIndexStride bytes to the pointer to access the next triangle.
|
---|
48 |
|
---|
49 | When a triangle mesh collides with another object, a material is required at the collision point.
|
---|
50 | If materialIndices is NULL, then the material of the NxTriangleMeshShape instance (specified via NxShapeDesc::materialIndex) is used.
|
---|
51 | Otherwise, if the point of contact is on a triangle with index i, then the material index is determined as:
|
---|
52 | NxMaterialIndex index = *(NxMaterialIndex *)(((NxU8*)materialIndices) + materialIndexStride * i);
|
---|
53 |
|
---|
54 | If the contact point falls on a vertex or an edge, a triangle adjacent to the vertex or edge is selected, and its index
|
---|
55 | used to look up a material. The selection is arbitrary but consistent over time.
|
---|
56 |
|
---|
57 | <b>Default:</b> NULL
|
---|
58 |
|
---|
59 | <b>Platform:</b>
|
---|
60 | \li PC SW: Yes
|
---|
61 | \li PPU : No
|
---|
62 | \li PS3 : Yes
|
---|
63 | \li XB360: Yes
|
---|
64 |
|
---|
65 | @see materialIndexStride
|
---|
66 | */
|
---|
67 | const void* materialIndices;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | The mesh may represent either an arbitrary mesh or a height field. The advantage of a height field
|
---|
71 | is that it is assumed to be semi-infinite along one axis, and therefore it doesn't have the problem
|
---|
72 | of fast moving objects 'popping' through it due to temporal under sampling.
|
---|
73 |
|
---|
74 | However, height fields must be 'flat' in the sense that the projections of all triangles onto the
|
---|
75 | height field plane must be disjoint. (If the height field vertical axis is Y, the height field plane is spanned by X and Z.)
|
---|
76 |
|
---|
77 | To create a height field, set heightFieldVerticalAxis to NX_X, NX_Y or NX_Z,
|
---|
78 | or leave it set to NX_NOT_HEIGHTFIELD for an arbitrary mesh.
|
---|
79 |
|
---|
80 | <b>Default:</b> NX_NOT_HEIGHTFIELD
|
---|
81 |
|
---|
82 | <b>Platform:</b>
|
---|
83 | \li PC SW: Yes
|
---|
84 | \li PPU : No
|
---|
85 | \li PS3 : Yes
|
---|
86 | \li XB360: Yes
|
---|
87 |
|
---|
88 | @see NxHeightFieldAxis heightFieldVerticalExtent
|
---|
89 | */
|
---|
90 | NxHeightFieldAxis heightFieldVerticalAxis;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | If this mesh is a height field, this sets how far 'below ground' the height volume extends.
|
---|
94 |
|
---|
95 | In this way even objects which are under the surface of the height field but above
|
---|
96 | this cutoff are treated as colliding with the height field. To create a height field with the up axis being
|
---|
97 | the Y axis, you need to set the heightFieldVerticalAxis to Y and the heightFieldVerticalExtent to a large negative number.
|
---|
98 |
|
---|
99 | The heightFieldVerticalExtent has to be outside of the vertex coordinate range of the mesh along the heightFieldVerticalAxis.
|
---|
100 |
|
---|
101 | You may set this to a positive value, in which case the extent will be cast along the opposite side of the height field.
|
---|
102 |
|
---|
103 | You may use a smaller finite value for the extent if you want to put some space under the height field, such as a cave.
|
---|
104 |
|
---|
105 | <b>Range:</b> (-inf,inf)<br>
|
---|
106 | <b>Default:</b> 0
|
---|
107 |
|
---|
108 | <b>Platform:</b>
|
---|
109 | \li PC SW: Yes
|
---|
110 | \li PPU : No
|
---|
111 | \li PS3 : Yes
|
---|
112 | \li XB360: Yes
|
---|
113 |
|
---|
114 | @see heightFieldVerticalAxis
|
---|
115 | */
|
---|
116 | NxReal heightFieldVerticalExtent;
|
---|
117 |
|
---|
118 | /**
|
---|
119 | The pmap is an optional data structure which makes mesh-mesh collision detection more robust at the cost of higher
|
---|
120 | memory consumption. A pmap can be created with ::NxCreatePMap and released with ::NxReleasePMap.
|
---|
121 | You may also save the output of ::NxCreatePMap do disc to avoid this preprocessing step.
|
---|
122 |
|
---|
123 | The pmap data will not be copied. For this reason the caller does not need to keep it around for the lifetime of
|
---|
124 | the NxTriangleMesh object.
|
---|
125 |
|
---|
126 | <b>Default:</b> NULL
|
---|
127 |
|
---|
128 | <b>Platform:</b>
|
---|
129 | \li PC SW: Yes
|
---|
130 | \li PPU : No
|
---|
131 | \li PS3 : Yes
|
---|
132 | \li XB360: Yes
|
---|
133 |
|
---|
134 | @see NxTriangleMesh.loadPMap
|
---|
135 | */
|
---|
136 | NxPMap* pmap;
|
---|
137 |
|
---|
138 | /**
|
---|
139 | The SDK computes convex edges of a mesh and use them for collision detection. This parameter allows you to
|
---|
140 | setup a tolerance for the convex edge detector.
|
---|
141 |
|
---|
142 | <b>Range:</b> (0,inf)<br>
|
---|
143 | <b>Default:</b> 0.001
|
---|
144 |
|
---|
145 | <b>Platform:</b>
|
---|
146 | \li PC SW: Yes
|
---|
147 | \li PPU : No
|
---|
148 | \li PS3 : Yes
|
---|
149 | \li XB360: Yes
|
---|
150 | */
|
---|
151 | NxReal convexEdgeThreshold;
|
---|
152 |
|
---|
153 | /**
|
---|
154 | \brief Constructor sets to default.
|
---|
155 | */
|
---|
156 | NX_INLINE NxTriangleMeshDesc();
|
---|
157 |
|
---|
158 | /**
|
---|
159 | \brief (re)sets the structure to the default.
|
---|
160 | */
|
---|
161 | NX_INLINE void setToDefault();
|
---|
162 |
|
---|
163 | /**
|
---|
164 | \brief Returns true if the descriptor is valid.
|
---|
165 | \return true if the current settings are valid
|
---|
166 | */
|
---|
167 | NX_INLINE bool isValid() const;
|
---|
168 | };
|
---|
169 |
|
---|
170 | NX_INLINE NxTriangleMeshDesc::NxTriangleMeshDesc() //constructor sets to default
|
---|
171 | {
|
---|
172 | setToDefault();
|
---|
173 | }
|
---|
174 |
|
---|
175 | NX_INLINE void NxTriangleMeshDesc::setToDefault()
|
---|
176 | {
|
---|
177 | NxSimpleTriangleMesh::setToDefault();
|
---|
178 | materialIndexStride = 0;
|
---|
179 | materialIndices = 0;
|
---|
180 | heightFieldVerticalAxis = NX_NOT_HEIGHTFIELD;
|
---|
181 | heightFieldVerticalExtent = 0;
|
---|
182 | convexEdgeThreshold = 0.001f;
|
---|
183 | pmap = NULL;
|
---|
184 | }
|
---|
185 |
|
---|
186 | NX_INLINE bool NxTriangleMeshDesc::isValid() const
|
---|
187 | {
|
---|
188 | if(numVertices < 3) //at least 1 trig's worth of points
|
---|
189 | return false;
|
---|
190 | if ((!triangles) && (numVertices%3)) // Non-indexed mesh => we must ensure the geometry defines an implicit number of triangles // i.e. numVertices can't be divided by 3
|
---|
191 | return false;
|
---|
192 | //add more validity checks here
|
---|
193 | if (materialIndices && materialIndexStride < sizeof(NxMaterialIndex))
|
---|
194 | return false;
|
---|
195 | return NxSimpleTriangleMesh::isValid();
|
---|
196 | }
|
---|
197 |
|
---|
198 | /** @} */
|
---|
199 | #endif
|
---|
200 |
|
---|
201 |
|
---|
202 | //AGCOPYRIGHTBEGIN
|
---|
203 | ///////////////////////////////////////////////////////////////////////////
|
---|
204 | // Copyright © 2005 AGEIA Technologies.
|
---|
205 | // All rights reserved. www.ageia.com
|
---|
206 | ///////////////////////////////////////////////////////////////////////////
|
---|
207 | //AGCOPYRIGHTEND
|
---|
208 |
|
---|