PxQueryReport.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         PX_DEPRECATED eDISTANCE     = (1<<2),   
00068         eUV                         = (1<<3),   
00069         eASSUME_NO_INITIAL_OVERLAP  = (1<<4),   
00070 
00071         eMESH_MULTIPLE              = (1<<5),   
00072         eMESH_ANY                   = (1<<6),   
00073 
00074         eMESH_BOTH_SIDES            = (1<<7),   
00075 
00076 
00077         ePRECISE_SWEEP              = (1<<8),   
00078 
00079         eMTD                        = (1<<9),   
00080         eFACE_INDEX                 = (1<<10),  
00081 
00082         eDEFAULT                    = ePOSITION|eNORMAL|eDISTANCE|eFACE_INDEX,
00083 
00085         eMODIFIABLE_FLAGS           = eMESH_MULTIPLE|eMESH_BOTH_SIDES|eASSUME_NO_INITIAL_OVERLAP|ePRECISE_SWEEP
00086     };
00087 };
00088 
00089 
00095 PX_FLAGS_TYPEDEF(PxHitFlag, PxU16)
00096 
00097 
00104 struct PxActorShape
00105 {
00106     PX_INLINE PxActorShape() : actor(NULL), shape(NULL) {}
00107     PX_INLINE PxActorShape(PxRigidActor* a, PxShape* s) : actor(a), shape(s) {}
00108 
00109     PxRigidActor*   actor;
00110     PxShape*        shape;
00111 };
00112 
00113 
00117 struct PxQueryHit : public PxActorShape
00118 {
00119     PX_INLINE           PxQueryHit() : faceIndex(0xFFFFffff) {}
00120 
00129     PxU32               faceIndex;
00130 };
00131 
00138 struct PxLocationHit : public PxQueryHit
00139 {
00140     PX_INLINE           PxLocationHit() : flags(0), position(PxVec3(0)), normal(PxVec3(0)), distance(PX_MAX_REAL)   {}
00141 
00148     PX_INLINE bool      hadInitialOverlap() const { return (distance <= 0.0f); }
00149 
00150     // the following fields are set in accordance with the #PxHitFlags
00151     PxHitFlags          flags;      
00152     PxVec3              position;   
00153     PxVec3              normal;     
00154 
00159     PxF32               distance;
00160 };
00161 
00162 
00174 struct PxRaycastHit : public PxLocationHit
00175 {
00176     PX_INLINE           PxRaycastHit() : u(0.0f), v(0.0f)   {}
00177 
00178     // the following fields are set in accordance with the #PxHitFlags
00179 
00180     PxReal  u, v;           
00181 #if !PX_P64_FAMILY
00182     PxU32   padTo16Bytes[3];
00183 #endif
00184 };
00185 
00186 
00192 struct PxOverlapHit: public PxQueryHit { PxU32 padTo16Bytes; };
00193 
00194 
00200 struct PxSweepHit : public PxLocationHit
00201 {
00202     PX_INLINE           PxSweepHit() {}
00203 
00204     PxU32               padTo16Bytes;
00205 };
00206 
00207 
00216 typedef bool PxAgain;
00217 
00218 
00232 template<typename HitType>
00233 struct PxHitCallback
00234 {
00235     HitType     block;          
00236     bool        hasBlock;       
00237 
00238     HitType*    touches;        
00239 
00244     PxU32       maxNbTouches;
00245 
00249     PxU32       nbTouches;
00250 
00262     PxHitCallback(HitType* aTouches, PxU32 aMaxNbTouches)
00263         : hasBlock(false), touches(aTouches), maxNbTouches(aMaxNbTouches), nbTouches(0)
00264     {}
00265 
00286     virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) = 0;
00287 
00288     virtual void finalizeQuery() {} 
00289 
00290     virtual ~PxHitCallback() {}
00291 
00293     PX_FORCE_INLINE bool hasAnyHits() { return (hasBlock || (nbTouches > 0)); }
00294 };
00295 
00296 
00310 template<typename HitType>
00311 struct PxHitBuffer : public PxHitCallback<HitType>
00312 {
00323     PxHitBuffer(HitType* aTouches = NULL, PxU32 aMaxNbTouches = 0) : PxHitCallback<HitType>(aTouches, aMaxNbTouches) {}
00324 
00326     PX_INLINE PxU32             getNbAnyHits() const                { return getNbTouches() + PxU32(this->hasBlock); }
00328     PX_INLINE const HitType&    getAnyHit(const PxU32 index) const  { PX_ASSERT(index < getNbTouches() + PxU32(this->hasBlock));
00329                                                                         return index < getNbTouches() ? getTouches()[index] : this->block; }
00330 
00331     PX_INLINE PxU32             getNbTouches() const                { return this->nbTouches; }
00332     PX_INLINE const HitType*    getTouches() const                  { return this->touches; }
00333     PX_INLINE const HitType&    getTouch(const PxU32 index) const   { PX_ASSERT(index < getNbTouches()); return getTouches()[index]; }
00334     PX_INLINE PxU32             getMaxNbTouches() const             { return this->maxNbTouches; }
00335 
00336     virtual ~PxHitBuffer() {}
00337 
00338 protected:
00339     // stops after the first callback
00340     virtual PxAgain processTouches(const HitType* buffer, PxU32 nbHits) { PX_UNUSED(buffer); PX_UNUSED(nbHits); return false; }
00341 };
00342 
00343 
00345 typedef PxHitCallback<PxRaycastHit> PxRaycastCallback;
00346 
00348 typedef PxHitCallback<PxOverlapHit> PxOverlapCallback;
00349 
00351 typedef PxHitCallback<PxSweepHit> PxSweepCallback;
00352 
00354 typedef PxHitBuffer<PxRaycastHit> PxRaycastBuffer;
00355 
00357 typedef PxHitBuffer<PxOverlapHit> PxOverlapBuffer;
00358 
00360 typedef PxHitBuffer<PxSweepHit> PxSweepBuffer;
00361 
00363 template <int N>
00364 struct PxRaycastBufferN : public PxHitBuffer<PxRaycastHit>
00365 {
00366     PxRaycastHit hits[N];
00367     PxRaycastBufferN() : PxHitBuffer<PxRaycastHit>(hits, N) {}
00368 };
00369 
00371 template <int N>
00372 struct PxOverlapBufferN : public PxHitBuffer<PxOverlapHit>
00373 {
00374     PxOverlapHit hits[N];
00375     PxOverlapBufferN() : PxHitBuffer<PxOverlapHit>(hits, N) {}
00376 };
00377 
00379 template <int N>
00380 struct PxSweepBufferN : public PxHitBuffer<PxSweepHit>
00381 {
00382     PxSweepHit hits[N];
00383     PxSweepBufferN() : PxHitBuffer<PxSweepHit>(hits, N) {}
00384 };
00385 
00386 #if !PX_DOXYGEN
00387 } // namespace physx
00388 #endif
00389 
00391 #endif


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