RavEngine
Loading...
Searching...
No Matches
PxContact.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_CONTACT_H
30#define PX_CONTACT_H
31
36#include "foundation/PxVec3.h"
37#include "foundation/PxAssert.h"
38#include "PxNodeIndex.h"
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
45#if PX_VC
46#pragma warning(push)
47#pragma warning(disable: 4324) // Padding was added at the end of a structure because of a __declspec(align) value.
48#endif
49
50#define PXC_CONTACT_NO_FACE_INDEX 0xffffffff
51
52class PxActor;
53
58PX_ALIGN_PREFIX(16)
60{
61 PxReal mInvMassScale0;
62 PxReal mInvInertiaScale0;
63 PxReal mInvMassScale1;
64 PxReal mInvInertiaScale1;
65}
66PX_ALIGN_SUFFIX(16);
67
71PX_ALIGN_PREFIX(16)
73{
75 {
76 eHAS_FACE_INDICES = 1,
77 eMODIFIABLE = 2,
78 eFORCE_NO_RESPONSE = 4,
79 eHAS_MODIFIED_MASS_RATIOS = 8,
80 eHAS_TARGET_VELOCITY = 16,
81 eHAS_MAX_IMPULSE = 32,
82 eREGENERATE_PATCHES = 64,
83 eCOMPRESSED_MODIFIED_CONTACT = 128
84 };
85
89 PX_ALIGN(16, PxMassModificationProps mMassModification); //16
90
94 PX_ALIGN(16, PxVec3 normal); //28
95
99 PxReal restitution; //32
100
104 PxReal dynamicFriction; //36
105
109 PxReal staticFriction; //40
110
114 PxReal damping; //44
115
120
124 PxU8 nbContacts; //47 //Can be a U8
125
130 PxU8 materialFlags; //48 //Can be a U16
131
135 PxU16 internalFlags; //50 //Can be a U16
136
140 PxU16 materialIndex0; //52 //Can be a U16
141
145 PxU16 materialIndex1; //54 //Can be a U16
146
147 PxU16 pad[5]; //64
148}
149PX_ALIGN_SUFFIX(16);
150
154PX_ALIGN_PREFIX(16)
156{
164 PxReal separation; //16
165}
166PX_ALIGN_SUFFIX(16);
167
171PX_ALIGN_PREFIX(16)
173{
177 PX_ALIGN(16, PxVec3 targetVelocity); //28
181 PxReal maxImpulse; //32
182}
183PX_ALIGN_SUFFIX(16);
184
189PX_ALIGN_PREFIX(16)
191{
195 PX_ALIGN(16, PxVec3 normal); //44
199 PxReal restitution; //48
200
204 PxU32 materialFlags; //52
205
209 PxU16 materialIndex0; //54
213 PxU16 materialIndex1; //56
217 PxReal staticFriction; //60
221 PxReal dynamicFriction; //64
222}
223PX_ALIGN_SUFFIX(16);
224
229{
230 enum StreamFormat
231 {
232 eSIMPLE_STREAM,
233 eMODIFIABLE_STREAM,
234 eCOMPRESSED_MODIFIABLE_STREAM
235 };
242
247
252
256 const PxU32* faceIndice;
257
262
267
272
277
283
289
293 StreamFormat mStreamFormat;
294
299
304
310
314 PX_CUDA_CALLABLE PX_FORCE_INLINE PxContactStreamIterator(const PxU8* contactPatches, const PxU8* contactPoints, const PxU32* contactFaceIndices, PxU32 nbPatches, PxU32 nbContacts)
315 : zero(0.f)
316 {
317 bool modify = false;
318 bool compressedModify = false;
319 bool response = false;
320 bool indices = false;
321
322 PxU32 pointSize = 0;
323 PxU32 patchHeaderSize = sizeof(PxContactPatch);
324
325 const PxContactPatch* patches = reinterpret_cast<const PxContactPatch*>(contactPatches);
326
327 if(patches)
328 {
329 modify = (patches->internalFlags & PxContactPatch::eMODIFIABLE) != 0;
330 compressedModify = (patches->internalFlags & PxContactPatch::eCOMPRESSED_MODIFIED_CONTACT) != 0;
331 indices = (patches->internalFlags & PxContactPatch::eHAS_FACE_INDICES) != 0;
332
333 patch = patches;
334
335 contact = reinterpret_cast<const PxContact*>(contactPoints);
336
337 faceIndice = contactFaceIndices;
338
339 pointSize = compressedModify ? sizeof(PxExtendedContact) : modify ? sizeof(PxModifiableContact) : sizeof(PxContact);
340
342 }
343
344
345 mStreamFormat = compressedModify ? eCOMPRESSED_MODIFIABLE_STREAM : modify ? eMODIFIABLE_STREAM : eSIMPLE_STREAM;
346 hasFaceIndices = PxU32(indices);
347 forceNoResponse = PxU32(!response);
348
349 contactPatchHeaderSize = patchHeaderSize;
350 contactPointSize = pointSize;
351 nextPatchIndex = 0;
353 totalContacts = nbContacts;
354 totalPatches = nbPatches;
355
356 pointStepped = false;
357 }
358
363 PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextPatch() const
364 {
366 }
367
372 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getTotalContactCount() const
373 {
374 return totalContacts;
375 }
376
381 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getTotalPatchCount() const
382 {
383 return totalPatches;
384 }
385
389 PX_CUDA_CALLABLE PX_INLINE void nextPatch()
390 {
391 PX_ASSERT(nextPatchIndex < totalPatches);
393 {
394 if(nextContactIndex < patch->nbContacts)
395 {
396 PxU32 nbToStep = patch->nbContacts - this->nextContactIndex;
397 contact = reinterpret_cast<const PxContact*>(reinterpret_cast<const PxU8*>(contact) + contactPointSize * nbToStep);
398 }
399 patch = reinterpret_cast<const PxContactPatch*>(reinterpret_cast<const PxU8*>(patch) + contactPatchHeaderSize);
400 }
403 }
404
409 PX_CUDA_CALLABLE PX_FORCE_INLINE bool hasNextContact() const
410 {
412 }
413
417 PX_CUDA_CALLABLE PX_FORCE_INLINE void nextContact()
418 {
419 PX_ASSERT(nextContactIndex < patch->nbContacts);
420 if(pointStepped)
421 {
422 contact = reinterpret_cast<const PxContact*>(reinterpret_cast<const PxU8*>(contact) + contactPointSize);
423 faceIndice++;
424 }
426 pointStepped = true;
427 }
428
433 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& getContactNormal() const
434 {
435 return getContactPatch().normal;
436 }
437
442 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvMassScale0() const
443 {
444 return patch->mMassModification.mInvMassScale0;
445 }
446
451 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvMassScale1() const
452 {
453 return patch->mMassModification.mInvMassScale1;
454 }
455
460 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvInertiaScale0() const
461 {
462 return patch->mMassModification.mInvInertiaScale0;
463 }
464
469 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvInertiaScale1() const
470 {
471 return patch->mMassModification.mInvInertiaScale1;
472 }
473
478 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getMaxImpulse() const
479 {
480 return mStreamFormat != eSIMPLE_STREAM ? getExtendedContact().maxImpulse : PX_MAX_REAL;
481 }
482
487 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& getTargetVel() const
488 {
489 return mStreamFormat != eSIMPLE_STREAM ? getExtendedContact().targetVelocity : zero;
490 }
491
496 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3& getContactPoint() const
497 {
498 return contact->contact;
499 }
500
505 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getSeparation() const
506 {
507 return contact->separation;
508 }
509
514 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex0() const
515 {
516 return PXC_CONTACT_NO_FACE_INDEX;
517 }
518
523 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getFaceIndex1() const
524 {
525 return hasFaceIndices ? *faceIndice : PXC_CONTACT_NO_FACE_INDEX;
526 }
527
532 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getStaticFriction() const
533 {
534 return getContactPatch().staticFriction;
535 }
536
541 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getDynamicFriction() const
542 {
543 return getContactPatch().dynamicFriction;
544 }
545
550 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getRestitution() const
551 {
552 return getContactPatch().restitution;
553 }
554
559 PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getDamping() const
560 {
561 return getContactPatch().damping;
562 }
563
568 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getMaterialFlags() const
569 {
570 return getContactPatch().materialFlags;
571 }
572
577 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU16 getMaterialIndex0() const
578 {
579 return PxU16(getContactPatch().materialIndex0);
580 }
581
586 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU16 getMaterialIndex1() const
587 {
588 return PxU16(getContactPatch().materialIndex1);
589 }
590
595 bool advanceToIndex(const PxU32 initialIndex)
596 {
597 PX_ASSERT(this->nextPatchIndex == 0 && this->nextContactIndex == 0);
598
599 PxU32 numToAdvance = initialIndex;
600
601 if(numToAdvance == 0)
602 {
603 PX_ASSERT(hasNextPatch());
604 nextPatch();
605 return true;
606 }
607
608 while(numToAdvance)
609 {
610 while(hasNextPatch())
611 {
612 nextPatch();
613 PxU32 patchSize = patch->nbContacts;
614 if(numToAdvance <= patchSize)
615 {
616 contact = reinterpret_cast<const PxContact*>(reinterpret_cast<const PxU8*>(contact) + contactPointSize * numToAdvance);
617 nextContactIndex += numToAdvance;
618 return true;
619 }
620 else
621 {
622 numToAdvance -= patchSize;
623 }
624 }
625 }
626 return false;
627 }
628
629private:
630
634 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxContactPatch& getContactPatch() const
635 {
636 return *static_cast<const PxContactPatch*>(patch);
637 }
638
639 PX_CUDA_CALLABLE PX_FORCE_INLINE const PxExtendedContact& getExtendedContact() const
640 {
641 PX_ASSERT(mStreamFormat == eMODIFIABLE_STREAM || mStreamFormat == eCOMPRESSED_MODIFIABLE_STREAM);
642 return *static_cast<const PxExtendedContact*>(contact);
643 }
644
645};
646
665
666
667#if PX_VC
668#pragma warning(pop)
669#endif
670
671#if !PX_DOXYGEN
672} // namespace physx
673#endif
674
676#endif
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
PxNodeIndex.
Definition PxNodeIndex.h:51
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Header for a contact patch where all points share same material and normal.
Definition PxContact.h:73
PxU8 nbContacts
The number of contacts in this patch.
Definition PxContact.h:124
PX_ALIGN(16, PxVec3 normal)
Contact normal.
PxReal restitution
Restitution coefficient.
Definition PxContact.h:99
PxU8 materialFlags
The combined material flag of two actors that come in contact.
Definition PxContact.h:130
PxReal damping
Damping coefficient (for compliant contacts)
Definition PxContact.h:114
PxContactPatchFlags
Definition PxContact.h:75
@ eHAS_FACE_INDICES
Indicates this contact stream has face indices.
Definition PxContact.h:76
@ eMODIFIABLE
Indicates this contact stream is modifiable.
Definition PxContact.h:77
@ eFORCE_NO_RESPONSE
Indicates this contact stream is notify-only (no contact response).
Definition PxContact.h:78
PxReal dynamicFriction
Dynamic friction coefficient.
Definition PxContact.h:104
PxU16 materialIndex1
Material index of second body.
Definition PxContact.h:145
PX_ALIGN(16, PxMassModificationProps mMassModification)
Modifiers for scaling the inertia of the involved bodies.
PxU16 startContactIndex
Index of the first contact in the patch.
Definition PxContact.h:119
PxU16 internalFlags
The PxContactPatchFlags for this patch.
Definition PxContact.h:135
PxU16 materialIndex0
Material index of first body.
Definition PxContact.h:140
PxReal staticFriction
Static friction coefficient.
Definition PxContact.h:109
A class to iterate over a compressed contact stream. This supports read-only access to the various co...
Definition PxContact.h:229
bool pointStepped
Internal helper for stepping the contact stream iterator.
Definition PxContact.h:303
PxU32 nextContactIndex
The current contact index.
Definition PxContact.h:271
PxVec3 zero
Utility zero vector to optimize functions returning zero vectors when a certain flag isn't set.
Definition PxContact.h:241
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
const PxU32 * faceIndice
The contact triangle face index.
Definition PxContact.h:256
PxU32 contactPointSize
Contact point size.
Definition PxContact.h:288
PxU32 totalPatches
The total number of patches in this contact stream.
Definition PxContact.h:261
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU16 getMaterialIndex1() const
Gets the contact's material index for shape 1.
Definition PxContact.h:586
StreamFormat mStreamFormat
The stream format.
Definition PxContact.h:293
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvInertiaScale0() const
Gets the inverse inertia scale for body 0.
Definition PxContact.h:460
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvInertiaScale1() const
Gets the inverse inertia scale for body 1.
Definition PxContact.h:469
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getDamping() const
Gets the contact's damping value.
Definition PxContact.h:559
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU16 getMaterialIndex0() const
Gets the contact's material index for shape 0.
Definition PxContact.h:577
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 & getContactNormal() const
Gets the current contact's normal.
Definition PxContact.h:433
const PxContact * contact
The contacts.
Definition PxContact.h:251
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
PxU32 totalContacts
The total number of contact points in this stream.
Definition PxContact.h:266
PxU32 nextPatchIndex
The current patch Index.
Definition PxContact.h:276
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 const PxVec3 & getTargetVel() const
Gets the contact's target velocity.
Definition PxContact.h:487
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getMaxImpulse() const
Gets the contact's max impulse.
Definition PxContact.h:478
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getDynamicFriction() const
Gets the contact's dynamic friction coefficient.
Definition PxContact.h:541
PxU32 contactPatchHeaderSize
Size of contact patch header.
Definition PxContact.h:282
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getTotalPatchCount() const
Returns the total patch count.
Definition PxContact.h:381
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_FORCE_INLINE PxU32 getMaterialFlags() const
Gets the contact's material flags.
Definition PxContact.h:568
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getStaticFriction() const
Gets the contact's static friction coefficient.
Definition PxContact.h:532
PxU32 hasFaceIndices
Specifies if this contactPatch has face indices (handled as bool)
Definition PxContact.h:309
bool advanceToIndex(const PxU32 initialIndex)
Advances the contact stream iterator to a specific contact index.
Definition PxContact.h:595
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvMassScale0() const
Gets the inverse mass scale for body 0.
Definition PxContact.h:442
PX_CUDA_CALLABLE PX_FORCE_INLINE PxContactStreamIterator(const PxU8 *contactPatches, const PxU8 *contactPoints, const PxU32 *contactFaceIndices, PxU32 nbPatches, PxU32 nbContacts)
Constructor.
Definition PxContact.h:314
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getRestitution() const
Gets the contact's restitution coefficient.
Definition PxContact.h:550
PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getInvMassScale1() const
Gets the inverse mass scale for body 1.
Definition PxContact.h:451
const PxContactPatch * patch
The patch headers.
Definition PxContact.h:246
PX_CUDA_CALLABLE PX_INLINE void nextPatch()
Advances iterator to next contact patch.
Definition PxContact.h:389
PxU32 forceNoResponse
Indicates whether this stream is notify-only or not.
Definition PxContact.h:298
PX_CUDA_CALLABLE PX_FORCE_INLINE PxU32 getTotalContactCount() const
Returns the total contact count.
Definition PxContact.h:372
Contact point data.
Definition PxContact.h:156
PxVec3 contact
Contact point in world space.
Definition PxContact.h:160
PxReal separation
Separation value (negative implies penetration).
Definition PxContact.h:164
Contact point data with additional target and max impulse values.
Definition PxContact.h:173
PxReal maxImpulse
Maximum impulse.
Definition PxContact.h:181
PX_ALIGN(16, PxVec3 targetVelocity)
Target velocity.
Contains contact information for a contact reported by the direct-GPU contact report API....
Definition PxContact.h:651
PxNodeIndex nodeIndex0
Unique Id for actor0 if the actor is dynamic.
Definition PxContact.h:657
PxU32 transformCacheRef0
Ref to shape0's transform in transform cache.
Definition PxContact.h:655
PxActor * actor0
Ptr to PxActor for actor0.
Definition PxContact.h:659
PxU8 * contactPoints
Ptr to contact points. Type: PxContact*, size: nbContacts.
Definition PxContact.h:653
PxU32 transformCacheRef1
Ref to shape1's transform in transform cache.
Definition PxContact.h:656
PxNodeIndex nodeIndex1
Unique Id for actor1 if the actor is dynamic.
Definition PxContact.h:658
PxActor * actor1
Ptr to PxActor for actor1.
Definition PxContact.h:660
PxU16 nbContacts
Num contacts.
Definition PxContact.h:662
PxU8 * contactPatches
Ptr to contact patches. Type: PxContactPatch*, size: nbPatches.
Definition PxContact.h:652
PxU16 nbPatches
Num patches.
Definition PxContact.h:663
PxReal * contactForces
Ptr to contact forces. Size: nbContacts.
Definition PxContact.h:654
Struct for specifying mass modification for a pair of rigids.
Definition PxContact.h:60
A modifiable contact point. This has additional fields per-contact to permit modification by user.
Definition PxContact.h:191
PxReal dynamicFriction
dynamic friction coefficient
Definition PxContact.h:221
PxU16 materialIndex1
Shape B's material index.
Definition PxContact.h:213
PxReal staticFriction
static friction coefficient
Definition PxContact.h:217
PX_ALIGN(16, PxVec3 normal)
Contact normal.
PxU32 materialFlags
Material Flags.
Definition PxContact.h:204
PxReal restitution
Restitution coefficient.
Definition PxContact.h:199
PxU16 materialIndex0
Shape A's material index.
Definition PxContact.h:209