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