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 PXV_DYNAMICS_H
32#define PXV_DYNAMICS_H
33
34#include "foundation/PxVec3.h"
35#include "foundation/PxQuat.h"
36#include "foundation/PxTransform.h"
37#include "foundation/PxSimpleTypes.h"
38#include "PsIntrinsics.h"
39#include "PxRigidDynamic.h"
40
41namespace physx
42{
43
44/*!
45\file
46Dynamics interface.
47*/
48
49struct PxsRigidCore
50{
51//= ATTENTION! =====================================================================================
52// Changing the data layout of this class breaks the binary serialization format. See comments for
53// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
54// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
55// accordingly.
56//==================================================================================================
57
58 PxsRigidCore() : mFlags(0), solverIterationCounts(0) {}
59 PxsRigidCore(const PxEMPTY) : mFlags(PxEmpty) {}
60
61 PX_ALIGN_PREFIX(16)
62 PxTransform body2World PX_ALIGN_SUFFIX(16);
63 PxRigidBodyFlags mFlags; // API body flags
64 PxU16 solverIterationCounts; // vel iters are in low word and pos iters in high word.
65
66 PX_FORCE_INLINE PxU32 isKinematic() const { return mFlags & PxRigidBodyFlag::eKINEMATIC; }
67 PX_FORCE_INLINE PxU32 hasCCD() const { return mFlags & PxRigidBodyFlag::eENABLE_CCD; }
68 PX_FORCE_INLINE PxU32 hasCCDFriction() const { return mFlags & PxRigidBodyFlag::eENABLE_CCD_FRICTION; }
69 PX_FORCE_INLINE PxU32 hasIdtBody2Actor() const { return mFlags & PxRigidBodyFlag::eRESERVED; }
70};
71PX_COMPILE_TIME_ASSERT(sizeof(PxsRigidCore) == 32);
72
73struct PxsBodyCore: public PxsRigidCore
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 |= PxRigidBodyFlag::eRESERVED;
90 else
91 mFlags.clear(e: 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 PxReal freezeThreshold;
117 PxReal wakeCounter; //144 this is authoritative wakeCounter
118
119 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.
120 PxU32 numCountedInteractions;
121 PxU32 numBodyInteractions; //Used by adaptive force to keep track of the total number of body interactions
122 PxU8 isFastMoving; //This could be a single bit but it's a u8 at the moment for simplicity's sake
123 PxU8 disableGravity; //This could be a single bit but it's a u8 at the moment for simplicity's sake
124 PxRigidDynamicLockFlags lockFlags; //This is u8.
125 PxU8 kinematicLink; //160 This indicates whether the articulation link is kinematic link. All fits into 16 byte alignment
126
127 // PT: TODO: revisit this / move to PxsCCD.cpp
128 PX_FORCE_INLINE bool shouldCreateContactReports() const
129 {
130 const PxU32* binary = reinterpret_cast<const PxU32*>(&contactReportThreshold);
131 return *binary != 0x7f7fffff; // PX_MAX_REAL
132 }
133
134 // PT: moved from Sc::BodyCore ctor - we don't want to duplicate all this in immediate mode
135 PX_FORCE_INLINE void init( const PxTransform& bodyPose,
136 const PxVec3& inverseInertia_, PxReal inverseMass_,
137 PxReal wakeCounter_, PxReal scaleSpeed,
138 PxReal linearDamping_, PxReal angularDamping_,
139 PxReal maxLinearVelocitySq_, PxReal maxAngularVelocitySq_)
140 {
141 PX_ASSERT(bodyPose.p.isFinite());
142 PX_ASSERT(bodyPose.q.isFinite());
143
144 // PT: TODO: unify naming convention
145
146 // From PxsRigidCore
147 body2World = bodyPose;
148 mFlags = PxRigidBodyFlags();
149 solverIterationCounts = (1 << 8) | 4;
150
151 setBody2Actor(PxTransform(PxIdentity));
152
153 ccdAdvanceCoefficient = 0.15f;
154 linearVelocity = PxVec3(0.0f);
155 maxPenBias = -1e32f;//-PX_MAX_F32;
156 angularVelocity = PxVec3(0.0f);
157 contactReportThreshold = PX_MAX_F32;
158 maxAngularVelocitySq = maxAngularVelocitySq_;
159 maxLinearVelocitySq = maxLinearVelocitySq_;
160 linearDamping = linearDamping_;
161 angularDamping = angularDamping_;
162 inverseInertia = inverseInertia_;
163 inverseMass = inverseMass_;
164 maxContactImpulse = 1e32f;// PX_MAX_F32;
165 sleepThreshold = 5e-5f * scaleSpeed * scaleSpeed;
166 freezeThreshold = 2.5e-5f * scaleSpeed * scaleSpeed;
167 wakeCounter = wakeCounter_;
168 // PT: this one is not initialized?
169 //solverWakeCounter
170 // PT: these are initialized in BodySim ctor
171 //numCountedInteractions;
172 //numBodyInteractions;
173 isFastMoving = false;
174 disableGravity = false;
175 lockFlags = PxRigidDynamicLockFlags(0);
176 }
177};
178
179PX_COMPILE_TIME_ASSERT(sizeof(PxsBodyCore) == 160);
180
181}
182
183#endif
184

source code of qtquick3dphysics/src/3rdparty/PhysX/source/lowlevel/api/include/PxvDynamics.h