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-2018 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 "PxPhysXConfig.h"
37 #include "foundation/PxVec3.h"
38 #include "foundation/PxFlags.h"
39 
40 #if !PX_DOXYGEN
41 namespace physx
42 {
43 #endif
44 
45 class PxShape;
46 class PxRigidActor;
47 
61 struct PxHitFlag
62 {
63  enum Enum
64  {
65  ePOSITION = (1<<0),
66  eNORMAL = (1<<1),
67  eUV = (1<<3),
68  eASSUME_NO_INITIAL_OVERLAP = (1<<4),
69  eMESH_MULTIPLE = (1<<5),
71  eMESH_ANY = (1<<6),
72  eMESH_BOTH_SIDES = (1<<7),
74  ePRECISE_SWEEP = (1<<8),
77  eMTD = (1<<9),
79  eFACE_INDEX = (1<<10),
80 
81  eDEFAULT = ePOSITION|eNORMAL|eFACE_INDEX,
82 
84  eMODIFIABLE_FLAGS = eMESH_MULTIPLE|eMESH_BOTH_SIDES|eASSUME_NO_INITIAL_OVERLAP|ePRECISE_SWEEP
85  };
86 };
87 
88 
94 PX_FLAGS_TYPEDEF(PxHitFlag, PxU16)
95 
96 
104 {
105  PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {}
106  PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {}
107 
110 };
111 
112 
116 struct PxQueryHit : public PxActorShape
117 {
118  PX_INLINE PxQueryHit() : faceIndex(0xFFFFffff) {}
119 
129 };
130 
137 struct PxLocationHit : public PxQueryHit
138 {
139  PX_INLINE PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL) {}
140 
147  PX_INLINE bool hadInitialOverlap() const { return (distance <= 0.0f); }
148 
149  // the following fields are set in accordance with the #PxHitFlags
150  PxHitFlags flags;
153 
159 };
160 
161 
174 {
175  PX_INLINE PxRaycastHit() : u(0.0f), v(0.0f) {}
176 
177  // the following fields are set in accordance with the #PxHitFlags
178 
179  PxReal u, v;
180 #if !PX_P64_FAMILY
181  PxU32 padTo16Bytes[3];
182 #endif
183 };
184 
185 
192 
193 
199 struct PxSweepHit : public PxLocationHit
200 {
202 
204 };
205 
206 
215 typedef bool PxAgain;
216 
217 
231 template<typename HitType>
233 {
234  HitType block;
235  bool hasBlock;
236 
237  HitType* touches;
238 
244 
249 
261  PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches)
262  : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0)
263  {}
264 
285  virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0;
286 
287  virtual void finalizeQuery() {}
288 
289  virtual ~PxHitCallback() {}
290 
292  PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); }
293 };
294 
295 
309 template<typename HitType>
310 struct PxHitBuffer : public PxHitCallback<HitType>
311 {
322  PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {}
323 
325  PX_INLINE PxU32 getNbAnyHits() const { return getNbTouches() + PxU32(this->hasBlock); }
327  PX_INLINE const HitType& getAnyHit(const PxU32 index) const { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock));
328  return index < getNbTouches() ? getTouches()[index] : this->block; }
329 
330  PX_INLINE PxU32 getNbTouches() const { return this->nbTouches; }
331  PX_INLINE const HitType* getTouches() const { return this->touches; }
332  PX_INLINE const HitType& getTouch(const PxU32 index) const { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; }
333  PX_INLINE PxU32 getMaxNbTouches() const { return this->maxNbTouches; }
334 
335  virtual ~PxHitBuffer() {}
336 
337 protected:
338  // stops after the first callback
339  virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; }
340 };
341 
342 
345 
348 
351 
354 
357 
360 
362 template <int N>
363 struct PxRaycastBufferN : public PxHitBuffer<PxRaycastHit>
364 {
365  PxRaycastHit hits[N];
367 };
368 
370 template <int N>
371 struct PxOverlapBufferN : public PxHitBuffer<PxOverlapHit>
372 {
373  PxOverlapHit hits[N];
375 };
376 
378 template <int N>
379 struct PxSweepBufferN : public PxHitBuffer<PxSweepHit>
380 {
381  PxSweepHit hits[N];
383 };
384 
385 #if !PX_DOXYGEN
386 } // namespace physx
387 #endif
388 
390 #endif
Definition: GuContactBuffer.h:37
PX_INLINE PxActorShape(PxRigidActor *a, PxShape *s)
Definition: PxQueryReport.h:106
PxHitBuffer< PxRaycastHit > PxRaycastBuffer
Raycast query buffer.
Definition: PxQueryReport.h:353
PxHitCallback< PxRaycastHit > PxRaycastCallback
Raycast query callback.
Definition: PxQueryReport.h:344
PxHitBuffer< PxSweepHit > PxSweepBuffer
Sweep query buffer.
Definition: PxQueryReport.h:359
float PxF32
Definition: PxSimpleTypes.h:76
virtual ~PxHitCallback()
Definition: PxQueryReport.h:289
collection of set bits defined in PxHitFlag.
Definition: PxQueryReport.h:103
PxF32 distance
Distance to hit.
Definition: PxQueryReport.h:158
Abstract class for collision shapes.
Definition: PxShape.h:142
PX_INLINE const HitType & getTouch(const PxU32 index) const
Definition: PxQueryReport.h:332
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
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:179
PX_INLINE PxQueryHit()
Definition: PxQueryReport.h:118
PxHitCallback< PxSweepHit > PxSweepCallback
Sweep query callback.
Definition: PxQueryReport.h:350
PX_INLINE PxLocationHit()
Definition: PxQueryReport.h:139
#define PX_MAX_REAL
Definition: PxSimpleTypes.h:93
uint32_t PxU32
Definition: PxSimpleTypes.h:71
PxRaycastBufferN()
Definition: PxQueryReport.h:366
Scene query and geometry query behavior flags.
Definition: PxQueryReport.h:61
bool hasBlock
Set to true if there was a blocking hit during query.
Definition: PxQueryReport.h:235
PX_INLINE const HitType * getTouches() const
Definition: PxQueryReport.h:331
PxRigidActor * actor
Definition: PxQueryReport.h:108
PxHitFlags flags
Hit flags specifying which members contain valid values.
Definition: PxQueryReport.h:150
PX_INLINE PxU32 getMaxNbTouches() const
Definition: PxQueryReport.h:333
PxU32 nbTouches
Number of touching hits returned by the query. Used with PxHitBuffer.
Definition: PxQueryReport.h:248
PxU32 padTo16Bytes
Definition: PxQueryReport.h:203
PxSweepBufferN()
Definition: PxQueryReport.h:382
PX_INLINE PxU32 getNbAnyHits() const
Computes the number of any hits in this result, blocking or touching.
Definition: PxQueryReport.h:325
PxU32 padTo16Bytes
Definition: PxQueryReport.h:191
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:310
PxShape * shape
Definition: PxQueryReport.h:109
bool PxAgain
Describes query behavior after returning a partial query result via a callback.
Definition: PxQueryReport.h:215
HitType block
Holds the closest blocking hit result for the query. Invalid if hasBlock is false.
Definition: PxQueryReport.h:234
PX_INLINE PxRaycastHit()
Definition: PxQueryReport.h:175
Scene query hit information for raycasts and sweeps returning hit position and normal information...
Definition: PxQueryReport.h:137
PxVec3 normal
World-space hit normal (flag: PxHitFlag::eNORMAL)
Definition: PxQueryReport.h:152
PX_INLINE bool hadInitialOverlap() const
Definition: PxQueryReport.h:147
PxVec3 position
World-space hit position (flag: PxHitFlag::ePOSITION)
Definition: PxQueryReport.h:151
HitType * touches
User specified buffer for touching hits.
Definition: PxQueryReport.h:237
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:327
PxU16 flags
a set of Px1DConstraintFlags
Definition: PxConstraintDesc.h:110
PxU32 faceIndex
Definition: PxQueryReport.h:128
PxOverlapBufferN()
Definition: PxQueryReport.h:374
Enum
Definition: PxQueryReport.h:63
PxU32 maxNbTouches
Size of the user specified touching hits buffer.
Definition: PxQueryReport.h:243
This callback class facilitates reporting scene query hits (intersections) to the user...
Definition: PxQueryReport.h:232
Returns touching sweep hits to the user in a fixed size array embedded in the buffer class...
Definition: PxQueryReport.h:379
Scene query hit information.
Definition: PxQueryReport.h:116
virtual PxAgain processTouches(const HitType *buffer, PxU32 nbHits)
virtual callback function used to communicate query results to the user.
Definition: PxQueryReport.h:339
Returns touching raycast hits to the user in a fixed size array embedded in the buffer class...
Definition: PxQueryReport.h:363
PX_INLINE PxActorShape()
Definition: PxQueryReport.h:105
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:479
PX_FORCE_INLINE bool hasAnyHits()
Returns true if any blocking or touching hits were encountered during a query.
Definition: PxQueryReport.h:292
PX_INLINE PxU32 getNbTouches() const
Definition: PxQueryReport.h:330
PxHitCallback(HitType *aTouches, PxU32 aMaxNbTouches)
Initializes the class with user provided buffer.
Definition: PxQueryReport.h:261
Stores results of overlap queries.
Definition: PxQueryReport.h:191
PxHitCallback< PxOverlapHit > PxOverlapCallback
Overlap query callback.
Definition: PxQueryReport.h:347
virtual ~PxHitBuffer()
Definition: PxQueryReport.h:335
#define PX_ASSERT(exp)
Definition: PxAssert.h:61
Stores results of sweep queries.
Definition: PxQueryReport.h:199
Stores results of raycast queries.
Definition: PxQueryReport.h:173
uint16_t PxU16
Definition: PxSimpleTypes.h:73
uint32_t PxU32
Definition: Px.h:48
PX_INLINE PxSweepHit()
Definition: PxQueryReport.h:201
PxHitBuffer(HitType *aTouches=NULL, PxU32 aMaxNbTouches=0)
Initializes the buffer with user memory.
Definition: PxQueryReport.h:322
#define PX_INLINE
Definition: PxPreprocessor.h:349
virtual void finalizeQuery()
Query finalization callback, called after the last processTouches callback.
Definition: PxQueryReport.h:287
PxHitBuffer< PxOverlapHit > PxOverlapBuffer
Overlap query buffer.
Definition: PxQueryReport.h:356
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:371