RavEngine
Loading...
Searching...
No Matches
PxContactModifyCallback.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_MODIFY_CALLBACK_H
30#define PX_CONTACT_MODIFY_CALLBACK_H
35#include "PxPhysXConfig.h"
36#include "PxShape.h"
37#include "PxContact.h"
38#include "foundation/PxTransform.h"
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
45class PxShape;
46
60{
61public:
69 PX_FORCE_INLINE const PxVec3& getPoint(PxU32 i) const { return mContacts[i].contact; }
70
78 PX_FORCE_INLINE void setPoint(PxU32 i, const PxVec3& p) { mContacts[i].contact = p; }
79
87 PX_FORCE_INLINE const PxVec3& getNormal(PxU32 i) const { return mContacts[i].normal; }
88
98 PX_FORCE_INLINE void setNormal(PxU32 i, const PxVec3& n)
99 {
100 PxContactPatch* patch = getPatch();
101 patch->internalFlags |= PxContactPatch::eREGENERATE_PATCHES;
102 mContacts[i].normal = n;
103 }
104
112 PX_FORCE_INLINE PxReal getSeparation(PxU32 i) const { return mContacts[i].separation; }
113
121 PX_FORCE_INLINE void setSeparation(PxU32 i, PxReal s) { mContacts[i].separation = s; }
122
131 PX_FORCE_INLINE const PxVec3& getTargetVelocity(PxU32 i) const { return mContacts[i].targetVelocity; }
132
141 {
142 PxContactPatch* patch = getPatch();
143 patch->internalFlags |= PxContactPatch::eHAS_TARGET_VELOCITY;
144 mContacts[i].targetVelocity = v;
145 }
146
155 PX_FORCE_INLINE PxU32 getInternalFaceIndex0(PxU32 i) const { PX_UNUSED(i); return PXC_CONTACT_NO_FACE_INDEX; }
156
165 {
166 PxContactPatch* patch = getPatch();
167 if (patch->internalFlags & PxContactPatch::eHAS_FACE_INDICES)
168 {
169 return reinterpret_cast<PxU32*>(mContacts + mCount)[mCount + i];
170 }
171 return PXC_CONTACT_NO_FACE_INDEX;
172 }
173
181 PX_FORCE_INLINE PxReal getMaxImpulse(PxU32 i) const { return mContacts[i].maxImpulse; }
182
192 PX_FORCE_INLINE void setMaxImpulse(PxU32 i, PxReal s)
193 {
194 PxContactPatch* patch = getPatch();
195 patch->internalFlags |= PxContactPatch::eHAS_MAX_IMPULSE;
196 mContacts[i].maxImpulse = s;
197 }
198
206 PX_FORCE_INLINE PxReal getRestitution(PxU32 i) const { return mContacts[i].restitution; }
207
217 PX_FORCE_INLINE void setRestitution(PxU32 i, PxReal r)
218 {
219 PxContactPatch* patch = getPatch();
220 patch->internalFlags |= PxContactPatch::eREGENERATE_PATCHES;
221 mContacts[i].restitution = r;
222 }
223
231 PX_FORCE_INLINE PxReal getStaticFriction(PxU32 i) const { return mContacts[i].staticFriction; }
232
240 PX_FORCE_INLINE void setStaticFriction(PxU32 i, PxReal f)
241 {
242 PxContactPatch* patch = getPatch();
243 patch->internalFlags |= PxContactPatch::eREGENERATE_PATCHES;
245 }
246
254 PX_FORCE_INLINE PxReal getDynamicFriction(PxU32 i) const { return mContacts[i].dynamicFriction; }
255
263 PX_FORCE_INLINE void setDynamicFriction(PxU32 i, PxReal f)
264 {
265 PxContactPatch* patch = getPatch();
266 patch->internalFlags |= PxContactPatch::eREGENERATE_PATCHES;
268 }
269
276 PX_FORCE_INLINE void ignore(PxU32 i) { setMaxImpulse(i, 0.0f); }
277
281 PX_FORCE_INLINE PxU32 size() const { return mCount; }
282
290 {
291 PxContactPatch* patch = getPatch();
292 return patch->mMassModification.mInvMassScale0;
293 }
294
302 {
303 PxContactPatch* patch = getPatch();
304 return patch->mMassModification.mInvMassScale1;
305 }
306
314 {
315 PxContactPatch* patch = getPatch();
316 return patch->mMassModification.mInvInertiaScale0;
317 }
318
326 {
327 PxContactPatch* patch = getPatch();
328 return patch->mMassModification.mInvInertiaScale1;
329 }
330
338 PX_FORCE_INLINE void setInvMassScale0(const PxReal scale)
339 {
340 PxContactPatch* patch = getPatch();
341 patch->mMassModification.mInvMassScale0 = scale;
342 patch->internalFlags |= PxContactPatch::eHAS_MODIFIED_MASS_RATIOS;
343 }
344
352 PX_FORCE_INLINE void setInvMassScale1(const PxReal scale)
353 {
354 PxContactPatch* patch = getPatch();
355 patch->mMassModification.mInvMassScale1 = scale;
356 patch->internalFlags |= PxContactPatch::eHAS_MODIFIED_MASS_RATIOS;
357 }
358
366 PX_FORCE_INLINE void setInvInertiaScale0(const PxReal scale)
367 {
368 PxContactPatch* patch = getPatch();
369 patch->mMassModification.mInvInertiaScale0 = scale;
370 patch->internalFlags |= PxContactPatch::eHAS_MODIFIED_MASS_RATIOS;
371 }
372
380 PX_FORCE_INLINE void setInvInertiaScale1(const PxReal scale)
381 {
382 PxContactPatch* patch = getPatch();
383 patch->mMassModification.mInvInertiaScale1 = scale;
384 patch->internalFlags |= PxContactPatch::eHAS_MODIFIED_MASS_RATIOS;
385 }
386
387protected:
388
389 PX_FORCE_INLINE PxContactPatch* getPatch() const
390 {
391 const size_t headerOffset = sizeof(PxContactPatch)*mCount;
392 return reinterpret_cast<PxContactPatch*>(reinterpret_cast<PxU8*>(mContacts) - headerOffset);
393 }
394
395 PxU32 mCount;
397};
398
399
400
408{
409public:
410
417
423 const PxShape* shape[2];
424
432
437};
438
439
459{
460public:
461
475 virtual void onContactModify(PxContactModifyPair* const pairs, PxU32 count) = 0;
476
477protected:
478 virtual ~PxContactModifyCallback(){}
479};
480
500{
501public:
502
514 virtual void onCCDContactModify(PxContactModifyPair* const pairs, PxU32 count) = 0;
515
516protected:
518};
519
520
521#if !PX_DOXYGEN
522} // namespace physx
523#endif
524
526#endif
An interface class that the user can implement in order to modify CCD contact constraints.
Definition PxContactModifyCallback.h:500
virtual void onCCDContactModify(PxContactModifyPair *const pairs, PxU32 count)=0
Passes modifiable arrays of contacts to the application.
An interface class that the user can implement in order to modify contact constraints.
Definition PxContactModifyCallback.h:459
virtual void onContactModify(PxContactModifyPair *const pairs, PxU32 count)=0
Passes modifiable arrays of contacts to the application.
An array of instances of this class is passed to PxContactModifyCallback::onContactModify().
Definition PxContactModifyCallback.h:408
const PxShape * shape[2]
The shapes which make up the pair in contact.
Definition PxContactModifyCallback.h:423
const PxRigidActor * actor[2]
The actors which make up the pair in contact.
Definition PxContactModifyCallback.h:416
PxContactSet contacts
An array of contact points between these two shapes.
Definition PxContactModifyCallback.h:436
PxTransform transform[2]
The shape to world transforms of the two shapes.
Definition PxContactModifyCallback.h:431
An array of contact points, as passed to contact modification.
Definition PxContactModifyCallback.h:60
PX_FORCE_INLINE void setTargetVelocity(PxU32 i, const PxVec3 &v)
Alter the target velocity of a specific contact point in the set.
Definition PxContactModifyCallback.h:140
PX_FORCE_INLINE void setPoint(PxU32 i, const PxVec3 &p)
Alter the position of a specific contact point in the set.
Definition PxContactModifyCallback.h:78
PX_FORCE_INLINE void setInvMassScale1(const PxReal scale)
Sets the invMassScale of body 1.
Definition PxContactModifyCallback.h:352
PX_FORCE_INLINE void setMaxImpulse(PxU32 i, PxReal s)
Alter the maximum impulse for a specific contact point in the set.
Definition PxContactModifyCallback.h:192
PX_FORCE_INLINE PxReal getMaxImpulse(PxU32 i) const
Get the maximum impulse for a specific contact point in the set.
Definition PxContactModifyCallback.h:181
PX_FORCE_INLINE PxReal getInvMassScale1() const
Returns the invMassScale of body 1.
Definition PxContactModifyCallback.h:301
PX_FORCE_INLINE void setRestitution(PxU32 i, PxReal r)
Alter the restitution coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:217
PX_FORCE_INLINE void setSeparation(PxU32 i, PxReal s)
Alter the separation of a specific contact point in the set.
Definition PxContactModifyCallback.h:121
PX_FORCE_INLINE const PxVec3 & getPoint(PxU32 i) const
Get the position of a specific contact point in the set.
Definition PxContactModifyCallback.h:69
PX_FORCE_INLINE PxReal getStaticFriction(PxU32 i) const
Get the static friction coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:231
PxModifiableContact * mContacts
The contact points of the set.
Definition PxContactModifyCallback.h:396
PX_FORCE_INLINE PxU32 size() const
The number of contact points in the set.
Definition PxContactModifyCallback.h:281
PX_FORCE_INLINE PxReal getSeparation(PxU32 i) const
Get the separation distance of a specific contact point in the set.
Definition PxContactModifyCallback.h:112
PX_FORCE_INLINE PxU32 getInternalFaceIndex1(PxU32 i) const
Get the face index with respect to the second shape of the pair for a specific contact point in the s...
Definition PxContactModifyCallback.h:164
PX_FORCE_INLINE void setInvInertiaScale0(const PxReal scale)
Sets the invInertiaScale of body 0.
Definition PxContactModifyCallback.h:366
PX_FORCE_INLINE PxReal getInvInertiaScale1() const
Returns the invInertiaScale of body 1.
Definition PxContactModifyCallback.h:325
PX_FORCE_INLINE void setDynamicFriction(PxU32 i, PxReal f)
Alter the static dynamic coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:263
PX_FORCE_INLINE PxReal getInvMassScale0() const
Returns the invMassScale of body 0.
Definition PxContactModifyCallback.h:289
PxU32 mCount
Number of contact points in the set.
Definition PxContactModifyCallback.h:395
PX_FORCE_INLINE PxReal getInvInertiaScale0() const
Returns the invInertiaScale of body 0.
Definition PxContactModifyCallback.h:313
PX_FORCE_INLINE PxU32 getInternalFaceIndex0(PxU32 i) const
Get the face index with respect to the first shape of the pair for a specific contact point in the se...
Definition PxContactModifyCallback.h:155
PX_FORCE_INLINE PxReal getRestitution(PxU32 i) const
Get the restitution coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:206
PX_FORCE_INLINE void setInvInertiaScale1(const PxReal scale)
Sets the invInertiaScale of body 1.
Definition PxContactModifyCallback.h:380
PX_FORCE_INLINE const PxVec3 & getNormal(PxU32 i) const
Get the contact normal of a specific contact point in the set.
Definition PxContactModifyCallback.h:87
PX_FORCE_INLINE void setStaticFriction(PxU32 i, PxReal f)
Alter the static friction coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:240
PX_FORCE_INLINE const PxVec3 & getTargetVelocity(PxU32 i) const
Get the target velocity of a specific contact point in the set.
Definition PxContactModifyCallback.h:131
PX_FORCE_INLINE void ignore(PxU32 i)
Ignore the contact point.
Definition PxContactModifyCallback.h:276
PX_FORCE_INLINE void setInvMassScale0(const PxReal scale)
Sets the invMassScale of body 0.
Definition PxContactModifyCallback.h:338
PX_FORCE_INLINE PxReal getDynamicFriction(PxU32 i) const
Get the static friction coefficient for a specific contact point in the set.
Definition PxContactModifyCallback.h:254
PX_FORCE_INLINE void setNormal(PxU32 i, const PxVec3 &n)
Alter the contact normal of a specific contact point in the set.
Definition PxContactModifyCallback.h:98
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Abstract class for collision shapes.
Definition PxShape.h:146
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
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
@ eHAS_FACE_INDICES
Indicates this contact stream has face indices.
Definition PxContact.h:76
@ eHAS_TARGET_VELOCITY
Indicates this contact stream has target velocities set.
Definition PxContact.h:80
@ eHAS_MAX_IMPULSE
Indicates this contact stream has max impulses set.
Definition PxContact.h:81
@ eHAS_MODIFIED_MASS_RATIOS
Indicates this contact stream has modified mass ratios.
Definition PxContact.h:79
@ eREGENERATE_PATCHES
Indicates this contact stream needs patches re-generated. This is required if the application modifie...
Definition PxContact.h:82
PxVec3 contact
Contact point in world space.
Definition PxContact.h:160
PxReal separation
Separation value (negative implies penetration).
Definition PxContact.h:164
PxReal maxImpulse
Maximum impulse.
Definition PxContact.h:181
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
PxReal staticFriction
static friction coefficient
Definition PxContact.h:217
PxReal restitution
Restitution coefficient.
Definition PxContact.h:199