PhysX SDK 3.2 API Reference: PxSimulationEventCallback.h Source File

PhysX SDK 3.2 API

PxSimulationEventCallback.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-2012 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_SIMULATION_EVENT_CALLBACK
00032 #define PX_SIMULATION_EVENT_CALLBACK
00033 
00037 #include "foundation/PxVec3.h"
00038 #include "PxPhysX.h"
00039 #include "PxFiltering.h"
00040 #include "PxContact.h"
00041 
00042 #ifndef PX_DOXYGEN
00043 namespace physx
00044 {
00045 #endif
00046 
00047 class PxShape;
00048 class PxActor;
00049 class PxConstraint;
00050 
00056 struct PxContactPairHeaderFlag
00057 {
00058     enum Enum
00059     {
00060         eDELETED_ACTOR_0                = (1<<0),   
00061         eDELETED_ACTOR_1                = (1<<1),   
00062     };
00063 };
00064 
00070 typedef PxFlags<PxContactPairHeaderFlag::Enum, PxU16> PxContactPairHeaderFlags;
00071 PX_FLAGS_OPERATORS(PxContactPairHeaderFlag::Enum, PxU16);
00072 
00073 
00079 struct PxContactPairHeader
00080 {
00081     public:
00082         PX_INLINE   PxContactPairHeader() {}
00083 
00095     PxActor*                    actors[2];
00096 
00102     PxContactPairHeaderFlags    flags;
00103 };
00104 
00105 
00111 struct PxContactPairFlag
00112 {
00113     enum Enum
00114     {
00118         eDELETED_SHAPE_0                = (1<<0),
00119 
00123         eDELETED_SHAPE_1                = (1<<1),
00124         
00132         eACTOR_PAIR_HAS_FIRST_TOUCH     = (1<<2),
00133 
00139         eACTOR_PAIR_LOST_TOUCH          = (1<<3),
00140 
00146         eINTERNAL_HAS_FACE_INDICES      = (1<<4),
00147 
00154         eINTERNAL_HAS_IMPULSES          = (1<<5),
00155 
00161         eINTERNAL_CONTACTS_ARE_FLIPPED  = (1<<6)
00162     };
00163 };
00164 
00170 typedef PxFlags<PxContactPairFlag::Enum, PxU16> PxContactPairFlags;
00171 PX_FLAGS_OPERATORS(PxContactPairFlag::Enum, PxU16);
00172 
00173 
00177 struct PxContactPairPoint
00178 {
00182     PxVec3  position;
00183 
00187     PxReal  separation;
00188 
00192     PxVec3  normal;
00193 
00197     PxU32   internalFaceIndex0;
00198 
00202     PxVec3  impulse;
00203 
00207     PxU32   internalFaceIndex1;
00208 };
00209 
00210 
00219 struct PxContactPair
00220 {
00221     public:
00222         PX_INLINE   PxContactPair() {}
00223 
00235     PxShape*                shapes[2];
00236 
00243     const PxU8*             contactStream;
00244 
00248     PxU32                   requiredBufferSize;
00249 
00253     PxU16                   contactCount;
00254 
00260     PxContactPairFlags      flags;
00261 
00280     PxPairFlags             events;
00281 
00282     PxU32                   internalData[2];    // For internal use only
00283 
00293     PX_INLINE PxU32          extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const;
00294 };
00295 
00296 
00297 PX_INLINE PxU32 PxContactPair::extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const
00298 {
00299     const PxU8* stream = contactStream;
00300 
00301     const PxContactPoint* contacts = reinterpret_cast<const PxContactPoint*>(stream);
00302     stream += contactCount * sizeof(PxContactPoint);
00303 
00304     const PxReal* impulses = reinterpret_cast<const PxReal*>(stream);
00305 
00306     PxU32 nbContacts = PxMin((PxU32)contactCount, bufferSize);
00307 
00308     PxU32 flippedContacts = (flags & PxContactPairFlag::eINTERNAL_CONTACTS_ARE_FLIPPED);
00309     PxU32 hasImpulses = (flags & PxContactPairFlag::eINTERNAL_HAS_IMPULSES);
00310 
00311     for(PxU32 i=0; i < nbContacts; i++)
00312     {
00313         const PxContactPoint& cp = contacts[i];
00314         PxContactPairPoint& dst = userBuffer[i];
00315         dst.position = cp.point;
00316         dst.separation = cp.separation;
00317         dst.normal = cp.normal;
00318         if (!flippedContacts)
00319         {
00320             dst.internalFaceIndex0 = cp.internalFaceIndex0;
00321             dst.internalFaceIndex1 = cp.internalFaceIndex1;
00322         }
00323         else
00324         {
00325             dst.internalFaceIndex0 = cp.internalFaceIndex1;
00326             dst.internalFaceIndex1 = cp.internalFaceIndex0;
00327         }
00328 
00329         if (hasImpulses)
00330         {
00331             PxReal impulse = impulses[i];
00332             dst.impulse = dst.normal * impulse;
00333         }
00334         else
00335             dst.impulse = PxVec3(0.0f);
00336     }
00337 
00338     return nbContacts;
00339 }
00340 
00341 
00347 struct PxTriggerPairFlag
00348 {
00349     enum Enum
00350     {
00351         eDELETED_SHAPE_TRIGGER          = (1<<0),   
00352         eDELETED_SHAPE_OTHER            = (1<<1),   
00353     };
00354 };
00355 
00361 typedef PxFlags<PxTriggerPairFlag::Enum, PxU8> PxTriggerPairFlags;
00362 PX_FLAGS_OPERATORS(PxTriggerPairFlag::Enum, PxU8);
00363 
00364 
00377 struct PxTriggerPair
00378 {
00379     PX_INLINE PxTriggerPair() {}
00380 
00381     PxShape*                triggerShape;   
00382     PxShape*                otherShape;     
00383     PxPairFlag::Enum        status;         
00384     PxTriggerPairFlags      flags;          
00385 };
00386 
00387 
00395 struct PxConstraintInfo
00396 {
00397     PX_INLINE PxConstraintInfo() {}
00398     PX_INLINE PxConstraintInfo(PxConstraint* c, void* extRef, PxU32 t) : constraint(c), externalReference(extRef), type(t) {}
00399 
00400     PxConstraint*   constraint;             
00401     void*           externalReference;      
00402     PxU32           type;                   
00403 };
00404 
00405 
00418 class PxSimulationEventCallback
00419     {
00420     public:
00431     virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) = 0;
00432 
00444     virtual void onWake(PxActor** actors, PxU32 count) = 0;
00445 
00457     virtual void onSleep(PxActor** actors, PxU32 count) = 0;
00458 
00476     virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 nbPairs) = 0;
00477 
00478     /*
00479     \brief This is called during PxScene::fetchResults with the current trigger pair events.
00480 
00481     Shapes which have been marked as triggers using PxShapeFlag::eTRIGGER_SHAPE will send events
00482     according to the pair flag specification in the filter shader (see #PxPairFlag, #PxSimulationFilterShader).
00483 
00484     \param[in] pairs - The trigger pairs which caused events.
00485     \param[in] count - The number of trigger pairs.
00486 
00487     @see PxScene.setSimulationEventCallback() PxSceneDesc.simulationEventCallback PxPairFlag PxSimulationFilterShader PxShapeFlag PxShape.setFlag()
00488     */
00489     virtual void onTrigger(PxTriggerPair* pairs, PxU32 count) = 0;
00490 
00491     virtual ~PxSimulationEventCallback() {}
00492     };
00493 
00494 #ifndef PX_DOXYGEN
00495 } // namespace physx
00496 #endif
00497 
00499 #endif


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