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_PHYSICS_EXTENSIONS_SCENE_QUERY_H |
32 | #define PX_PHYSICS_EXTENSIONS_SCENE_QUERY_H |
33 | /** \addtogroup extensions |
34 | @{ |
35 | */ |
36 | |
37 | #include "PxPhysXConfig.h" |
38 | |
39 | #include "PxScene.h" |
40 | |
41 | #if !PX_DOXYGEN |
42 | namespace physx |
43 | { |
44 | #endif |
45 | |
46 | // These types have been deprecated (removed) in PhysX 3.4. We typedef them to the new types here for easy migration from 3.3 to 3.4. |
47 | typedef PxQueryHit PxSceneQueryHit; |
48 | typedef PxQueryFilterData PxSceneQueryFilterData; |
49 | typedef PxQueryFilterCallback PxSceneQueryFilterCallback; |
50 | typedef PxQueryCache PxSceneQueryCache; |
51 | typedef PxHitFlag PxSceneQueryFlag; |
52 | typedef PxHitFlags PxSceneQueryFlags; |
53 | |
54 | /** |
55 | \brief utility functions for use with PxScene, related to scene queries. |
56 | |
57 | Some of these functions have been deprecated (removed) in PhysX 3.4. We re-implement them here for easy migration from 3.3 to 3.4. |
58 | |
59 | @see PxShape |
60 | */ |
61 | |
62 | class PxSceneQueryExt |
63 | { |
64 | public: |
65 | |
66 | /** |
67 | \brief Raycast returning any blocking hit, not necessarily the closest. |
68 | |
69 | Returns whether any rigid actor is hit along the ray. |
70 | |
71 | \note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms. |
72 | |
73 | \param[in] scene The scene |
74 | \param[in] origin Origin of the ray. |
75 | \param[in] unitDir Normalized direction of the ray. |
76 | \param[in] distance Length of the ray. Needs to be larger than 0. |
77 | \param[out] hit Raycast hit information. |
78 | \param[in] filterData Filtering data and simple logic. |
79 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking. |
80 | \param[in] cache Cached hit shape (optional). Ray is tested against cached shape first. If no hit is found the ray gets queried against the scene. |
81 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
82 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
83 | \return True if a blocking hit was found. |
84 | |
85 | @see PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache PxSceneQueryHit |
86 | */ |
87 | static bool raycastAny( const PxScene& scene, |
88 | const PxVec3& origin, const PxVec3& unitDir, const PxReal distance, |
89 | PxSceneQueryHit& hit, const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
90 | PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL); |
91 | |
92 | /** |
93 | \brief Raycast returning a single result. |
94 | |
95 | Returns the first rigid actor that is hit along the ray. Data for a blocking hit will be returned as specified by the outputFlags field. Touching hits will be ignored. |
96 | |
97 | \note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms. |
98 | |
99 | \param[in] scene The scene |
100 | \param[in] origin Origin of the ray. |
101 | \param[in] unitDir Normalized direction of the ray. |
102 | \param[in] distance Length of the ray. Needs to be larger than 0. |
103 | \param[in] outputFlags Specifies which properties should be written to the hit information |
104 | \param[out] hit Raycast hit information. |
105 | \param[in] filterData Filtering data and simple logic. |
106 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking. |
107 | \param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene. |
108 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
109 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
110 | \return True if a blocking hit was found. |
111 | |
112 | @see PxSceneQueryFlags PxRaycastHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache |
113 | */ |
114 | static bool raycastSingle( const PxScene& scene, |
115 | const PxVec3& origin, const PxVec3& unitDir, const PxReal distance, |
116 | PxSceneQueryFlags outputFlags, PxRaycastHit& hit, |
117 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
118 | PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL); |
119 | |
120 | /** |
121 | \brief Raycast returning multiple results. |
122 | |
123 | Find all rigid actors that get hit along the ray. Each result contains data as specified by the outputFlags field. |
124 | |
125 | \note Touching hits are not ordered. |
126 | |
127 | \note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms. |
128 | |
129 | \param[in] scene The scene |
130 | \param[in] origin Origin of the ray. |
131 | \param[in] unitDir Normalized direction of the ray. |
132 | \param[in] distance Length of the ray. Needs to be larger than 0. |
133 | \param[in] outputFlags Specifies which properties should be written to the hit information |
134 | \param[out] hitBuffer Raycast hit information buffer. If the buffer overflows, the blocking hit is returned as the last entry together with an arbitrary subset |
135 | of the nearer touching hits (typically the query should be restarted with a larger buffer). |
136 | \param[in] hitBufferSize Size of the hit buffer. |
137 | \param[out] blockingHit True if a blocking hit was found. If found, it is the last in the buffer, preceded by any touching hits which are closer. Otherwise the touching hits are listed. |
138 | \param[in] filterData Filtering data and simple logic. |
139 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be touching. |
140 | \param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene. |
141 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
142 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
143 | \return Number of hits in the buffer, or -1 if the buffer overflowed. |
144 | |
145 | @see PxSceneQueryFlags PxRaycastHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache |
146 | */ |
147 | static PxI32 raycastMultiple( const PxScene& scene, |
148 | const PxVec3& origin, const PxVec3& unitDir, const PxReal distance, |
149 | PxSceneQueryFlags outputFlags, |
150 | PxRaycastHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit, |
151 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
152 | PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL); |
153 | |
154 | /** |
155 | \brief Sweep returning any blocking hit, not necessarily the closest. |
156 | |
157 | Returns whether any rigid actor is hit along the sweep path. |
158 | |
159 | \note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag. |
160 | |
161 | \param[in] scene The scene |
162 | \param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex). |
163 | \param[in] pose Pose of the sweep object. |
164 | \param[in] unitDir Normalized direction of the sweep. |
165 | \param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE. |
166 | \param[in] queryFlags Combination of PxSceneQueryFlag defining the query behavior |
167 | \param[out] hit Sweep hit information. |
168 | \param[in] filterData Filtering data and simple logic. |
169 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking. |
170 | \param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first. If no hit is found the sweep gets queried against the scene. |
171 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
172 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
173 | \param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal. |
174 | \return True if a blocking hit was found. |
175 | |
176 | @see PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryHit PxSceneQueryCache |
177 | */ |
178 | static bool sweepAny( const PxScene& scene, |
179 | const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance, |
180 | PxSceneQueryFlags queryFlags, |
181 | PxSceneQueryHit& hit, |
182 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
183 | PxSceneQueryFilterCallback* filterCall = NULL, |
184 | const PxSceneQueryCache* cache = NULL, |
185 | PxReal inflation = 0.0f); |
186 | |
187 | /** |
188 | \brief Sweep returning a single result. |
189 | |
190 | Returns the first rigid actor that is hit along the ray. Data for a blocking hit will be returned as specified by the outputFlags field. Touching hits will be ignored. |
191 | |
192 | \note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag. |
193 | |
194 | \param[in] scene The scene |
195 | \param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex). |
196 | \param[in] pose Pose of the sweep object. |
197 | \param[in] unitDir Normalized direction of the sweep. |
198 | \param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE. |
199 | \param[in] outputFlags Specifies which properties should be written to the hit information. |
200 | \param[out] hit Sweep hit information. |
201 | \param[in] filterData Filtering data and simple logic. |
202 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking. |
203 | \param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first then against the scene. |
204 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
205 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
206 | \param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal. |
207 | \return True if a blocking hit was found. |
208 | |
209 | @see PxSceneQueryFlags PxSweepHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache |
210 | */ |
211 | static bool sweepSingle(const PxScene& scene, |
212 | const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance, |
213 | PxSceneQueryFlags outputFlags, |
214 | PxSweepHit& hit, |
215 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
216 | PxSceneQueryFilterCallback* filterCall = NULL, |
217 | const PxSceneQueryCache* cache = NULL, |
218 | PxReal inflation=0.0f); |
219 | |
220 | /** |
221 | \brief Sweep returning multiple results. |
222 | |
223 | Find all rigid actors that get hit along the sweep. Each result contains data as specified by the outputFlags field. |
224 | |
225 | \note Touching hits are not ordered. |
226 | |
227 | \note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag. |
228 | |
229 | \param[in] scene The scene |
230 | \param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex). |
231 | \param[in] pose Pose of the sweep object. |
232 | \param[in] unitDir Normalized direction of the sweep. |
233 | \param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE. |
234 | \param[in] outputFlags Specifies which properties should be written to the hit information. |
235 | \param[out] hitBuffer Sweep hit information buffer. If the buffer overflows, the blocking hit is returned as the last entry together with an arbitrary subset |
236 | of the nearer touching hits (typically the query should be restarted with a larger buffer). |
237 | \param[in] hitBufferSize Size of the hit buffer. |
238 | \param[out] blockingHit True if a blocking hit was found. If found, it is the last in the buffer, preceded by any touching hits which are closer. Otherwise the touching hits are listed. |
239 | \param[in] filterData Filtering data and simple logic. |
240 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be touching. |
241 | \param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first then against the scene. |
242 | Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit. |
243 | Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking. |
244 | \param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal. |
245 | \return Number of hits in the buffer, or -1 if the buffer overflowed. |
246 | |
247 | @see PxSceneQueryFlags PxSweepHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache |
248 | */ |
249 | static PxI32 sweepMultiple( const PxScene& scene, |
250 | const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance, |
251 | PxSceneQueryFlags outputFlags, PxSweepHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit, |
252 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
253 | PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL, |
254 | PxReal inflation = 0.0f); |
255 | |
256 | /** |
257 | \brief Test overlap between a geometry and objects in the scene. |
258 | |
259 | \note Filtering: Overlap tests do not distinguish between touching and blocking hit types. Both get written to the hit buffer. |
260 | |
261 | \note PxHitFlag::eMESH_MULTIPLE and PxHitFlag::eMESH_BOTH_SIDES have no effect in this case |
262 | |
263 | \param[in] scene The scene |
264 | \param[in] geometry Geometry of object to check for overlap (supported types are: box, sphere, capsule, convex). |
265 | \param[in] pose Pose of the object. |
266 | \param[out] hitBuffer Buffer to store the overlapping objects to. If the buffer overflows, an arbitrary subset of overlapping objects is stored (typically the query should be restarted with a larger buffer). |
267 | \param[in] hitBufferSize Size of the hit buffer. |
268 | \param[in] filterData Filtering data and simple logic. |
269 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to overlap. |
270 | \return Number of hits in the buffer, or -1 if the buffer overflowed. |
271 | |
272 | @see PxSceneQueryFlags PxSceneQueryFilterData PxSceneQueryFilterCallback |
273 | */ |
274 | static PxI32 overlapMultiple( const PxScene& scene, |
275 | const PxGeometry& geometry, const PxTransform& pose, |
276 | PxOverlapHit* hitBuffer, PxU32 hitBufferSize, |
277 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
278 | PxSceneQueryFilterCallback* filterCall = NULL); |
279 | |
280 | /** |
281 | \brief Test returning, for a given geometry, any overlapping object in the scene. |
282 | |
283 | \note Filtering: Overlap tests do not distinguish between touching and blocking hit types. Both trigger a hit. |
284 | |
285 | \note PxHitFlag::eMESH_MULTIPLE and PxHitFlag::eMESH_BOTH_SIDES have no effect in this case |
286 | |
287 | \param[in] scene The scene |
288 | \param[in] geometry Geometry of object to check for overlap (supported types are: box, sphere, capsule, convex). |
289 | \param[in] pose Pose of the object. |
290 | \param[out] hit Pointer to store the overlapping object to. |
291 | \param[in] filterData Filtering data and simple logic. |
292 | \param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to overlap. |
293 | \return True if an overlap was found. |
294 | |
295 | @see PxSceneQueryFlags PxSceneQueryFilterData PxSceneQueryFilterCallback |
296 | */ |
297 | static bool overlapAny( const PxScene& scene, |
298 | const PxGeometry& geometry, const PxTransform& pose, |
299 | PxOverlapHit& hit, |
300 | const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(), |
301 | PxSceneQueryFilterCallback* filterCall = NULL); |
302 | }; |
303 | |
304 | #if !PX_DOXYGEN |
305 | } // namespace physx |
306 | #endif |
307 | |
308 | /** @} */ |
309 | #endif |
310 | |