PxQueryReport.h
Go to the documentation of this file.
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_NX_SCENEQUERYREPORT
32 #define PX_PHYSICS_NX_SCENEQUERYREPORT
33 
36 #include "foundation/PxVec3.h"
37 #include "foundation/PxFlags.h"
38 #include "foundation/PxAssert.h"
39 #include "PxPhysXConfig.h"
40 
41 #if !PX_DOXYGEN
42 namespace physx
43 {
44 #endif
45 
46 class PxShape;
47 class PxRigidActor;
48 
62 struct PxHitFlag
63 {
64  enum Enum
65  {
66  ePOSITION = (1<<0),
67  eNORMAL = (1<<1),
68  eUV = (1<<3),
69  eASSUME_NO_INITIAL_OVERLAP = (1<<4),
70  eMESH_MULTIPLE = (1<<5),
72  eMESH_ANY = (1<<6),
73  eMESH_BOTH_SIDES = (1<<7),
75  ePRECISE_SWEEP = (1<<8),
78  eMTD = (1<<9),
80  eFACE_INDEX = (1<<10),
81 
82  eDEFAULT = ePOSITION|eNORMAL|eFACE_INDEX,
83 
85  eMODIFIABLE_FLAGS = eMESH_MULTIPLE|eMESH_BOTH_SIDES|eASSUME_NO_INITIAL_OVERLAP|ePRECISE_SWEEP
86  };
87 };
88 
89 
95 PX_FLAGS_TYPEDEF(PxHitFlag, PxU16)
96 
97 
105 {
106  PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {}
107  PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {}
108 
111 };
112 
113 
117 struct PxQueryHit : public PxActorShape
118 {
119  PX_INLINE PxQueryHit() : faceIndex(0xFFFFffff) {}
120 
130 };
131 
138 struct PxLocationHit : public PxQueryHit
139 {
140  PX_INLINE PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL) {}
141 
148  PX_INLINE bool hadInitialOverlap() const { return (distance <= 0.0f); }
149 
150  // the following fields are set in accordance with the #PxHitFlags
151  PxHitFlags flags;
154 
160 };
161 
162 
175 {
176  PX_INLINE PxRaycastHit() : u(0.0f), v(0.0f) {}
177 
178  // the following fields are set in accordance with the #PxHitFlags
179 
180  PxReal u, v;
181 #if !PX_P64_FAMILY
182  PxU32 padTo16Bytes[3];
183 #endif
184 };
185 
186 
193 
194 
200 struct PxSweepHit : public PxLocationHit
201 {
203 
205 };
206 
207 
216 typedef bool PxAgain;
217 
218 
232 template<typename HitType>
234 {
235  HitType block;
236  bool hasBlock;
237 
238  HitType* touches;
239 
245 
250 
262  PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches)
263  : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0)
264  {}
265 
286  virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0;
287 
288  virtual void finalizeQuery() {}
289 
290  virtual ~PxHitCallback() {}
291 
293  PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); }
294 };
295 
296 
310 template<typename HitType>
311 struct PxHitBuffer : public PxHitCallback<HitType>
312 {
323  PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {}
324 
326  PX_INLINE PxU32 getNbAnyHits() const { return getNbTouches() + PxU32(this->hasBlock); }
328  PX_INLINE const HitType& getAnyHit(const PxU32 index) const { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock));
329  return index < getNbTouches() ? getTouches()[index] : this->block; }
330 
331  PX_INLINE PxU32 getNbTouches() const { return this->nbTouches; }
332  PX_INLINE const HitType* getTouches() const { return this->touches; }
333  PX_INLINE const HitType& getTouch(const PxU32 index) const { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; }
334  PX_INLINE PxU32 getMaxNbTouches() const { return this->maxNbTouches; }
335 
336  virtual ~PxHitBuffer() {}
337 
338 protected:
339  // stops after the first callback
340  virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; }
341 };
342 
343 
346 
349 
352 
355 
358 
361 
363 template <int N>
364 struct PxRaycastBufferN : public PxHitBuffer<PxRaycastHit>
365 {
366  PxRaycastHit hits[N];
368 };
369 
371 template <int N>
372 struct PxOverlapBufferN : public PxHitBuffer<PxOverlapHit>
373 {
374  PxOverlapHit hits[N];
376 };
377 
379 template <int N>
380 struct PxSweepBufferN : public PxHitBuffer<PxSweepHit>
381 {
382  PxSweepHit hits[N];
384 };
385 
386 #if !PX_DOXYGEN
387 } // namespace physx
388 #endif
389 
391 #endif
Definition: GuContactBuffer.h:37
PX_INLINE PxActorShape(PxRigidActor *a, PxShape *s)
Definition: PxQueryReport.h:107
PxHitBuffer< PxRaycastHit > PxRaycastBuffer
Raycast query buffer.
Definition: PxQueryReport.h:354
PxHitCallback< PxRaycastHit > PxRaycastCallback
Raycast query callback.
Definition: PxQueryReport.h:345
PxHitBuffer< PxSweepHit > PxSweepBuffer
Sweep query buffer.
Definition: PxQueryReport.h:360
float PxF32
Definition: PxSimpleTypes.h:76
virtual ~PxHitCallback()
Definition: PxQueryReport.h:290
collection of set bits defined in PxHitFlag.
Definition: PxQueryReport.h:104
PxF32 distance
Distance to hit.
Definition: PxQueryReport.h:159
Abstract class for collision shapes.
Definition: PxShape.h:142
PX_INLINE const HitType & getTouch(const PxU32 index) const
Definition: PxQueryReport.h:333
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
float PxReal
Definition: PxSimpleTypes.h:78
PxReal v
barycentric coordinates of hit point, for triangle mesh and height field (flag: PxHitFlag::eUV) ...
Definition: PxQueryReport.h:180
PX_INLINE PxQueryHit()
Definition: PxQueryReport.h:119
PxHitCallback< PxSweepHit > PxSweepCallback
Sweep query callback.
Definition: PxQueryReport.h:351
PX_INLINE PxLocationHit()
Definition: PxQueryReport.h:140
#define PX_MAX_REAL
Definition: PxSimpleTypes.h:93
uint32_t PxU32
Definition: PxSimpleTypes.h:71
PxRaycastBufferN()
Definition: PxQueryReport.h:367
Scene query and geometry query behavior flags.
Definition: PxQueryReport.h:62
bool hasBlock
Set to true if there was a blocking hit during query.
Definition: PxQueryReport.h:236
PX_INLINE const HitType * getTouches() const
Definition: PxQueryReport.h:332
PxRigidActor * actor
Definition: PxQueryReport.h:109
PxHitFlags flags
Hit flags specifying which members contain valid values.
Definition: PxQueryReport.h:151
PX_INLINE PxU32 getMaxNbTouches() const
Definition: PxQueryReport.h:334
PxU32 nbTouches
Number of touching hits returned by the query. Used with PxHitBuffer.
Definition: PxQueryReport.h:249
PxU32 padTo16Bytes
Definition: PxQueryReport.h:204
PxSweepBufferN()
Definition: PxQueryReport.h:383
PX_INLINE PxU32 getNbAnyHits() const
Computes the number of any hits in this result, blocking or touching.
Definition: PxQueryReport.h:326
PxU32 padTo16Bytes
Definition: PxQueryReport.h:192
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition: PxRigidActor.h:58
Returns scene query hits (intersections) to the user in a preallocated buffer.
Definition: PxQueryReport.h:311
PxShape * shape
Definition: PxQueryReport.h:110
bool PxAgain
Describes query behavior after returning a partial query result via a callback.
Definition: PxQueryReport.h:216
HitType block
Holds the closest blocking hit result for the query. Invalid if hasBlock is false.
Definition: PxQueryReport.h:235
PX_INLINE PxRaycastHit()
Definition: PxQueryReport.h:176
Scene query hit information for raycasts and sweeps returning hit position and normal information...
Definition: PxQueryReport.h:138
PxVec3 normal
World-space hit normal (flag: PxHitFlag::eNORMAL)
Definition: PxQueryReport.h:153
PX_INLINE bool hadInitialOverlap() const
Definition: PxQueryReport.h:148
PxVec3 position
World-space hit position (flag: PxHitFlag::ePOSITION)
Definition: PxQueryReport.h:152
HitType * touches
User specified buffer for touching hits.
Definition: PxQueryReport.h:238
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:328
PxU16 flags
a set of Px1DConstraintFlags
Definition: PxConstraintDesc.h:110
PxU32 faceIndex
Definition: PxQueryReport.h:129
PxOverlapBufferN()
Definition: PxQueryReport.h:375
Enum
Definition: PxQueryReport.h:64
PxU32 maxNbTouches
Size of the user specified touching hits buffer.
Definition: PxQueryReport.h:244
This callback class facilitates reporting scene query hits (intersections) to the user...
Definition: PxQueryReport.h:233
Returns touching sweep hits to the user in a fixed size array embedded in the buffer class...
Definition: PxQueryReport.h:380
Scene query hit information.
Definition: PxQueryReport.h:117
virtual PxAgain processTouches(const HitType *buffer, PxU32 nbHits)
virtual callback function used to communicate query results to the user.
Definition: PxQueryReport.h:340
Returns touching raycast hits to the user in a fixed size array embedded in the buffer class...
Definition: PxQueryReport.h:364
PX_INLINE PxActorShape()
Definition: PxQueryReport.h:106
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:466
PX_FORCE_INLINE bool hasAnyHits()
Returns true if any blocking or touching hits were encountered during a query.
Definition: PxQueryReport.h:293
PX_INLINE PxU32 getNbTouches() const
Definition: PxQueryReport.h:331
PxHitCallback(HitType *aTouches, PxU32 aMaxNbTouches)
Initializes the class with user provided buffer.
Definition: PxQueryReport.h:262
Stores results of overlap queries.
Definition: PxQueryReport.h:192
PxHitCallback< PxOverlapHit > PxOverlapCallback
Overlap query callback.
Definition: PxQueryReport.h:348
virtual ~PxHitBuffer()
Definition: PxQueryReport.h:336
#define PX_ASSERT(exp)
Definition: PxAssert.h:59
Stores results of sweep queries.
Definition: PxQueryReport.h:200
Stores results of raycast queries.
Definition: PxQueryReport.h:174
uint16_t PxU16
Definition: PxSimpleTypes.h:73
uint32_t PxU32
Definition: Px.h:48
PX_INLINE PxSweepHit()
Definition: PxQueryReport.h:202
PxHitBuffer(HitType *aTouches=NULL, PxU32 aMaxNbTouches=0)
Initializes the buffer with user memory.
Definition: PxQueryReport.h:323
#define PX_INLINE
Definition: PxPreprocessor.h:336
virtual void finalizeQuery()
Query finalization callback, called after the last processTouches callback.
Definition: PxQueryReport.h:288
PxHitBuffer< PxOverlapHit > PxOverlapBuffer
Overlap query buffer.
Definition: PxQueryReport.h:357
3 Element vector class.
Definition: PxVec3.h:49
Returns touching overlap hits to the user in a fixed size array embedded in the buffer class...
Definition: PxQueryReport.h:372