PxSimulationEventCallback.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_SIMULATION_EVENT_CALLBACK
15 #define PX_SIMULATION_EVENT_CALLBACK
16 
20 #include "foundation/PxVec3.h"
21 #include "foundation/PxTransform.h"
22 #include "foundation/PxMemory.h"
23 #include "PxPhysXConfig.h"
24 #include "PxFiltering.h"
25 #include "PxContact.h"
26 
27 #ifndef PX_DOXYGEN
28 namespace physx
29 {
30 #endif
31 
32 class PxShape;
33 class PxActor;
34 class PxRigidActor;
35 class PxConstraint;
36 
37 
44 {
45  enum Enum
46  {
50  eCONTACT_PAIR_INDEX
51  };
52 };
53 
54 
61 {
62 public:
64 
69 };
70 
71 
84 {
85 public:
87 
91  PxVec3 linearVelocity[2];
92 
96  PxVec3 angularVelocity[2];
97 };
98 
99 
106 {
107 public:
109 
113  PxTransform globalPose[2];
114 };
115 
116 
143 {
144 public:
146 
151 };
152 
153 
160 {
167  : currPtr(stream), endPtr(stream + size), contactPairIndex(0)
168  {
169  clearDataPtrs();
170  }
171 
190  PX_INLINE bool nextItemSet()
191  {
192  clearDataPtrs();
193 
194  bool foundEntry = false;
195  bool endOfItemSet = false;
196  while ((currPtr < endPtr) && (!endOfItemSet))
197  {
198  const PxContactPairExtraDataItem* edItem = reinterpret_cast<const PxContactPairExtraDataItem*>(currPtr);
199  PxU8 type = edItem->type;
200 
201  switch(type)
202  {
204  {
205  PX_ASSERT(!preSolverVelocity);
206  preSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
207  currPtr += sizeof(PxContactPairVelocity);
208  foundEntry = true;
209  }
210  break;
211 
213  {
214  postSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
215  currPtr += sizeof(PxContactPairVelocity);
216  foundEntry = true;
217  }
218  break;
219 
221  {
222  eventPose = static_cast<const PxContactPairPose*>(edItem);
223  currPtr += sizeof(PxContactPairPose);
224  foundEntry = true;
225  }
226  break;
227 
229  {
230  if (!foundEntry)
231  {
232  contactPairIndex = static_cast<const PxContactPairIndex*>(edItem)->index;
233  currPtr += sizeof(PxContactPairIndex);
234  foundEntry = true;
235  }
236  else
237  endOfItemSet = true;
238  }
239  break;
240 
241  default:
242  return foundEntry;
243  }
244  }
245 
246  return foundEntry;
247  }
248 
249 private:
253  PX_FORCE_INLINE void clearDataPtrs()
254  {
255  preSolverVelocity = NULL;
256  postSolverVelocity = NULL;
257  eventPose = NULL;
258  }
259 
260 public:
264  const PxU8* currPtr;
265 
269  const PxU8* endPtr;
270 
277 
284 
291 
298 };
299 
300 
307 {
308  enum Enum
309  {
310  eREMOVED_ACTOR_0 = (1<<0),
311  eREMOVED_ACTOR_1 = (1<<1),
312  PX_DEPRECATED eDELETED_ACTOR_0 = eREMOVED_ACTOR_0,
313  PX_DEPRECATED eDELETED_ACTOR_1 = eREMOVED_ACTOR_1
314 
315  };
316 };
317 
325 
326 
327 
333 {
334  public:
336 
348  PxRigidActor* actors[2];
349 
359 
364 
371 };
372 
373 
380 {
381  enum Enum
382  {
386  eREMOVED_SHAPE_0 = (1<<0),
387 
391  eREMOVED_SHAPE_1 = (1<<1),
392 
396  PX_DEPRECATED eDELETED_SHAPE_0 = eREMOVED_SHAPE_0,
397 
401  PX_DEPRECATED eDELETED_SHAPE_1 = eREMOVED_SHAPE_1,
402 
410  eACTOR_PAIR_HAS_FIRST_TOUCH = (1<<2),
411 
417  eACTOR_PAIR_LOST_TOUCH = (1<<3),
418 
424  eINTERNAL_HAS_FACE_INDICES = (1<<4),
425 
432  eINTERNAL_HAS_IMPULSES = (1<<5),
433 
439  eINTERNAL_CONTACTS_ARE_FLIPPED = (1<<6)
440  };
441 };
442 
450 
451 
452 
456 {
461 
466 
471 
476 
481 
486 };
487 
488 
498 {
499  public:
501 
513  PxShape* shapes[2];
514 
522 
527 
532 
538 
545 
569 
570  PxU32 internalData[2]; // For internal use only
571 
581  PX_INLINE PxU32 extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const;
582 
592  PX_INLINE void bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const;
593 };
594 
595 
597 {
598  const PxU8* stream = contactStream;
599 
600  PxU32 nbContacts = 0;
601 
602  if(contactCount && bufferSize)
603  {
604  PxContactStreamIterator iter((PxU8*)stream, contactStreamSize);
605 
606  stream += ((contactStreamSize + 15) & ~15);
607 
608  const PxReal* impulses = reinterpret_cast<const PxReal*>(stream);
609 
612 
613 
614  while(iter.hasNextPatch())
615  {
616  iter.nextPatch();
617  while(iter.hasNextContact())
618  {
619  iter.nextContact();
620  PxContactPairPoint& dst = userBuffer[nbContacts];
621  dst.position = iter.getContactPoint();
622  dst.separation = iter.getSeparation();
623  dst.normal = iter.getContactNormal();
624  if (!flippedContacts)
625  {
626  dst.internalFaceIndex0 = iter.getFaceIndex0();
627  dst.internalFaceIndex1 = iter.getFaceIndex1();
628  }
629  else
630  {
631  dst.internalFaceIndex0 = iter.getFaceIndex1();
632  dst.internalFaceIndex1 = iter.getFaceIndex0();
633  }
634 
635  if (hasImpulses)
636  {
637  PxReal impulse = impulses[nbContacts];
638  dst.impulse = dst.normal * impulse;
639  }
640  else
641  dst.impulse = PxVec3(0.0f);
642  ++nbContacts;
643  if(nbContacts == bufferSize)
644  return nbContacts;
645  }
646  }
647  }
648 
649  return nbContacts;
650 }
651 
652 
653 PX_INLINE void PxContactPair::bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const
654 {
655  if (newPair)
656  {
657  *newPair = *this;
658  newPair->contactStream = bufferMemory;
659  }
660 
661  if (contactStream)
662  PxMemCopy(bufferMemory, contactStream, requiredBufferSize);
663 }
664 
665 
672 {
673  enum Enum
674  {
675  eREMOVED_SHAPE_TRIGGER = (1<<0),
676  eREMOVED_SHAPE_OTHER = (1<<1),
677  PX_DEPRECATED eDELETED_SHAPE_TRIGGER = eREMOVED_SHAPE_TRIGGER,
678  PX_DEPRECATED eDELETED_SHAPE_OTHER = eREMOVED_SHAPE_OTHER,
679  eNEXT_FREE = (1<<2)
680  };
681 };
682 
690 
691 
692 
705 {
707 
714 };
715 
716 
725 {
727  PX_INLINE PxConstraintInfo(PxConstraint* c, void* extRef, PxU32 t) : constraint(c), externalReference(extRef), type(t) {}
728 
732 };
733 
734 
750  {
751  public:
764  virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) = 0;
765 
782  virtual void onWake(PxActor** actors, PxU32 count) = 0;
783 
801  virtual void onSleep(PxActor** actors, PxU32 count) = 0;
802 
819  virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 nbPairs) = 0;
820 
832  virtual void onTrigger(PxTriggerPair* pairs, PxU32 count) = 0;
833 
835  };
836 
837 #ifndef PX_DOXYGEN
838 } // namespace physx
839 #endif
840 
842 #endif


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