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_GEOMUTILS_PX_GEOMETRY_QUERY |
32 | #define PX_PHYSICS_GEOMUTILS_PX_GEOMETRY_QUERY |
33 | |
34 | /** |
35 | \brief Maximum sweep distance for scene sweeps. The distance parameter for sweep functions will be clamped to this value. |
36 | The reason for this is GJK support cannot be evaluated near infinity. A viable alternative can be a sweep followed by an infinite raycast. |
37 | |
38 | @see PxScene |
39 | */ |
40 | #define PX_MAX_SWEEP_DISTANCE 1e8f |
41 | |
42 | /** \addtogroup geomutils |
43 | @{ |
44 | */ |
45 | |
46 | #include "common/PxPhysXCommonConfig.h" |
47 | #include "PxQueryReport.h" |
48 | |
49 | #if !PX_DOXYGEN |
50 | namespace physx |
51 | { |
52 | #endif |
53 | |
54 | class PxGeometry; |
55 | struct PxSweepHit; |
56 | struct PxRaycastHit; |
57 | |
58 | class PxTriangle; |
59 | |
60 | /** |
61 | \brief Collection of geometry object queries (sweeps, raycasts, overlaps, ...). |
62 | */ |
63 | class PxGeometryQuery |
64 | { |
65 | public: |
66 | |
67 | /** |
68 | \brief Sweep a specified geometry object in space and test for collision with a given object. |
69 | |
70 | The following combinations are supported. |
71 | |
72 | \li PxSphereGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry} |
73 | \li PxCapsuleGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry} |
74 | \li PxBoxGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry} |
75 | \li PxConvexMeshGeometry vs. {PxSphereGeometry, PxPlaneGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexMeshGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry} |
76 | |
77 | \param[in] unitDir Normalized direction along which object geom0 should be swept |
78 | \param[in] maxDist Maximum sweep distance, has to be in the [0, inf) range |
79 | \param[in] geom0 The geometry object to sweep. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry, #PxBoxGeometry and #PxConvexMeshGeometry |
80 | \param[in] pose0 Pose of the geometry object to sweep |
81 | \param[in] geom1 The geometry object to test the sweep against |
82 | \param[in] pose1 Pose of the geometry object to sweep against |
83 | \param[out] sweepHit The sweep hit information. Only valid if this method returns true. |
84 | \param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags |
85 | \param[in] inflation Surface of the swept shape is additively extruded in the normal direction, rounding corners and edges. |
86 | |
87 | \return True if the swept geometry object geom0 hits the object geom1 |
88 | |
89 | @see PxSweepHit PxGeometry PxTransform |
90 | */ |
91 | PX_PHYSX_COMMON_API static bool sweep(const PxVec3& unitDir, |
92 | const PxReal maxDist, |
93 | const PxGeometry& geom0, |
94 | const PxTransform& pose0, |
95 | const PxGeometry& geom1, |
96 | const PxTransform& pose1, |
97 | PxSweepHit& sweepHit, |
98 | PxHitFlags hitFlags = PxHitFlag::eDEFAULT, |
99 | const PxReal inflation = 0.f); |
100 | |
101 | |
102 | /** |
103 | \brief Overlap test for two geometry objects. |
104 | |
105 | All combinations are supported except: |
106 | \li PxPlaneGeometry vs. {PxPlaneGeometry, PxTriangleMeshGeometry, PxHeightFieldGeometry} |
107 | \li PxTriangleMeshGeometry vs. {PxTriangleMeshGeometry, PxHeightFieldGeometry} |
108 | \li PxHeightFieldGeometry vs. {PxHeightFieldGeometry} |
109 | |
110 | \param[in] geom0 The first geometry object |
111 | \param[in] pose0 Pose of the first geometry object |
112 | \param[in] geom1 The second geometry object |
113 | \param[in] pose1 Pose of the second geometry object |
114 | \return True if the two geometry objects overlap |
115 | |
116 | @see PxGeometry PxTransform |
117 | */ |
118 | PX_PHYSX_COMMON_API static bool overlap(const PxGeometry& geom0, const PxTransform& pose0, |
119 | const PxGeometry& geom1, const PxTransform& pose1); |
120 | |
121 | |
122 | /** |
123 | \brief Raycast test against a geometry object. |
124 | |
125 | \param[in] origin The origin of the ray to test the geometry object against |
126 | \param[in] unitDir Normalized direction of the ray to test the geometry object against |
127 | \param[in] geom The geometry object to test the ray against |
128 | \param[in] pose Pose of the geometry object |
129 | \param[in] maxDist Maximum ray length, has to be in the [0, inf) range |
130 | \param[in] hitFlags Specification of the kind of information to retrieve on hit. Combination of #PxHitFlag flags |
131 | \param[in] maxHits max number of returned hits = size of 'rayHits' buffer |
132 | \param[out] rayHits Raycast hits information |
133 | \return Number of hits between the ray and the geometry object |
134 | |
135 | @see PxRaycastHit PxGeometry PxTransform |
136 | */ |
137 | PX_PHYSX_COMMON_API static PxU32 raycast(const PxVec3& origin, |
138 | const PxVec3& unitDir, |
139 | const PxGeometry& geom, |
140 | const PxTransform& pose, |
141 | PxReal maxDist, |
142 | PxHitFlags hitFlags, |
143 | PxU32 maxHits, |
144 | PxRaycastHit* PX_RESTRICT rayHits); |
145 | |
146 | /** |
147 | \brief Compute minimum translational distance (MTD) between two geometry objects. |
148 | |
149 | All combinations of geom objects are supported except: |
150 | - plane/plane |
151 | - plane/mesh |
152 | - plane/heightfield |
153 | - mesh/mesh |
154 | - mesh/heightfield |
155 | - heightfield/heightfield |
156 | |
157 | The function returns a unit vector ('direction') and a penetration depth ('depth'). |
158 | |
159 | The depenetration vector D = direction * depth should be applied to the first object, to |
160 | get out of the second object. |
161 | |
162 | Returned depth should always be positive or null. |
163 | |
164 | If objects do not overlap, the function can not compute the MTD and returns false. |
165 | |
166 | \param[out] direction Computed MTD unit direction |
167 | \param[out] depth Penetration depth. Always positive or null. |
168 | \param[in] geom0 The first geometry object |
169 | \param[in] pose0 Pose of the first geometry object |
170 | \param[in] geom1 The second geometry object |
171 | \param[in] pose1 Pose of the second geometry object |
172 | \return True if the MTD has successfully been computed, i.e. if objects do overlap. |
173 | |
174 | @see PxGeometry PxTransform |
175 | */ |
176 | PX_PHYSX_COMMON_API static bool computePenetration(PxVec3& direction, PxF32& depth, |
177 | const PxGeometry& geom0, const PxTransform& pose0, |
178 | const PxGeometry& geom1, const PxTransform& pose1); |
179 | |
180 | /** |
181 | \brief Computes distance between a point and a geometry object. |
182 | |
183 | Currently supported geometry objects: box, sphere, capsule, convex. |
184 | |
185 | \param[in] point The point P |
186 | \param[in] geom The geometry object |
187 | \param[in] pose Pose of the geometry object |
188 | \param[out] closestPoint Optionally returned closest point to P on the geom object. Only valid when returned distance is strictly positive. |
189 | \return Square distance between the point and the geom object, or 0.0 if the point is inside the object, or -1.0 if the geometry type is not supported. |
190 | |
191 | @see PxGeometry PxTransform |
192 | */ |
193 | PX_PHYSX_COMMON_API static PxReal pointDistance(const PxVec3& point, const PxGeometry& geom, const PxTransform& pose, PxVec3* closestPoint=NULL); |
194 | |
195 | |
196 | /** |
197 | \brief get the bounds for a geometry object |
198 | |
199 | \param[in] geom The geometry object |
200 | \param[in] pose Pose of the geometry object |
201 | \param[in] inflation Scale factor for computed world bounds. Box extents are multiplied by this value. |
202 | \return The bounds of the object |
203 | |
204 | @see PxGeometry PxTransform |
205 | */ |
206 | PX_PHYSX_COMMON_API static PxBounds3 getWorldBounds(const PxGeometry& geom, const PxTransform& pose, float inflation=1.01f); |
207 | |
208 | /** |
209 | \brief Checks if provided geometry is valid. |
210 | |
211 | \param[in] geom The geometry object. |
212 | \return True if geometry is valid. |
213 | |
214 | @see PxGeometry PxSphereGeometry, PxCapsuleGeometry, PxBoxGeometry, PxConvexGeometry |
215 | */ |
216 | PX_PHYSX_COMMON_API static bool isValid(const PxGeometry& geom); |
217 | }; |
218 | |
219 | |
220 | #if !PX_DOXYGEN |
221 | } |
222 | #endif |
223 | |
224 | /** @} */ |
225 | #endif |
226 | |