1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PX_COLLISION_NXHEIGHTFIELDDESC |
32 | #define PX_COLLISION_NXHEIGHTFIELDDESC |
33 | /** \addtogroup geomutils |
34 | @{ |
35 | */ |
36 | |
37 | #include "common/PxPhysXCommonConfig.h" |
38 | #include "geometry/PxHeightFieldFlag.h" |
39 | #include "common/PxCoreUtilityTypes.h" |
40 | |
41 | #if !PX_DOXYGEN |
42 | namespace physx |
43 | { |
44 | #endif |
45 | |
46 | /** |
47 | \brief Descriptor class for #PxHeightField. |
48 | |
49 | \note The heightfield data is *copied* when a PxHeightField object is created from this descriptor. After the call the |
50 | user may discard the height data. |
51 | |
52 | @see PxHeightField PxHeightFieldGeometry PxShape PxPhysics.createHeightField() PxCooking.createHeightField() |
53 | */ |
54 | class PxHeightFieldDesc |
55 | { |
56 | public: |
57 | |
58 | /** |
59 | \brief Number of sample rows in the height field samples array. |
60 | |
61 | \note Local space X-axis corresponds to rows. |
62 | |
63 | <b>Range:</b> >1<br> |
64 | <b>Default:</b> 0 |
65 | */ |
66 | PxU32 nbRows; |
67 | |
68 | /** |
69 | \brief Number of sample columns in the height field samples array. |
70 | |
71 | \note Local space Z-axis corresponds to columns. |
72 | |
73 | <b>Range:</b> >1<br> |
74 | <b>Default:</b> 0 |
75 | */ |
76 | PxU32 nbColumns; |
77 | |
78 | /** |
79 | \brief Format of the sample data. |
80 | |
81 | Currently the only supported format is PxHeightFieldFormat::eS16_TM: |
82 | |
83 | <b>Default:</b> PxHeightFieldFormat::eS16_TM |
84 | |
85 | @see PxHeightFormat PxHeightFieldDesc.samples |
86 | */ |
87 | PxHeightFieldFormat::Enum format; |
88 | |
89 | /** |
90 | \brief The samples array. |
91 | |
92 | It is copied to the SDK's storage at creation time. |
93 | |
94 | There are nbRows * nbColumn samples in the array, |
95 | which define nbRows * nbColumn vertices and cells, |
96 | of which (nbRows - 1) * (nbColumns - 1) cells are actually used. |
97 | |
98 | The array index of sample(row, column) = row * nbColumns + column. |
99 | The byte offset of sample(row, column) = sampleStride * (row * nbColumns + column). |
100 | The sample data follows at the offset and spans the number of bytes defined by the format. |
101 | Then there are zero or more unused bytes depending on sampleStride before the next sample. |
102 | |
103 | <b>Default:</b> NULL |
104 | |
105 | @see PxHeightFormat |
106 | */ |
107 | PxStridedData samples; |
108 | |
109 | /** |
110 | This threshold is used by the collision detection to determine if a height field edge is convex |
111 | and can generate contact points. |
112 | Usually the convexity of an edge is determined from the angle (or cosine of the angle) between |
113 | the normals of the faces sharing that edge. |
114 | The height field allows a more efficient approach by comparing height values of neighboring vertices. |
115 | This parameter offsets the comparison. Smaller changes than 0.5 will not alter the set of convex edges. |
116 | The rule of thumb is that larger values will result in fewer edge contacts. |
117 | |
118 | This parameter is ignored in contact generation with sphere and capsule primitives. |
119 | |
120 | <b>Range:</b> [0, PX_MAX_F32)<br> |
121 | <b>Default:</b> 0 |
122 | */ |
123 | PxReal convexEdgeThreshold; |
124 | |
125 | /** |
126 | \brief Flags bits, combined from values of the enum ::PxHeightFieldFlag. |
127 | |
128 | <b>Default:</b> 0 |
129 | |
130 | @see PxHeightFieldFlag PxHeightFieldFlags |
131 | */ |
132 | PxHeightFieldFlags flags; |
133 | |
134 | /** |
135 | \brief Constructor sets to default. |
136 | */ |
137 | PX_INLINE PxHeightFieldDesc(); |
138 | |
139 | /** |
140 | \brief (re)sets the structure to the default. |
141 | */ |
142 | PX_INLINE void setToDefault(); |
143 | |
144 | /** |
145 | \brief Returns true if the descriptor is valid. |
146 | \return True if the current settings are valid. |
147 | */ |
148 | PX_INLINE bool isValid() const; |
149 | }; |
150 | |
151 | PX_INLINE PxHeightFieldDesc::PxHeightFieldDesc() //constructor sets to default |
152 | { |
153 | nbColumns = 0; |
154 | nbRows = 0; |
155 | format = PxHeightFieldFormat::eS16_TM; |
156 | convexEdgeThreshold = 0.0f; |
157 | flags = PxHeightFieldFlags(); |
158 | } |
159 | |
160 | PX_INLINE void PxHeightFieldDesc::setToDefault() |
161 | { |
162 | *this = PxHeightFieldDesc(); |
163 | } |
164 | |
165 | PX_INLINE bool PxHeightFieldDesc::isValid() const |
166 | { |
167 | if (nbColumns < 2) |
168 | return false; |
169 | if (nbRows < 2) |
170 | return false; |
171 | if(format != PxHeightFieldFormat::eS16_TM) |
172 | return false; |
173 | if (samples.stride < 4) |
174 | return false; |
175 | if (convexEdgeThreshold < 0) |
176 | return false; |
177 | if ((flags & PxHeightFieldFlag::eNO_BOUNDARY_EDGES) != flags) |
178 | return false; |
179 | return true; |
180 | } |
181 | |
182 | #if !PX_DOXYGEN |
183 | } // namespace physx |
184 | #endif |
185 | |
186 | /** @} */ |
187 | #endif |
188 | |