| 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_EXTENSIONS_SHAPE_H |
| 15 | #define PX_PHYSICS_EXTENSIONS_SHAPE_H |
| 16 | /** \addtogroup extensions |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "PxPhysXConfig.h" |
| 21 | |
| 22 | #include "foundation/PxPlane.h" |
| 23 | #include "PxShape.h" |
| 24 | #include "PxRigidActor.h" |
| 25 | #include "geometry/PxGeometryQuery.h" |
| 26 | |
| 27 | #ifndef PX_DOXYGEN |
| 28 | namespace physx |
| 29 | { |
| 30 | #endif |
| 31 | |
| 32 | /** |
| 33 | \brief utility functions for use with PxShape |
| 34 | |
| 35 | @see PxShape |
| 36 | */ |
| 37 | |
| 38 | class PxShapeExt |
| 39 | { |
| 40 | public: |
| 41 | /** |
| 42 | \brief Retrieves the world space pose of the shape. |
| 43 | |
| 44 | \param[in] shape The shape for which to get the global pose. |
| 45 | \param[in] actor The actor to which the shape is attached |
| 46 | |
| 47 | \return Global pose of shape. |
| 48 | */ |
| 49 | static PX_INLINE PxTransform getGlobalPose(const PxShape& shape, const PxRigidActor& actor) |
| 50 | { |
| 51 | return actor.getGlobalPose() * shape.getLocalPose(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | \brief Raycast test against the shape. |
| 56 | |
| 57 | \param[in] shape the shape |
| 58 | \param[in] actor the actor to which the shape is attached |
| 59 | \param[in] rayOrigin The origin of the ray to test the geometry object against |
| 60 | \param[in] rayDir The direction of the ray to test the geometry object against |
| 61 | \param[in] maxDist Maximum ray length |
| 62 | \param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags |
| 63 | \param[in] maxHits max number of returned hits = size of 'rayHits' buffer |
| 64 | \param[out] rayHits Raycast hits information |
| 65 | \param[in] anyHit Set to false if the closest hit point should be computed, else the query aborts as soon as any valid hit point is found. |
| 66 | \return Number of hits between the ray and the shape |
| 67 | |
| 68 | @see PxRaycastHit PxTransform |
| 69 | */ |
| 70 | static PX_INLINE PxU32 raycast(const PxShape& shape, const PxRigidActor& actor, |
| 71 | const PxVec3& rayOrigin, const PxVec3& rayDir, PxReal maxDist, PxHitFlags hitFlags, |
| 72 | PxU32 maxHits, PxRaycastHit* rayHits, bool anyHit) |
| 73 | { |
| 74 | return PxGeometryQuery::raycast( |
| 75 | rayOrigin, rayDir, shape.getGeometry().any(), getGlobalPose(shape, actor), maxDist, hitFlags, maxHits, rayHits, anyHit); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | \brief Test overlap between the shape and a geometry object |
| 80 | |
| 81 | \param[in] shape the shape |
| 82 | \param[in] actor the actor to which the shape is attached |
| 83 | \param[in] otherGeom The other geometry object to test overlap with |
| 84 | \param[in] otherGeomPose Pose of the other geometry object |
| 85 | \return True if the shape overlaps the geometry object |
| 86 | |
| 87 | @see PxGeometry PxTransform |
| 88 | */ |
| 89 | static PX_INLINE bool overlap(const PxShape& shape, const PxRigidActor& actor, |
| 90 | const PxGeometry& otherGeom, const PxTransform& otherGeomPose) |
| 91 | { |
| 92 | return PxGeometryQuery::overlap(shape.getGeometry().any(), getGlobalPose(shape, actor), otherGeom, otherGeomPose); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | \brief Sweep a geometry object against the shape. |
| 97 | |
| 98 | Currently only box, sphere, capsule and convex mesh shapes are supported, i.e. the swept geometry object must be one of those types. |
| 99 | |
| 100 | \param[in] shape the shape |
| 101 | \param[in] actor the actor to which the shape is attached |
| 102 | \param[in] unitDir Normalized direction along which the geometry object should be swept. |
| 103 | \param[in] distance Sweep distance. Needs to be larger than 0. |
| 104 | \param[in] otherGeom The geometry object to sweep against the shape |
| 105 | \param[in] otherGeomPose Pose of the geometry object |
| 106 | \param[out] sweepHit The sweep hit information. Only valid if this method returns true. |
| 107 | \param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags |
| 108 | \return True if the swept geometry object hits the shape |
| 109 | |
| 110 | @see PxGeometry PxTransform PxSweepHit |
| 111 | */ |
| 112 | static PX_INLINE bool sweep(const PxShape& shape, const PxRigidActor& actor, |
| 113 | const PxVec3& unitDir, const PxReal distance, const PxGeometry& otherGeom, const PxTransform& otherGeomPose, |
| 114 | PxSweepHit& sweepHit, PxHitFlags hitFlags) |
| 115 | { |
| 116 | return PxGeometryQuery::sweep(unitDir, distance, otherGeom, otherGeomPose, shape.getGeometry().any(), getGlobalPose(shape, actor), sweepHit, hitFlags); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | \brief Retrieves the axis aligned bounding box enclosing the shape. |
| 122 | |
| 123 | \return The shape's bounding box. |
| 124 | |
| 125 | \param[in] shape the shape |
| 126 | \param[in] actor the actor to which the shape is attached |
| 127 | \param[in] inflation Scale factor for computed world bounds. Box extents are multiplied by this value. |
| 128 | |
| 129 | @see PxBounds3 |
| 130 | */ |
| 131 | static PX_INLINE PxBounds3 getWorldBounds(const PxShape& shape, const PxRigidActor& actor, float inflation=1.01f) |
| 132 | { |
| 133 | return PxGeometryQuery::getWorldBounds(shape.getGeometry().any(), getGlobalPose(shape, actor), inflation); |
| 134 | } |
| 135 | |
| 136 | }; |
| 137 | |
| 138 | #ifndef PX_DOXYGEN |
| 139 | } // namespace physx |
| 140 | #endif |
| 141 | |
| 142 | /** @} */ |
| 143 | #endif |
| 144 | |