RavEngine
Loading...
Searching...
No Matches
PxQueryReport.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_QUERY_REPORT_H
30#define PX_QUERY_REPORT_H
34#include "foundation/PxVec3.h"
35#include "foundation/PxFlags.h"
36#include "foundation/PxAssert.h"
37#include "geometry/PxGeometryHit.h"
38#include "geometry/PxGeometryQueryContext.h"
39#include "PxPhysXConfig.h"
40
41#if !PX_DOXYGEN
42namespace physx
43{
44#endif
45
46class PxShape;
47class PxRigidActor;
48
57{
58 PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {}
59 PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {}
60
61 PxRigidActor* actor;
62 PxShape* shape;
63};
64
65// Extends geom hits with Px object pointers
69
78typedef bool PxAgain;
79
93template<typename HitType>
95{
96 HitType block;
97 bool hasBlock;
98
99 HitType* touches;
100
106
111
123 PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches)
124 : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0)
125 {}
126
147 virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0;
148
149 virtual void finalizeQuery() {}
150
151 virtual ~PxHitCallback() {}
152
154 PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); }
155};
156
170template<typename HitType>
171struct PxHitBuffer : public PxHitCallback<HitType>
172{
183 PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {}
184
186 PX_INLINE PxU32 getNbAnyHits() const { return getNbTouches() + PxU32(this->hasBlock); }
188 PX_INLINE const HitType& getAnyHit(const PxU32 index) const { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock));
189 return index < getNbTouches() ? getTouches()[index] : this->block; }
190
191 PX_INLINE PxU32 getNbTouches() const { return this->nbTouches; }
192 PX_INLINE const HitType* getTouches() const { return this->touches; }
193 PX_INLINE const HitType& getTouch(const PxU32 index) const { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; }
194 PX_INLINE PxU32 getMaxNbTouches() const { return this->maxNbTouches; }
195
196 virtual ~PxHitBuffer() {}
197
198protected:
199 // stops after the first callback
200 virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; }
201};
202
205
208
211
214
217
220
222template <int N>
223struct PxRaycastBufferN : public PxHitBuffer<PxRaycastHit>
224{
225 PxRaycastHit hits[N];
227};
228
230template <int N>
231struct PxOverlapBufferN : public PxHitBuffer<PxOverlapHit>
232{
233 PxOverlapHit hits[N];
235};
236
238template <int N>
239struct PxSweepBufferN : public PxHitBuffer<PxSweepHit>
240{
241 PxSweepHit hits[N];
243};
244
264{
268 PX_INLINE PxQueryCache() : shape(NULL), actor(NULL), faceIndex(0xffffffff) {}
269
273 PX_INLINE PxQueryCache(PxShape* s, PxU32 findex) : shape(s), actor(NULL), faceIndex(findex) {}
274
277 PxU32 faceIndex;
278};
279
280#if !PX_DOXYGEN
281} // namespace physx
282#endif
283
285#endif
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Abstract class for collision shapes.
Definition PxShape.h:146
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxHitBuffer< PxSweepHit > PxSweepBuffer
Sweep query buffer.
Definition PxQueryReport.h:219
bool PxAgain
Describes query behavior after returning a partial query result via a callback.
Definition PxQueryReport.h:78
PxHitBuffer< PxOverlapHit > PxOverlapBuffer
Overlap query buffer.
Definition PxQueryReport.h:216
PxHitBuffer< PxRaycastHit > PxRaycastBuffer
Raycast query buffer.
Definition PxQueryReport.h:213
PxHitCallback< PxOverlapHit > PxOverlapCallback
Overlap query callback.
Definition PxQueryReport.h:207
PxHitCallback< PxRaycastHit > PxRaycastCallback
Raycast query callback.
Definition PxQueryReport.h:204
PxHitCallback< PxSweepHit > PxSweepCallback
Sweep query callback.
Definition PxQueryReport.h:210
Combines a shape pointer and the actor the shape belongs to into one memory location.
Definition PxQueryReport.h:57
Stores results of overlap queries.
Definition PxGeometryHit.h:165
Stores results of raycast queries.
Definition PxGeometryHit.h:151
Stores results of sweep queries.
Definition PxGeometryHit.h:175
Returns scene query hits (intersections) to the user in a preallocated buffer.
Definition PxQueryReport.h:172
PX_INLINE const HitType & getAnyHit(const PxU32 index) const
Convenience iterator used to access any hits in this result, blocking or touching.
Definition PxQueryReport.h:188
virtual PxAgain processTouches(const HitType *buffer, PxU32 nbHits)
virtual callback function used to communicate query results to the user.
Definition PxQueryReport.h:200
PxHitBuffer(HitType *aTouches=NULL, PxU32 aMaxNbTouches=0)
Initializes the buffer with user memory.
Definition PxQueryReport.h:183
PX_INLINE PxU32 getNbAnyHits() const
Computes the number of any hits in this result, blocking or touching.
Definition PxQueryReport.h:186
This callback class facilitates reporting scene query hits (intersections) to the user.
Definition PxQueryReport.h:95
bool hasBlock
Set to true if there was a blocking hit during query.
Definition PxQueryReport.h:97
virtual PxAgain processTouches(const HitType *buffer, PxU32 nbHits)=0
virtual callback function used to communicate query results to the user.
HitType block
Holds the closest blocking hit result for the query. Invalid if hasBlock is false.
Definition PxQueryReport.h:96
PxU32 maxNbTouches
Size of the user specified touching hits buffer.
Definition PxQueryReport.h:105
PxU32 nbTouches
Number of touching hits returned by the query. Used with PxHitBuffer.
Definition PxQueryReport.h:110
PX_FORCE_INLINE bool hasAnyHits()
Returns true if any blocking or touching hits were encountered during a query.
Definition PxQueryReport.h:154
HitType * touches
User specified buffer for touching hits.
Definition PxQueryReport.h:99
virtual void finalizeQuery()
Query finalization callback, called after the last processTouches callback.
Definition PxQueryReport.h:149
PxHitCallback(HitType *aTouches, PxU32 aMaxNbTouches)
Initializes the class with user provided buffer.
Definition PxQueryReport.h:123
Returns touching overlap hits to the user in a fixed size array embedded in the buffer class.
Definition PxQueryReport.h:232
Definition PxQueryReport.h:67
single hit cache for scene queries.
Definition PxQueryReport.h:264
PxShape * shape
Shape to test for intersection first.
Definition PxQueryReport.h:275
PX_INLINE PxQueryCache(PxShape *s, PxU32 findex)
constructor to set properties
Definition PxQueryReport.h:273
PX_INLINE PxQueryCache()
constructor sets to default
Definition PxQueryReport.h:268
PxRigidActor * actor
Actor to which the shape belongs.
Definition PxQueryReport.h:276
PxU32 faceIndex
Triangle index to test first - NOT CURRENTLY SUPPORTED.
Definition PxQueryReport.h:277
A per-thread context passed to low-level query functions.
Definition PxGeometryQueryContext.h:52
Returns touching raycast hits to the user in a fixed size array embedded in the buffer class.
Definition PxQueryReport.h:224
Definition PxQueryReport.h:66
Returns touching sweep hits to the user in a fixed size array embedded in the buffer class.
Definition PxQueryReport.h:240
Definition PxQueryReport.h:68