1 | /* |
2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
3 | * |
4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
5 | * and proprietary rights in and to this software, related documentation |
6 | * and any modifications thereto. Any use, reproduction, disclosure or |
7 | * distribution of this software and related documentation without an express |
8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
9 | */ |
10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
12 | |
13 | |
14 | #ifndef PX_COLLISION_NXHEIGHTFIELDDESC |
15 | #define PX_COLLISION_NXHEIGHTFIELDDESC |
16 | /** \addtogroup geomutils |
17 | @{ |
18 | */ |
19 | |
20 | #include "foundation/PxBounds3.h" |
21 | #include "common/PxPhysXCommonConfig.h" |
22 | #include "geometry/PxHeightFieldFlag.h" |
23 | #include "common/PxCoreUtilityTypes.h" |
24 | |
25 | #ifndef PX_DOXYGEN |
26 | namespace physx |
27 | { |
28 | #endif |
29 | |
30 | /** |
31 | \brief Descriptor class for #PxHeightField. |
32 | |
33 | \note The heightfield data is *copied* when a PxHeightField object is created from this descriptor. After the call the |
34 | user may discard the height data. |
35 | |
36 | @see PxHeightField PxHeightFieldGeometry PxShape PxPhysics.createHeightField() |
37 | */ |
38 | class PxHeightFieldDesc |
39 | { |
40 | public: |
41 | |
42 | /** |
43 | \brief Number of sample rows in the height field samples array. |
44 | |
45 | \note Local space X-axis corresponds to rows. |
46 | |
47 | <b>Range:</b> >1<br> |
48 | <b>Default:</b> 0 |
49 | */ |
50 | PxU32 nbRows; |
51 | |
52 | /** |
53 | \brief Number of sample columns in the height field samples array. |
54 | |
55 | \note Local space Z-axis corresponds to columns. |
56 | |
57 | <b>Range:</b> >1<br> |
58 | <b>Default:</b> 0 |
59 | */ |
60 | PxU32 nbColumns; |
61 | |
62 | /** |
63 | \brief Format of the sample data. |
64 | |
65 | Currently the only supported format is PxHeightFieldFormat::eS16_TM: |
66 | |
67 | <b>Default:</b> PxHeightFieldFormat::eS16_TM |
68 | |
69 | @see PxHeightFormat PxHeightFieldDesc.samples |
70 | */ |
71 | PxHeightFieldFormat::Enum format; |
72 | |
73 | /** |
74 | \brief The samples array. |
75 | |
76 | It is copied to the SDK's storage at creation time. |
77 | |
78 | There are nbRows * nbColumn samples in the array, |
79 | which define nbRows * nbColumn vertices and cells, |
80 | of which (nbRows - 1) * (nbColumns - 1) cells are actually used. |
81 | |
82 | The array index of sample(row, column) = row * nbColumns + column. |
83 | The byte offset of sample(row, column) = sampleStride * (row * nbColumns + column). |
84 | The sample data follows at the offset and spans the number of bytes defined by the format. |
85 | Then there are zero or more unused bytes depending on sampleStride before the next sample. |
86 | |
87 | <b>Default:</b> NULL |
88 | |
89 | @see PxHeightFormat |
90 | */ |
91 | PxStridedData samples; |
92 | |
93 | /** |
94 | \brief Sets how thick the heightfield surface is. |
95 | |
96 | In this way even objects which are under the surface of the height field but above |
97 | this cutoff are treated as colliding with the height field. |
98 | |
99 | The thickness is measured relative to the surface at the given point. |
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 | \note Please refer to the Raycasts Against Heightfields section of the user guide for details of how this value affects raycasts. |
106 | |
107 | <b>Range:</b> (-PX_MAX_BOUNDS_EXTENTS, PX_MAX_BOUNDS_EXTENTS)<br> |
108 | <b>Default:</b> -1 |
109 | */ |
110 | PxReal thickness; |
111 | |
112 | /** |
113 | This threshold is used by the collision detection to determine if a height field edge is convex |
114 | and can generate contact points. |
115 | Usually the convexity of an edge is determined from the angle (or cosine of the angle) between |
116 | the normals of the faces sharing that edge. |
117 | The height field allows a more efficient approach by comparing height values of neighboring vertices. |
118 | This parameter offsets the comparison. Smaller changes than 0.5 will not alter the set of convex edges. |
119 | The rule of thumb is that larger values will result in fewer edge contacts. |
120 | |
121 | This parameter is ignored in contact generation with sphere and capsule primitives. |
122 | |
123 | <b>Range:</b> [0, PX_MAX_F32)<br> |
124 | <b>Default:</b> 0 |
125 | */ |
126 | PxReal convexEdgeThreshold; |
127 | |
128 | /** |
129 | \brief Flags bits, combined from values of the enum ::PxHeightFieldFlag. |
130 | |
131 | <b>Default:</b> 0 |
132 | |
133 | @see PxHeightFieldFlag PxHeightFieldFlags |
134 | */ |
135 | PxHeightFieldFlags flags; |
136 | |
137 | /** |
138 | \brief Constructor sets to default. |
139 | */ |
140 | PX_INLINE PxHeightFieldDesc(); |
141 | |
142 | /** |
143 | \brief (re)sets the structure to the default. |
144 | */ |
145 | PX_INLINE void setToDefault(); |
146 | |
147 | /** |
148 | \brief Returns true if the descriptor is valid. |
149 | \return True if the current settings are valid. |
150 | */ |
151 | PX_INLINE bool isValid() const; |
152 | }; |
153 | |
154 | PX_INLINE PxHeightFieldDesc::PxHeightFieldDesc() //constructor sets to default |
155 | { |
156 | nbColumns = 0; |
157 | nbRows = 0; |
158 | format = PxHeightFieldFormat::eS16_TM; |
159 | thickness = -1.0f; |
160 | convexEdgeThreshold = 0.0f; |
161 | flags = PxHeightFieldFlags(); |
162 | } |
163 | |
164 | PX_INLINE void PxHeightFieldDesc::setToDefault() |
165 | { |
166 | *this = PxHeightFieldDesc(); |
167 | } |
168 | |
169 | PX_INLINE bool PxHeightFieldDesc::isValid() const |
170 | { |
171 | if (nbColumns < 2) |
172 | return false; |
173 | if (nbRows < 2) |
174 | return false; |
175 | switch (format) |
176 | { |
177 | case PxHeightFieldFormat::eS16_TM: |
178 | if (samples.stride < 4) |
179 | return false; |
180 | break; |
181 | default: |
182 | return false; |
183 | } |
184 | if (convexEdgeThreshold < 0) |
185 | return false; |
186 | if ((flags & PxHeightFieldFlag::eNO_BOUNDARY_EDGES) != flags) |
187 | return false; |
188 | if (thickness < -PX_MAX_BOUNDS_EXTENTS || thickness > PX_MAX_BOUNDS_EXTENTS) |
189 | return false; |
190 | return true; |
191 | } |
192 | |
193 | #ifndef PX_DOXYGEN |
194 | } // namespace physx |
195 | #endif |
196 | |
197 | /** @} */ |
198 | #endif |
199 | |