RavEngine
Loading...
Searching...
No Matches
PxvDynamics.h
Go to the documentation of this file.
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 PXV_DYNAMICS_H
30#define PXV_DYNAMICS_H
31
32#include "foundation/PxVec3.h"
33#include "foundation/PxQuat.h"
34#include "foundation/PxTransform.h"
35#include "foundation/PxSimpleTypes.h"
36#include "foundation/PxIntrinsics.h"
37#include "PxRigidDynamic.h"
38
39namespace physx
40{
41
48{
49//= ATTENTION! =====================================================================================
50// Changing the data layout of this class breaks the binary serialization format. See comments for
51// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
52// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
53// accordingly.
54//==================================================================================================
55
56 PxsRigidCore() : mFlags(0), solverIterationCounts(0) {}
57 PxsRigidCore(const PxEMPTY) : mFlags(PxEmpty) {}
58
59 PX_ALIGN_PREFIX(16)
60 PxTransform body2World PX_ALIGN_SUFFIX(16);
61 PxRigidBodyFlags mFlags; // API body flags
62 PxU16 solverIterationCounts; // vel iters are in low word and pos iters in high word.
63
64 PX_FORCE_INLINE PxU32 isKinematic() const { return mFlags & PxRigidBodyFlag::eKINEMATIC; }
65 PX_FORCE_INLINE PxU32 hasCCD() const { return mFlags & PxRigidBodyFlag::eENABLE_CCD; }
66 PX_FORCE_INLINE PxU32 hasCCDFriction() const { return mFlags & PxRigidBodyFlag::eENABLE_CCD_FRICTION; }
67 PX_FORCE_INLINE PxU32 hasIdtBody2Actor() const { return mFlags & PxRigidBodyFlag::eRESERVED; }
68};
70
71#define PXV_CONTACT_REPORT_DISABLED PX_MAX_F32
72
74{
75//= ATTENTION! =====================================================================================
76// Changing the data layout of this class breaks the binary serialization format. See comments for
77// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
78// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
79// accordingly.
80//==================================================================================================
81
82 PxsBodyCore() : PxsRigidCore() { kinematicLink = PxU8(0); }
83 PxsBodyCore(const PxEMPTY) : PxsRigidCore(PxEmpty) {}
84
85 PX_FORCE_INLINE const PxTransform& getBody2Actor() const { return body2Actor; }
86 PX_FORCE_INLINE void setBody2Actor(const PxTransform& t)
87 {
88 if(t.p.isZero() && t.q.isIdentity())
89 mFlags.raise(PxRigidBodyFlag::eRESERVED);
90 else
91 mFlags.clear(PxRigidBodyFlag::eRESERVED);
92
93 body2Actor = t;
94 }
95 protected:
96 PxTransform body2Actor;
97 public:
98 PxReal ccdAdvanceCoefficient; //64
99
100 PxVec3 linearVelocity;
101 PxReal maxPenBias;
102
103 PxVec3 angularVelocity;
104 PxReal contactReportThreshold; //96
105
106 PxReal maxAngularVelocitySq;
107 PxReal maxLinearVelocitySq;
108 PxReal linearDamping;
109 PxReal angularDamping; //112
110
111 PxVec3 inverseInertia;
112 PxReal inverseMass; //128
113
114 PxReal maxContactImpulse;
115 PxReal sleepThreshold;
116 union
117 {
118 PxReal freezeThreshold;
119 PxReal cfmScale;
120 };
121
122 PxReal wakeCounter; //144 this is authoritative wakeCounter
123
124 PxReal solverWakeCounter; //this is calculated by the solver when it performs sleepCheck. It is committed to wakeCounter in ScAfterIntegrationTask if the body is still awake.
125 PxU32 numCountedInteractions;
126 PxReal offsetSlop; //Slop value used to snap contact line of action back in-line with the COM
127 PxU8 isFastMoving; //This could be a single bit but it's a u8 at the moment for simplicity's sake
128 PxU8 disableGravity; //This could be a single bit but it's a u8 at the moment for simplicity's sake
129 PxRigidDynamicLockFlags lockFlags; //This is u8.
130 PxU8 kinematicLink; //160 This indicates whether the articulation link is kinematic link. All fits into 16 byte alignment
131
132 // PT: moved from Sc::BodyCore ctor - we don't want to duplicate all this in immediate mode
133 PX_FORCE_INLINE void init( const PxTransform& bodyPose,
134 const PxVec3& inverseInertia_, PxReal inverseMass_,
135 PxReal wakeCounter_, PxReal scaleSpeed,
136 PxReal linearDamping_, PxReal angularDamping_,
137 PxReal maxLinearVelocitySq_, PxReal maxAngularVelocitySq_,
139 {
140 PX_ASSERT(bodyPose.p.isFinite());
141 PX_ASSERT(bodyPose.q.isFinite());
142
143 // PT: TODO: unify naming convention
144
145 // From PxsRigidCore
146 body2World = bodyPose;
147 mFlags = PxRigidBodyFlags();
148 solverIterationCounts = (1 << 8) | 4;
149
150 setBody2Actor(PxTransform(PxIdentity));
151
152 ccdAdvanceCoefficient = 0.15f;
153 linearVelocity = PxVec3(0.0f);
154 maxPenBias = -1e32f;//-PX_MAX_F32;
155 angularVelocity = PxVec3(0.0f);
156 contactReportThreshold = PXV_CONTACT_REPORT_DISABLED;
157 maxAngularVelocitySq = maxAngularVelocitySq_;
158 maxLinearVelocitySq = maxLinearVelocitySq_;
159 linearDamping = linearDamping_;
160 angularDamping = angularDamping_;
161 inverseInertia = inverseInertia_;
162 inverseMass = inverseMass_;
163 maxContactImpulse = 1e32f;// PX_MAX_F32;
164 sleepThreshold = 5e-5f * scaleSpeed * scaleSpeed;
166 cfmScale = 0.025f;
167 else
168 freezeThreshold = 2.5e-5f * scaleSpeed * scaleSpeed;
169 wakeCounter = wakeCounter_;
170 offsetSlop = 0.f;
171 // PT: this one is not initialized?
172 //solverWakeCounter
173 // PT: these are initialized in BodySim ctor
174 //numCountedInteractions;
175 //numBodyInteractions;
176 isFastMoving = false;
177 disableGravity = false;
178 lockFlags = PxRigidDynamicLockFlags(0);
179 }
180};
181
182PX_COMPILE_TIME_ASSERT(sizeof(PxsBodyCore) == 160);
183
184}
185
186#endif
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isIdentity() const
returns true if quat is identity
Definition PxQuat.h:116
PX_CUDA_CALLABLE bool isFinite() const
returns true if all elements are finite (not NAN or INF, etc.)
Definition PxQuat.h:124
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition PxVec3.h:156
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero() const
tests for exact zero vector
Definition PxVec3.h:148
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxRigidBodyFlag::Enum, PxU16 > PxRigidBodyFlags
collection of set bits defined in PxRigidBodyFlag.
Definition PxRigidBody.h:189
PxEMPTY
Definition Px.h:87
Enum
Definition PxActor.h:121
@ eARTICULATION_LINK
An articulation link.
Definition PxActor.h:138
@ eENABLE_CCD_FRICTION
Enabled CCD in swept integration for the actor.
Definition PxRigidBody.h:107
@ eKINEMATIC
Enables kinematic mode for the actor.
Definition PxRigidBody.h:74
@ eENABLE_CCD
Enables swept integration for the actor.
Definition PxRigidBody.h:96
@ eRESERVED
Reserved for internal usage.
Definition PxRigidBody.h:180
Definition PxvDynamics.h:74
Definition PxvDynamics.h:48