PxSimulationEventCallback.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-2021 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_SIMULATION_EVENT_CALLBACK
32 #define PX_SIMULATION_EVENT_CALLBACK
33 
37 #include "foundation/PxVec3.h"
38 #include "foundation/PxTransform.h"
39 #include "foundation/PxMemory.h"
40 #include "PxPhysXConfig.h"
41 #include "PxFiltering.h"
42 #include "PxContact.h"
43 
44 #if !PX_DOXYGEN
45 namespace physx
46 {
47 #endif
48 
49 class PxShape;
50 class PxActor;
51 class PxRigidActor;
52 class PxRigidBody;
53 class PxConstraint;
54 
55 
62 {
63  enum Enum
64  {
68  eCONTACT_PAIR_INDEX
69  };
70 };
71 
72 
79 {
80 public:
82 
87 };
88 
89 
102 {
103 public:
105 
109  PxVec3 linearVelocity[2];
110 
114  PxVec3 angularVelocity[2];
115 };
116 
117 
124 {
125 public:
127 
131  PxTransform globalPose[2];
132 };
133 
134 
161 {
162 public:
164 
169 };
170 
171 
178 {
185  : currPtr(stream), endPtr(stream + size), contactPairIndex(0)
186  {
187  clearDataPtrs();
188  }
189 
209  {
210  clearDataPtrs();
211 
212  bool foundEntry = false;
213  bool endOfItemSet = false;
214  while ((currPtr < endPtr) && (!endOfItemSet))
215  {
216  const PxContactPairExtraDataItem* edItem = reinterpret_cast<const PxContactPairExtraDataItem*>(currPtr);
217  PxU8 type = edItem->type;
218 
219  switch(type)
220  {
222  {
223  PX_ASSERT(!preSolverVelocity);
224  preSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
225  currPtr += sizeof(PxContactPairVelocity);
226  foundEntry = true;
227  }
228  break;
229 
231  {
232  postSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
233  currPtr += sizeof(PxContactPairVelocity);
234  foundEntry = true;
235  }
236  break;
237 
239  {
240  eventPose = static_cast<const PxContactPairPose*>(edItem);
241  currPtr += sizeof(PxContactPairPose);
242  foundEntry = true;
243  }
244  break;
245 
247  {
248  if (!foundEntry)
249  {
250  contactPairIndex = static_cast<const PxContactPairIndex*>(edItem)->index;
251  currPtr += sizeof(PxContactPairIndex);
252  foundEntry = true;
253  }
254  else
255  endOfItemSet = true;
256  }
257  break;
258 
259  default:
260  return foundEntry;
261  }
262  }
263 
264  return foundEntry;
265  }
266 
267 private:
272  {
273  preSolverVelocity = NULL;
274  postSolverVelocity = NULL;
275  eventPose = NULL;
276  }
277 
278 public:
282  const PxU8* currPtr;
283 
287  const PxU8* endPtr;
288 
295 
302 
309 
316 };
317 
318 
325 {
326  enum Enum
327  {
328  eREMOVED_ACTOR_0 = (1<<0),
329  eREMOVED_ACTOR_1 = (1<<1)
330  };
331 };
332 
339 PX_FLAGS_OPERATORS(PxContactPairHeaderFlag::Enum, PxU16)
340 
341 
342 
348 {
349  public:
351 
363  PxRigidActor* actors[2];
364 
374 
379 
386 
390  const struct PxContactPair* pairs;
391 
396 };
397 
398 
405 {
406  enum Enum
407  {
411  eREMOVED_SHAPE_0 = (1<<0),
412 
416  eREMOVED_SHAPE_1 = (1<<1),
417 
425  eACTOR_PAIR_HAS_FIRST_TOUCH = (1<<2),
426 
432  eACTOR_PAIR_LOST_TOUCH = (1<<3),
433 
440  eINTERNAL_HAS_IMPULSES = (1<<4),
441 
447  eINTERNAL_CONTACTS_ARE_FLIPPED = (1<<5)
448  };
449 };
450 
457 PX_FLAGS_OPERATORS(PxContactPairFlag::Enum, PxU16)
458 
459 
460 
464 {
469 
474 
479 
484 
489 
494 };
495 
496 
506 {
507  public:
509 
521  PxShape* shapes[2];
522 
530 
538 
546 
551 
556 
562 
568 
575 
599 
600  PxU32 internalData[2]; // For internal use only
601 
611  PX_INLINE PxU32 extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const;
612 
622  PX_INLINE void bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const;
623 
624  PX_INLINE const PxU32* getInternalFaceIndices() const;
625 };
626 
627 
629 {
630  PxU32 nbContacts = 0;
631 
632  if(contactCount && bufferSize)
633  {
634  PxContactStreamIterator iter(contactPatches, contactPoints, getInternalFaceIndices(), patchCount, contactCount);
635 
636  const PxReal* impulses = contactImpulses;
637 
639  const PxU32 hasImpulses = (flags & PxContactPairFlag::eINTERNAL_HAS_IMPULSES);
640 
641  while(iter.hasNextPatch())
642  {
643  iter.nextPatch();
644  while(iter.hasNextContact())
645  {
646  iter.nextContact();
647  PxContactPairPoint& dst = userBuffer[nbContacts];
648  dst.position = iter.getContactPoint();
649  dst.separation = iter.getSeparation();
650  dst.normal = iter.getContactNormal();
651  if(!flippedContacts)
652  {
653  dst.internalFaceIndex0 = iter.getFaceIndex0();
654  dst.internalFaceIndex1 = iter.getFaceIndex1();
655  }
656  else
657  {
658  dst.internalFaceIndex0 = iter.getFaceIndex1();
659  dst.internalFaceIndex1 = iter.getFaceIndex0();
660  }
661 
662  if(hasImpulses)
663  {
664  const PxReal impulse = impulses[nbContacts];
665  dst.impulse = dst.normal * impulse;
666  }
667  else
668  dst.impulse = PxVec3(0.0f);
669  ++nbContacts;
670  if(nbContacts == bufferSize)
671  return nbContacts;
672  }
673  }
674  }
675 
676  return nbContacts;
677 }
678 
679 
680 PX_INLINE void PxContactPair::bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const
681 {
682  PxU8* patches = bufferMemory;
683  PxU8* contacts = NULL;
684  if(patches)
685  {
686  contacts = bufferMemory + patchCount * sizeof(PxContactPatch);
687  PxMemCopy(patches, contactPatches, sizeof(PxContactPatch)*patchCount);
688  PxMemCopy(contacts, contactPoints, contactStreamSize - (sizeof(PxContactPatch)*patchCount));
689  }
690 
691  if(contactImpulses)
692  {
693  PxMemCopy(bufferMemory + ((contactStreamSize + 15) & (~15)), contactImpulses, sizeof(PxReal) * contactCount);
694  }
695 
696  if (newPair)
697  {
698  *newPair = *this;
699  newPair->contactPatches = patches;
700  newPair->contactPoints = contacts;
701  }
702 }
703 
704 
706 {
707  return reinterpret_cast<const PxU32*>(contactImpulses + contactCount);
708 }
709 
716 {
717  enum Enum
718  {
719  eREMOVED_SHAPE_TRIGGER = (1<<0),
720  eREMOVED_SHAPE_OTHER = (1<<1),
721  eNEXT_FREE = (1<<2)
722  };
723 };
724 
731 PX_FLAGS_OPERATORS(PxTriggerPairFlag::Enum, PxU8)
732 
733 
734 
747 {
749 
756 };
757 
758 
767 {
769  PX_INLINE PxConstraintInfo(PxConstraint* c, void* extRef, PxU32 t) : constraint(c), externalReference(extRef), type(t) {}
770 
774 };
775 
776 
794  {
795  public:
808  virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) = 0;
809 
826  virtual void onWake(PxActor** actors, PxU32 count) = 0;
827 
845  virtual void onSleep(PxActor** actors, PxU32 count) = 0;
846 
863  virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 nbPairs) = 0;
864 
878  virtual void onTrigger(PxTriggerPair* pairs, PxU32 count) = 0;
879 
905  virtual void onAdvance(const PxRigidBody*const* bodyBuffer, const PxTransform* poseBuffer, const PxU32 count) = 0;
906 
908  };
909 
910 #if !PX_DOXYGEN
911 } // namespace physx
912 #endif
913 
915 #endif
Definition: GuContactBuffer.h:37
Enum
Definition: PxSimulationEventCallback.h:63
PX_INLINE PxU32 extractContacts(PxContactPairPoint *userBuffer, PxU32 bufferSize) const
Extracts the contact points from the stream and stores them in a convenient format.
Definition: PxSimulationEventCallback.h:628
PxU32 internalFaceIndex1
The surface index of shape 1 at the contact point. This is used to identify the surface material...
Definition: PxSimulationEventCallback.h:493
PxTriggerPairFlags flags
Additional information on the pair (see PxTriggerPairFlag)
Definition: PxSimulationEventCallback.h:755
PxFlags< PxContactPairFlag::Enum, PxU16 > PxContactPairFlags
Bitfield that contains a set of raised flags defined in PxContactPairFlag.
Definition: PxSimulationEventCallback.h:456
see PxContactPairVelocity
Definition: PxSimulationEventCallback.h:65
const PxU8 * currPtr
Current pointer in the stream.
Definition: PxSimulationEventCallback.h:282
PX_INLINE PxConstraintInfo()
Definition: PxSimulationEventCallback.h:768
Extra data item types for contact pairs.
Definition: PxSimulationEventCallback.h:61
PxU32 contactPairIndex
The contact pair index of the current item set in the stream.
Definition: PxSimulationEventCallback.h:315
PxU8 nbContacts
Definition: PxContact.h:462
PX_INLINE PxContactPair()
Definition: PxSimulationEventCallback.h:508
An Instance of this class is passed to PxSimulationEventCallback.onContact().
Definition: PxSimulationEventCallback.h:347
PxActor is the base class for the main simulation objects in the physics SDK.
Definition: PxActor.h:154
Enum
Definition: PxFiltering.h:57
Abstract class for collision shapes.
Definition: PxShape.h:142
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
Enum
Definition: PxSimulationEventCallback.h:326
float PxReal
Definition: PxSimpleTypes.h:78
PxU16 extraDataStreamSize
Size of the extra data stream [bytes].
Definition: PxSimulationEventCallback.h:378
PX_INLINE PxConstraintInfo(PxConstraint *c, void *extRef, PxU32 t)
Definition: PxSimulationEventCallback.h:769
PX_INLINE const PxU32 * getInternalFaceIndices() const
Definition: PxSimulationEventCallback.h:705
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition: PxMemory.h:84
PX_FORCE_INLINE PxContactPairVelocity()
Definition: PxSimulationEventCallback.h:104
Descriptor for a broken constraint.
Definition: PxSimulationEventCallback.h:766
const PxContactPairVelocity * preSolverVelocity
Pointer to the current pre solver velocity item in the stream. NULL if there is none.
Definition: PxSimulationEventCallback.h:294
Internal flag, used by PxContactPair.extractContacts()
Definition: PxSimulationEventCallback.h:447
PxU8 contactCount
Number of contact points stored in the contact stream.
Definition: PxSimulationEventCallback.h:555
PxU16 contactStreamSize
Size of the contact stream [bytes] not including force buffer.
Definition: PxSimulationEventCallback.h:567
PxRigidActor * otherActor
The actor to which otherShape is attached.
Definition: PxSimulationEventCallback.h:753
PxVec3 normal
The normal of the contacting surfaces at the contact point. The normal direction points from the seco...
Definition: PxSimulationEventCallback.h:478
const struct PxContactPair * pairs
pointer to the contact pairs
Definition: PxSimulationEventCallback.h:390
see PxContactPairPose
Definition: PxSimulationEventCallback.h:67
PxU8 type
The type of the extra data stream item.
Definition: PxSimulationEventCallback.h:86
PxConstraint * constraint
The broken constraint.
Definition: PxSimulationEventCallback.h:771
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextPatch() const
Returns whether there are more patches in this stream.
Definition: PxContact.h:303
void * externalReference
The external object which owns the constraint (see PxConstraintConnector::getExternalReference()) ...
Definition: PxSimulationEventCallback.h:772
PxShape * otherShape
The shape causing the trigger event.
Definition: PxSimulationEventCallback.h:752
const PxContactPairPose * eventPose
Pointer to the current contact event pose item in the stream. NULL if there is none.
Definition: PxSimulationEventCallback.h:308
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition: PxRigidActor.h:58
A contact point as used by contact notification.
Definition: PxSimulationEventCallback.h:463
An interface class that the user can implement in order to receive simulation events.
Definition: PxSimulationEventCallback.h:793
const PxU8 * contactPatches
Pointer to first patch header in contact stream containing contact patch data.
Definition: PxSimulationEventCallback.h:529
PxPairFlag::Enum status
Type of trigger event (eNOTIFY_TOUCH_FOUND or eNOTIFY_TOUCH_LOST). eNOTIFY_TOUCH_PERSISTS events are ...
Definition: PxSimulationEventCallback.h:754
Collection of flags providing information on contact report pairs.
Definition: PxSimulationEventCallback.h:404
Header for contact patch where all points share same material and normal.
Definition: PxContact.h:64
A class to iterate over a contact pair extra data stream.
Definition: PxSimulationEventCallback.h:177
Enum
Definition: PxSimulationEventCallback.h:406
Velocities of the contact pair rigid bodies.
Definition: PxSimulationEventCallback.h:101
Internal flag, used by PxContactPair.extractContacts()
Definition: PxSimulationEventCallback.h:440
PxPairFlags events
Flags raised due to the contact.
Definition: PxSimulationEventCallback.h:598
virtual ~PxSimulationEventCallback()
Definition: PxSimulationEventCallback.h:907
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex0() const
Gets the contact&#39;s face index for shape 0.
Definition: PxContact.h:451
PxContactPairFlags flags
Additional information on the contact report pair.
Definition: PxSimulationEventCallback.h:574
PxVec3 impulse
The impulse applied at the contact point, in world space. Divide by the simulation time step to get a...
Definition: PxSimulationEventCallback.h:488
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextContact() const
Returns if the current patch has more contacts.
Definition: PxContact.h:345
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex1() const
Gets the contact&#39;s face index for shape 1.
Definition: PxContact.h:460
PxU16 flags
a set of Px1DConstraintFlags
Definition: PxConstraintDesc.h:110
PxU8 patchCount
Number of contact patches stored in the contact stream.
Definition: PxSimulationEventCallback.h:561
PX_INLINE bool nextItemSet()
Advances the iterator to next set of extra data items.
Definition: PxSimulationEventCallback.h:208
Collection of flags providing information on contact report pairs.
Definition: PxSimulationEventCallback.h:324
Contact report pair information.
Definition: PxSimulationEventCallback.h:505
PxU32 type
Unique type ID of the external object. Allows to cast the provided external reference to the appropri...
Definition: PxSimulationEventCallback.h:773
uint8_t PxU8
Definition: PxSimpleTypes.h:75
class representing a rigid euclidean transform as a quaternion and a vector
Definition: PxTransform.h:48
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 & getContactNormal() const
Gets the current contact&#39;s normal.
Definition: PxContact.h:370
A plugin class for implementing constraints.
Definition: PxConstraint.h:108
PX_INLINE PxContactPairHeader()
Definition: PxSimulationEventCallback.h:350
Enum
Definition: PxSimulationEventCallback.h:717
Marker for the beginning of a new item set in the extra data stream.
Definition: PxSimulationEventCallback.h:160
PxU32 internalFaceIndex0
The surface index of shape 0 at the contact point. This is used to identify the surface material...
Definition: PxSimulationEventCallback.h:483
PxVec3 position
The position of the contact point between the shapes, in world space.
Definition: PxSimulationEventCallback.h:468
PX_FORCE_INLINE PxContactPairExtraDataItem()
Definition: PxSimulationEventCallback.h:81
Descriptor for a trigger pair.
Definition: PxSimulationEventCallback.h:746
PX_CUDA_CALLABLE PX_FORCE_INLINE void nextContact()
Advances to the next contact in the patch.
Definition: PxContact.h:353
const PxReal * contactImpulses
Buffer containing applied impulse data.
Definition: PxSimulationEventCallback.h:545
Base class for items in the extra data stream of contact pairs.
Definition: PxSimulationEventCallback.h:78
const PxU8 * contactPoints
Pointer to first contact point in contact stream containing contact data.
Definition: PxSimulationEventCallback.h:537
World space actor poses of the contact pair rigid bodies.
Definition: PxSimulationEventCallback.h:123
PxShape * triggerShape
The shape that has been marked as a trigger.
Definition: PxSimulationEventCallback.h:750
see PxContactPairVelocity
Definition: PxSimulationEventCallback.h:66
PxU16 index
The next item set in the extra data stream refers to the contact pairs starting at index in the repor...
Definition: PxSimulationEventCallback.h:168
PX_FORCE_INLINE PxContactPairPose()
Definition: PxSimulationEventCallback.h:126
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getSeparation() const
Gets the contact&#39;s separation.
Definition: PxContact.h:442
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 & getContactPoint() const
Gets the contact&#39;s contact point.
Definition: PxContact.h:433
PxFlags< PxContactPairHeaderFlag::Enum, PxU16 > PxContactPairHeaderFlags
Bitfield that contains a set of raised flags defined in PxContactPairHeaderFlag.
Definition: PxSimulationEventCallback.h:338
PX_INLINE void bufferContacts(PxContactPair *newPair, PxU8 *bufferMemory) const
Helper method to clone the contact pair and copy the contact data stream into a user buffer...
Definition: PxSimulationEventCallback.h:680
PxU32 nbPairs
number of contact pairs
Definition: PxSimulationEventCallback.h:395
PX_FORCE_INLINE PxContactPairIndex()
Definition: PxSimulationEventCallback.h:163
const PxU8 * endPtr
Pointer to the end of the stream.
Definition: PxSimulationEventCallback.h:287
#define PX_ASSERT(exp)
Definition: PxAssert.h:59
PxFlags< PxTriggerPairFlag::Enum, PxU8 > PxTriggerPairFlags
Bitfield that contains a set of raised flags defined in PxTriggerPairFlag.
Definition: PxSimulationEventCallback.h:730
PxReal separation
The separation of the shapes at the contact point. A negative separation denotes a penetration...
Definition: PxSimulationEventCallback.h:473
PxRigidBody is a base class shared between dynamic rigid body objects.
Definition: PxRigidBody.h:195
PX_INLINE PxTriggerPair()
Definition: PxSimulationEventCallback.h:748
uint16_t PxU16
Definition: PxSimpleTypes.h:73
see PxContactPairIndex
Definition: PxSimulationEventCallback.h:68
uint32_t PxU32
Definition: Px.h:48
const PxContactPairVelocity * postSolverVelocity
Pointer to the current post solver velocity item in the stream. NULL if there is none.
Definition: PxSimulationEventCallback.h:301
#define PX_INLINE
Definition: PxPreprocessor.h:336
const PxU8 * extraDataStream
Stream containing extra data as requested in the PxPairFlag flags of the simulation filter...
Definition: PxSimulationEventCallback.h:373
A class to iterate over a compressed contact stream. This supports read-only access to the various co...
Definition: PxContact.h:178
PX_FORCE_INLINE PxContactPairExtraDataIterator(const PxU8 *stream, PxU32 size)
Constructor.
Definition: PxSimulationEventCallback.h:184
3 Element vector class.
Definition: PxVec3.h:49
PX_FORCE_INLINE void clearDataPtrs()
Internal helper.
Definition: PxSimulationEventCallback.h:271
PxContactPairHeaderFlags flags
Additional information on the contact report pair.
Definition: PxSimulationEventCallback.h:385
PxRigidActor * triggerActor
The actor to which triggerShape is attached.
Definition: PxSimulationEventCallback.h:751
Collection of flags providing information on trigger report pairs.
Definition: PxSimulationEventCallback.h:715
PX_CUDA_CALLABLE PX_INLINE void nextPatch()
Advances iterator to next contact patch.
Definition: PxContact.h:325
PxU32 requiredBufferSize
Size of the contact stream [bytes] including force buffer.
Definition: PxSimulationEventCallback.h:550