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

source code of qtquick3dphysics/src/3rdparty/PhysX/include/extensions/PxShapeExt.h