PxQueryReport.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_PHYSICS_NX_SCENEQUERYREPORT
00032 #define PX_PHYSICS_NX_SCENEQUERYREPORT
00033 
00036 #include "PxPhysXConfig.h"
00037 #include "foundation/PxVec3.h"
00038 #include "foundation/PxFlags.h"
00039 
00040 #if !PX_DOXYGEN
00041 namespace physx
00042 {
00043 #endif
00044 
00045 class PxShape;
00046 class PxRigidActor;
00047 
00061 struct PxHitFlag
00062 {
00063     enum Enum
00064     {
00065         ePOSITION                   = (1<<0),   
00066         eNORMAL                     = (1<<1),   
00067         eUV                         = (1<<3),   
00068         eASSUME_NO_INITIAL_OVERLAP  = (1<<4),   
00069 
00070         eMESH_MULTIPLE              = (1<<5),   
00071         eMESH_ANY                   = (1<<6),   
00072 
00073         eMESH_BOTH_SIDES            = (1<<7),   
00074 
00075 
00076         ePRECISE_SWEEP              = (1<<8),   
00077 
00078         eMTD                        = (1<<9),   
00079         eFACE_INDEX                 = (1<<10),  
00080 
00081         eDEFAULT                    = ePOSITION|eNORMAL|eFACE_INDEX,
00082 
00084         eMODIFIABLE_FLAGS           = eMESH_MULTIPLE|eMESH_BOTH_SIDES|eASSUME_NO_INITIAL_OVERLAP|ePRECISE_SWEEP
00085     };
00086 };
00087 
00088 
00094 PX_FLAGS_TYPEDEF(PxHitFlag, PxU16)
00095 
00096 
00103 struct PxActorShape
00104 {
00105     PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {}
00106     PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {}
00107 
00108     PxRigidActor*   actor;
00109     PxShape*        shape;
00110 };
00111 
00112 
00116 struct PxQueryHit : public PxActorShape
00117 {
00118     PX_INLINE           PxQueryHit() : faceIndex(0xFFFFffff) {}
00119 
00128     PxU32               faceIndex;
00129 };
00130 
00137 struct PxLocationHit : public PxQueryHit
00138 {
00139     PX_INLINE           PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL)   {}
00140 
00147     PX_INLINE bool      hadInitialOverlap() const { return (distance <= 0.0f); }
00148 
00149     // the following fields are set in accordance with the #PxHitFlags
00150     PxHitFlags          flags;      
00151     PxVec3              position;   
00152     PxVec3              normal;     
00153 
00158     PxF32               distance;
00159 };
00160 
00161 
00173 struct PxRaycastHit : public PxLocationHit
00174 {
00175     PX_INLINE           PxRaycastHit() : u(0.0f), v(0.0f)   {}
00176 
00177     // the following fields are set in accordance with the #PxHitFlags
00178 
00179     PxReal  u, v;           
00180 #if !PX_P64_FAMILY
00181     PxU32   padTo16Bytes[3];
00182 #endif
00183 };
00184 
00185 
00191 struct PxOverlapHit: public PxQueryHit { PxU32 padTo16Bytes; };
00192 
00193 
00199 struct PxSweepHit : public PxLocationHit
00200 {
00201     PX_INLINE           PxSweepHit() {}
00202 
00203     PxU32               padTo16Bytes;
00204 };
00205 
00206 
00215 typedef bool PxAgain;
00216 
00217 
00231 template<typename HitType>
00232 struct PxHitCallback
00233 {
00234     HitType     block;          
00235     bool        hasBlock;       
00236 
00237     HitType*    touches;        
00238 
00243     PxU32       maxNbTouches;
00244 
00248     PxU32       nbTouches;
00249 
00261     PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches)
00262         : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0)
00263     {}
00264 
00285     virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0;
00286 
00287     virtual void finalizeQuery() {} 
00288 
00289     virtual ~PxHitCallback() {}
00290 
00292     PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); }
00293 };
00294 
00295 
00309 template<typename HitType>
00310 struct PxHitBuffer : public PxHitCallback<HitType>
00311 {
00322     PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {}
00323 
00325     PX_INLINE PxU32             getNbAnyHits() const                { return getNbTouches() + PxU32(this->hasBlock); }
00327     PX_INLINE const HitType&    getAnyHit(const PxU32 index) const  { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock));
00328                                                                         return index < getNbTouches() ? getTouches()[index] : this->block; }
00329 
00330     PX_INLINE PxU32             getNbTouches() const                { return this->nbTouches; }
00331     PX_INLINE const HitType*    getTouches() const                  { return this->touches; }
00332     PX_INLINE const HitType&    getTouch(const PxU32 index) const   { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; }
00333     PX_INLINE PxU32             getMaxNbTouches() const             { return this->maxNbTouches; }
00334 
00335     virtual ~PxHitBuffer() {}
00336 
00337 protected:
00338     // stops after the first callback
00339     virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; }
00340 };
00341 
00342 
00344 typedef PxHitCallback<PxRaycastHit> PxRaycastCallback;
00345 
00347 typedef PxHitCallback<PxOverlapHit> PxOverlapCallback;
00348 
00350 typedef PxHitCallback<PxSweepHit> PxSweepCallback;
00351 
00353 typedef PxHitBuffer<PxRaycastHit> PxRaycastBuffer;
00354 
00356 typedef PxHitBuffer<PxOverlapHit> PxOverlapBuffer;
00357 
00359 typedef PxHitBuffer<PxSweepHit> PxSweepBuffer;
00360 
00362 template <int N>
00363 struct PxRaycastBufferN : public PxHitBuffer<PxRaycastHit>
00364 {
00365     PxRaycastHit hits[N];
00366     PxRaycastBufferN() : PxHitBuffer<PxRaycastHit>(hits, N) {}
00367 };
00368 
00370 template <int N>
00371 struct PxOverlapBufferN : public PxHitBuffer<PxOverlapHit>
00372 {
00373     PxOverlapHit hits[N];
00374     PxOverlapBufferN() : PxHitBuffer<PxOverlapHit>(hits, N) {}
00375 };
00376 
00378 template <int N>
00379 struct PxSweepBufferN : public PxHitBuffer<PxSweepHit>
00380 {
00381     PxSweepHit hits[N];
00382     PxSweepBufferN() : PxHitBuffer<PxSweepHit>(hits, N) {}
00383 };
00384 
00385 #if !PX_DOXYGEN
00386 } // namespace physx
00387 #endif
00388 
00390 #endif


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com