RavEngine
Loading...
Searching...
No Matches
PxSimulationEventCallback.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_SIMULATION_EVENT_CALLBACK_H
30#define PX_SIMULATION_EVENT_CALLBACK_H
35#include "foundation/PxVec3.h"
36#include "foundation/PxTransform.h"
37#include "foundation/PxMemory.h"
38#include "PxPhysXConfig.h"
39#include "PxFiltering.h"
40#include "PxContact.h"
41
42#if !PX_DOXYGEN
43namespace physx
44{
45#endif
46
47class PxShape;
48class PxActor;
49class PxRigidActor;
50class PxRigidBody;
51class PxConstraint;
52
53
69
70
86
87
114
115
131
132
159{
160public:
162
166 PxU16 index;
167};
168
169
176{
182 PX_FORCE_INLINE PxContactPairExtraDataIterator(const PxU8* stream, PxU32 size)
183 : currPtr(stream), endPtr(stream + size), contactPairIndex(0)
184 {
185 clearDataPtrs();
186 }
187
207 {
208 clearDataPtrs();
209
210 bool foundEntry = false;
211 bool endOfItemSet = false;
212 while ((currPtr < endPtr) && (!endOfItemSet))
213 {
214 const PxContactPairExtraDataItem* edItem = reinterpret_cast<const PxContactPairExtraDataItem*>(currPtr);
215 PxU8 type = edItem->type;
216
217 switch(type)
218 {
220 {
221 PX_ASSERT(!preSolverVelocity);
222 preSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
224 foundEntry = true;
225 }
226 break;
227
229 {
230 postSolverVelocity = static_cast<const PxContactPairVelocity*>(edItem);
232 foundEntry = true;
233 }
234 break;
235
237 {
238 eventPose = static_cast<const PxContactPairPose*>(edItem);
239 currPtr += sizeof(PxContactPairPose);
240 foundEntry = true;
241 }
242 break;
243
245 {
246 if (!foundEntry)
247 {
248 contactPairIndex = static_cast<const PxContactPairIndex*>(edItem)->index;
249 currPtr += sizeof(PxContactPairIndex);
250 foundEntry = true;
251 }
252 else
253 endOfItemSet = true;
254 }
255 break;
256
257 default:
258 return foundEntry;
259 }
260 }
261
262 return foundEntry;
263 }
264
265private:
269 PX_FORCE_INLINE void clearDataPtrs()
270 {
271 preSolverVelocity = NULL;
272 postSolverVelocity = NULL;
273 eventPose = NULL;
274 }
275
276public:
280 const PxU8* currPtr;
281
285 const PxU8* endPtr;
286
293
300
307
314};
315
316
323{
324 enum Enum
325 {
327 eREMOVED_ACTOR_1 = (1<<1)
328 };
329};
330
337PX_FLAGS_OPERATORS(PxContactPairHeaderFlag::Enum, PxU16)
338
339
340
346{
347 public:
349
361 PxActor* actors[2];
362
371 const PxU8* extraDataStream;
372
377
384
388 const struct PxContactPair* pairs;
389
393 PxU32 nbPairs;
394};
395
396
448
455PX_FLAGS_OPERATORS(PxContactPairFlag::Enum, PxU16)
456
457
458
493
494
504{
505 public:
507
520
527 const PxU8* contactPatches;
528
535 const PxU8* contactPoints;
536
543 const PxReal* contactImpulses;
544
549
554
560
566
573
597
598 PxU32 internalData[2]; // For internal use only
599
609 PX_INLINE PxU32 extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const;
610
620 PX_INLINE void bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const;
621
622 PX_INLINE const PxU32* getInternalFaceIndices() const;
623};
624
625
626PX_INLINE PxU32 PxContactPair::extractContacts(PxContactPairPoint* userBuffer, PxU32 bufferSize) const
627{
628 PxU32 nbContacts = 0;
629
630 if(contactCount && bufferSize)
631 {
633
634 const PxReal* impulses = contactImpulses;
635
636 const PxU32 flippedContacts = (flags & PxContactPairFlag::eINTERNAL_CONTACTS_ARE_FLIPPED);
637 const PxU32 hasImpulses = (flags & PxContactPairFlag::eINTERNAL_HAS_IMPULSES);
638
639 while(iter.hasNextPatch())
640 {
641 iter.nextPatch();
642 while(iter.hasNextContact())
643 {
644 iter.nextContact();
645 PxContactPairPoint& dst = userBuffer[nbContacts];
646 dst.position = iter.getContactPoint();
647 dst.separation = iter.getSeparation();
648 dst.normal = iter.getContactNormal();
649 if(!flippedContacts)
650 {
653 }
654 else
655 {
658 }
659
660 if(hasImpulses)
661 {
662 const PxReal impulse = impulses[nbContacts];
663 dst.impulse = dst.normal * impulse;
664 }
665 else
666 dst.impulse = PxVec3(0.0f);
667 ++nbContacts;
668 if(nbContacts == bufferSize)
669 return nbContacts;
670 }
671 }
672 }
673
674 return nbContacts;
675}
676
677
678PX_INLINE void PxContactPair::bufferContacts(PxContactPair* newPair, PxU8* bufferMemory) const
679{
680 PxU8* patches = bufferMemory;
681 PxU8* contacts = NULL;
682 if(patches)
683 {
684 contacts = bufferMemory + patchCount * sizeof(PxContactPatch);
687 }
688
690 {
691 PxMemCopy(bufferMemory + ((contactStreamSize + 15) & (~15)), contactImpulses, sizeof(PxReal) * contactCount);
692 }
693
694 if (newPair)
695 {
696 *newPair = *this;
697 newPair->contactPatches = patches;
698 newPair->contactPoints = contacts;
699 }
700}
701
702
703PX_INLINE const PxU32* PxContactPair::getInternalFaceIndices() const
704{
705 return reinterpret_cast<const PxU32*>(contactImpulses + contactCount);
706}
707
714{
715 enum Enum
716 {
719 eNEXT_FREE = (1<<2)
720 };
721};
722
729PX_FLAGS_OPERATORS(PxTriggerPairFlag::Enum, PxU8)
730
731
732
755
756
765{
767 PX_INLINE PxConstraintInfo(PxConstraint* c, void* extRef, PxU32 t) : constraint(c), externalReference(extRef), type(t) {}
768
771 PxU32 type;
772};
773
774
792 {
793 public:
806 virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) = 0;
807
824 virtual void onWake(PxActor** actors, PxU32 count) = 0;
825
843 virtual void onSleep(PxActor** actors, PxU32 count) = 0;
844
861 virtual void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 nbPairs) = 0;
862
876 virtual void onTrigger(PxTriggerPair* pairs, PxU32 count) = 0;
877
899 virtual void onAdvance(const PxRigidBody*const* bodyBuffer, const PxTransform* poseBuffer, const PxU32 count) = 0;
900
901 virtual ~PxSimulationEventCallback() {}
902 };
903
904#if !PX_DOXYGEN
905} // namespace physx
906#endif
907
909#endif
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
A plugin class for implementing constraints.
Definition PxConstraint.h:100
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
PxRigidBody is a base class shared between dynamic rigid body objects.
Definition PxRigidBody.h:199
Abstract class for collision shapes.
Definition PxShape.h:146
An interface class that the user can implement in order to receive simulation events.
Definition PxSimulationEventCallback.h:792
virtual void onAdvance(const PxRigidBody *const *bodyBuffer, const PxTransform *poseBuffer, const PxU32 count)=0
Provides early access to the new pose of moving rigid bodies.
virtual void onSleep(PxActor **actors, PxU32 count)=0
This is called with the actors which have just been put to sleep.
virtual void onTrigger(PxTriggerPair *pairs, PxU32 count)=0
This is called with the current trigger pair events.
virtual void onContact(const PxContactPairHeader &pairHeader, const PxContactPair *pairs, PxU32 nbPairs)=0
This is called when certain contact events occur.
virtual void onWake(PxActor **actors, PxU32 count)=0
This is called with the actors which have just been woken up.
virtual void onConstraintBreak(PxConstraintInfo *constraints, PxU32 count)=0
This is called when a breakable constraint breaks.
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
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:83
PxFlags< PxTriggerPairFlag::Enum, PxU8 > PxTriggerPairFlags
Bitfield that contains a set of raised flags defined in PxTriggerPairFlag.
Definition PxSimulationEventCallback.h:728
PxFlags< PxContactPairFlag::Enum, PxU16 > PxContactPairFlags
Bitfield that contains a set of raised flags defined in PxContactPairFlag.
Definition PxSimulationEventCallback.h:454
PxFlags< PxContactPairHeaderFlag::Enum, PxU16 > PxContactPairHeaderFlags
Bitfield that contains a set of raised flags defined in PxContactPairHeaderFlag.
Definition PxSimulationEventCallback.h:336
Descriptor for a broken constraint.
Definition PxSimulationEventCallback.h:765
PxConstraint * constraint
The broken constraint.
Definition PxSimulationEventCallback.h:769
void * externalReference
The external object which owns the constraint (see PxConstraintConnector::getExternalReference())
Definition PxSimulationEventCallback.h:770
PxU32 type
Unique type ID of the external object. Allows to cast the provided external reference to the appropri...
Definition PxSimulationEventCallback.h:771
Base class for items in the extra data stream of contact pairs.
Definition PxSimulationEventCallback.h:77
PxU8 type
The type of the extra data stream item.
Definition PxSimulationEventCallback.h:84
A class to iterate over a contact pair extra data stream.
Definition PxSimulationEventCallback.h:176
PxU32 contactPairIndex
The contact pair index of the current item set in the stream.
Definition PxSimulationEventCallback.h:313
PX_FORCE_INLINE PxContactPairExtraDataIterator(const PxU8 *stream, PxU32 size)
Constructor.
Definition PxSimulationEventCallback.h:182
const PxContactPairVelocity * postSolverVelocity
Pointer to the current post solver velocity item in the stream. NULL if there is none.
Definition PxSimulationEventCallback.h:299
PX_INLINE bool nextItemSet()
Advances the iterator to next set of extra data items.
Definition PxSimulationEventCallback.h:206
const PxU8 * currPtr
Current pointer in the stream.
Definition PxSimulationEventCallback.h:280
const PxContactPairVelocity * preSolverVelocity
Pointer to the current pre solver velocity item in the stream. NULL if there is none.
Definition PxSimulationEventCallback.h:292
const PxContactPairPose * eventPose
Pointer to the current contact event pose item in the stream. NULL if there is none.
Definition PxSimulationEventCallback.h:306
const PxU8 * endPtr
Pointer to the end of the stream.
Definition PxSimulationEventCallback.h:285
Extra data item types for contact pairs.
Definition PxSimulationEventCallback.h:60
Enum
Definition PxSimulationEventCallback.h:62
@ eCONTACT_EVENT_POSE
see #PxContactPairPose
Definition PxSimulationEventCallback.h:65
@ ePRE_SOLVER_VELOCITY
see #PxContactPairVelocity
Definition PxSimulationEventCallback.h:63
@ eCONTACT_PAIR_INDEX
see #PxContactPairIndex
Definition PxSimulationEventCallback.h:66
@ ePOST_SOLVER_VELOCITY
see #PxContactPairVelocity
Definition PxSimulationEventCallback.h:64
Collection of flags providing information on contact report pairs.
Definition PxSimulationEventCallback.h:403
Enum
Definition PxSimulationEventCallback.h:405
@ eACTOR_PAIR_HAS_FIRST_TOUCH
First actor pair contact.
Definition PxSimulationEventCallback.h:423
@ eREMOVED_SHAPE_0
The shape with index 0 has been removed from the actor/scene.
Definition PxSimulationEventCallback.h:409
@ eACTOR_PAIR_LOST_TOUCH
All contact between the actor pair was lost.
Definition PxSimulationEventCallback.h:430
@ eINTERNAL_HAS_IMPULSES
Internal flag, used by PxContactPair.extractContacts()
Definition PxSimulationEventCallback.h:438
@ eINTERNAL_CONTACTS_ARE_FLIPPED
Internal flag, used by PxContactPair.extractContacts()
Definition PxSimulationEventCallback.h:445
@ eREMOVED_SHAPE_1
The shape with index 1 has been removed from the actor/scene.
Definition PxSimulationEventCallback.h:414
Collection of flags providing information on contact report pairs.
Definition PxSimulationEventCallback.h:323
Enum
Definition PxSimulationEventCallback.h:325
@ eREMOVED_ACTOR_0
The actor with index 0 has been removed from the scene.
Definition PxSimulationEventCallback.h:326
@ eREMOVED_ACTOR_1
The actor with index 1 has been removed from the scene.
Definition PxSimulationEventCallback.h:327
An Instance of this class is passed to PxSimulationEventCallback.onContact().
Definition PxSimulationEventCallback.h:346
const PxU8 * extraDataStream
Stream containing extra data as requested in the PxPairFlag flags of the simulation filter.
Definition PxSimulationEventCallback.h:371
PxU16 extraDataStreamSize
Size of the extra data stream [bytes].
Definition PxSimulationEventCallback.h:376
PxContactPairHeaderFlags flags
Additional information on the contact report pair.
Definition PxSimulationEventCallback.h:383
PxU32 nbPairs
number of contact pairs
Definition PxSimulationEventCallback.h:393
const struct PxContactPair * pairs
pointer to the contact pairs
Definition PxSimulationEventCallback.h:388
Marker for the beginning of a new item set in the extra data stream.
Definition PxSimulationEventCallback.h:159
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:166
A contact point as used by contact notification.
Definition PxSimulationEventCallback.h:462
PxU32 internalFaceIndex0
The surface index of shape 0 at the contact point. This is used to identify the surface material.
Definition PxSimulationEventCallback.h:481
PxU32 internalFaceIndex1
The surface index of shape 1 at the contact point. This is used to identify the surface material.
Definition PxSimulationEventCallback.h:491
PxVec3 position
The position of the contact point between the shapes, in world space.
Definition PxSimulationEventCallback.h:466
PxReal separation
The separation of the shapes at the contact point. A negative separation denotes a penetration.
Definition PxSimulationEventCallback.h:471
PxVec3 impulse
The impulse applied at the contact point, in world space. Divide by the simulation time step to get a...
Definition PxSimulationEventCallback.h:486
PxVec3 normal
The normal of the contacting surfaces at the contact point. The normal direction points from the seco...
Definition PxSimulationEventCallback.h:476
World space actor poses of the contact pair rigid bodies.
Definition PxSimulationEventCallback.h:122
PxTransform globalPose[2]
The world space pose of the rigid bodies.
Definition PxSimulationEventCallback.h:129
Velocities of the contact pair rigid bodies.
Definition PxSimulationEventCallback.h:100
PxVec3 angularVelocity[2]
The angular velocity of the rigid bodies.
Definition PxSimulationEventCallback.h:112
PxVec3 linearVelocity[2]
The linear velocity of the rigid bodies.
Definition PxSimulationEventCallback.h:107
Contact report pair information.
Definition PxSimulationEventCallback.h:504
PxU8 contactCount
Number of contact points stored in the contact stream.
Definition PxSimulationEventCallback.h:553
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:626
PxU16 contactStreamSize
Size of the contact stream [bytes] not including force buffer.
Definition PxSimulationEventCallback.h:565
PxShape * shapes[2]
The two shapes that make up the pair.
Definition PxSimulationEventCallback.h:519
PxContactPairFlags flags
Additional information on the contact report pair.
Definition PxSimulationEventCallback.h:572
PxPairFlags events
Flags raised due to the contact.
Definition PxSimulationEventCallback.h:596
const PxU8 * contactPoints
Pointer to first contact point in contact stream containing contact data.
Definition PxSimulationEventCallback.h:535
PxU32 requiredBufferSize
Size of the contact stream [bytes] including force buffer.
Definition PxSimulationEventCallback.h:548
const PxReal * contactImpulses
Buffer containing applied impulse data.
Definition PxSimulationEventCallback.h:543
const PxU8 * contactPatches
Pointer to first patch header in contact stream containing contact patch data.
Definition PxSimulationEventCallback.h:527
PxU8 patchCount
Number of contact patches stored in the contact stream.
Definition PxSimulationEventCallback.h:559
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:678
Header for a contact patch where all points share same material and normal.
Definition PxContact.h:73
A class to iterate over a compressed contact stream. This supports read-only access to the various co...
Definition PxContact.h:229
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextContact() const
Returns if the current patch has more contacts.
Definition PxContact.h:409
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 & getContactPoint() const
Gets the contact's contact point.
Definition PxContact.h:496
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 & getContactNormal() const
Gets the current contact's normal.
Definition PxContact.h:433
PX_CUDA_CALLABLE PX_FORCE_INLINE void nextContact()
Advances to the next contact in the patch.
Definition PxContact.h:417
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getSeparation() const
Gets the contact's separation.
Definition PxContact.h:505
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex0() const
Gets the contact's face index for shape 0.
Definition PxContact.h:514
PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextPatch() const
Returns whether there are more patches in this stream.
Definition PxContact.h:363
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex1() const
Gets the contact's face index for shape 1.
Definition PxContact.h:523
PX_CUDA_CALLABLE PX_INLINE void nextPatch()
Advances iterator to next contact patch.
Definition PxContact.h:389
Enum
Definition PxFiltering.h:56
Collection of flags providing information on trigger report pairs.
Definition PxSimulationEventCallback.h:714
Enum
Definition PxSimulationEventCallback.h:716
@ eNEXT_FREE
For internal use only.
Definition PxSimulationEventCallback.h:719
@ eREMOVED_SHAPE_TRIGGER
The trigger shape has been removed from the actor/scene.
Definition PxSimulationEventCallback.h:717
@ eREMOVED_SHAPE_OTHER
The shape causing the trigger event has been removed from the actor/scene.
Definition PxSimulationEventCallback.h:718
Descriptor for a trigger pair.
Definition PxSimulationEventCallback.h:745
PxShape * triggerShape
The shape that has been marked as a trigger.
Definition PxSimulationEventCallback.h:748
PxPairFlag::Enum status
Type of trigger event (eNOTIFY_TOUCH_FOUND or eNOTIFY_TOUCH_LOST). eNOTIFY_TOUCH_PERSISTS events are ...
Definition PxSimulationEventCallback.h:752
PxActor * triggerActor
The actor to which triggerShape is attached.
Definition PxSimulationEventCallback.h:749
PxTriggerPairFlags flags
Additional information on the pair (see #PxTriggerPairFlag)
Definition PxSimulationEventCallback.h:753
PxShape * otherShape
The shape causing the trigger event.
Definition PxSimulationEventCallback.h:750
PxActor * otherActor
The actor to which otherShape is attached.
Definition PxSimulationEventCallback.h:751