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#ifndef PX_PHYSICS_SCP_BODYCORE
31#define PX_PHYSICS_SCP_BODYCORE
32
33#include "foundation/PxTransform.h"
34#include "ScRigidCore.h"
35#include "PxRigidDynamic.h"
36#include "PxvDynamics.h"
37#include "PxvConfig.h"
38#include "PsPool.h"
39
40namespace physx
41{
42class PxRigidBodyDesc;
43
44namespace Sc
45{
46 class BodySim;
47 struct SimStateData;
48
49 struct KinematicTransform
50 {
51 PxTransform targetPose; // The body will move to this pose over the superstep following this getting set.
52 PxU8 targetValid; // User set a kinematic target.
53 PxU8 pad[2];
54 PxU8 type;
55 };
56
57 class BodyCore : public RigidCore
58 {
59 //= ATTENTION! =====================================================================================
60 // Changing the data layout of this class breaks the binary serialization format. See comments for
61 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
62 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
63 // accordingly.
64 //==================================================================================================
65
66 //---------------------------------------------------------------------------------
67 // Construction, destruction & initialization
68 //---------------------------------------------------------------------------------
69 public:
70// PX_SERIALIZATION
71 BodyCore(const PxEMPTY) : RigidCore(PxEmpty), mCore(PxEmpty), mSimStateData(NULL) {}
72 static void getBinaryMetaData(PxOutputStream& stream);
73 void disableInternalCaching(bool disable);
74 void restoreDynamicData();
75
76//~PX_SERIALIZATION
77 BodyCore(PxActorType::Enum type, const PxTransform& bodyPose);
78 /*virtual*/ ~BodyCore();
79
80 //---------------------------------------------------------------------------------
81 // External API
82 //---------------------------------------------------------------------------------
83 PX_FORCE_INLINE const PxTransform& getBody2World() const { return mCore.body2World; }
84 void setBody2World(const PxTransform& p);
85
86 PX_FORCE_INLINE const PxVec3& getLinearVelocity() const { return mCore.linearVelocity; }
87 void setLinearVelocity(const PxVec3& v);
88
89 PX_FORCE_INLINE const PxVec3& getAngularVelocity() const { return mCore.angularVelocity; }
90 void setAngularVelocity(const PxVec3& v);
91
92 PX_FORCE_INLINE void updateVelocities(const PxVec3& linearVelModPerStep, const PxVec3& angularVelModPerStep)
93 {
94 mCore.linearVelocity += linearVelModPerStep;
95 mCore.angularVelocity += angularVelModPerStep;
96 }
97
98 PX_FORCE_INLINE const PxTransform& getBody2Actor() const { return mCore.getBody2Actor(); }
99 void setBody2Actor(const PxTransform& p);
100
101 void addSpatialAcceleration(Ps::Pool<SimStateData>* simStateDataPool, const PxVec3* linAcc, const PxVec3* angAcc);
102 void setSpatialAcceleration(Ps::Pool<SimStateData>* simStateDataPool, const PxVec3* linAcc, const PxVec3* angAcc);
103 void clearSpatialAcceleration(bool force, bool torque);
104 void addSpatialVelocity(Ps::Pool<SimStateData>* simStateDataPool, const PxVec3* linVelDelta, const PxVec3* angVelDelta);
105 void clearSpatialVelocity(bool force, bool torque);
106
107 PX_FORCE_INLINE PxReal getMaxPenetrationBias() const { return mCore.maxPenBias; }
108 PX_FORCE_INLINE void setMaxPenetrationBias(PxReal p) { mCore.maxPenBias = p; }
109
110 PxReal getInverseMass() const;
111 void setInverseMass(PxReal m);
112 const PxVec3& getInverseInertia() const;
113 void setInverseInertia(const PxVec3& i);
114
115 PxReal getLinearDamping() const;
116 void setLinearDamping(PxReal d);
117
118 PxReal getAngularDamping() const;
119 void setAngularDamping(PxReal d);
120
121 PX_FORCE_INLINE PxRigidBodyFlags getFlags() const { return mCore.mFlags; }
122 void setFlags(Ps::Pool<SimStateData>* simStateDataPool, PxRigidBodyFlags f);
123
124 PX_FORCE_INLINE PxRigidDynamicLockFlags getRigidDynamicLockFlags() const { return mCore.lockFlags; }
125
126 PX_FORCE_INLINE void setRigidDynamicLockFlags(PxRigidDynamicLockFlags flags) { mCore.lockFlags = flags; }
127
128 PX_FORCE_INLINE PxReal getSleepThreshold() const { return mCore.sleepThreshold; }
129 void setSleepThreshold(PxReal t);
130
131 PX_FORCE_INLINE PxReal getFreezeThreshold() const { return mCore.freezeThreshold; }
132 void setFreezeThreshold(PxReal t);
133
134 PX_FORCE_INLINE PxReal getMaxContactImpulse() const { return mCore.maxContactImpulse; }
135 void setMaxContactImpulse(PxReal m);
136
137 PxU32 getInternalIslandNodeIndex() const;
138
139 PX_FORCE_INLINE PxReal getWakeCounter() const { return mCore.wakeCounter; }
140 void setWakeCounter(PxReal wakeCounter, bool forceWakeUp=false);
141
142 bool isSleeping() const;
143 PX_FORCE_INLINE void wakeUp(PxReal wakeCounter) { setWakeCounter(wakeCounter, forceWakeUp: true); }
144 void putToSleep();
145
146 PxReal getMaxAngVelSq() const;
147 void setMaxAngVelSq(PxReal v);
148
149 PxReal getMaxLinVelSq() const;
150 void setMaxLinVelSq(PxReal v);
151
152 PX_FORCE_INLINE PxU16 getSolverIterationCounts() const { return mCore.solverIterationCounts; }
153 void setSolverIterationCounts(PxU16 c);
154
155 bool getKinematicTarget(PxTransform& p) const;
156 bool getHasValidKinematicTarget() const;
157 void setKinematicTarget(Ps::Pool<SimStateData>* simStateDataPool, const PxTransform& p, PxReal wakeCounter);
158 void invalidateKinematicTarget();
159
160
161 PX_FORCE_INLINE PxReal getContactReportThreshold() const { return mCore.contactReportThreshold; }
162 void setContactReportThreshold(PxReal t) { mCore.contactReportThreshold = t; }
163
164 void onOriginShift(const PxVec3& shift);
165
166 //---------------------------------------------------------------------------------
167 // Internal API
168 //---------------------------------------------------------------------------------
169
170 PX_FORCE_INLINE void setLinearVelocityInternal(const PxVec3& v) { mCore.linearVelocity = v; }
171 PX_FORCE_INLINE void setAngularVelocityInternal(const PxVec3& v) { mCore.angularVelocity = v; }
172 PX_FORCE_INLINE void setWakeCounterFromSim(PxReal c) { mCore.wakeCounter = c; }
173
174 BodySim* getSim() const;
175
176 PX_FORCE_INLINE PxsBodyCore& getCore() { return mCore; }
177 PX_FORCE_INLINE const PxsBodyCore& getCore() const { return mCore; }
178
179 PX_FORCE_INLINE PxReal getCCDAdvanceCoefficient() const { return mCore.ccdAdvanceCoefficient; }
180 PX_FORCE_INLINE void setCCDAdvanceCoefficient(PxReal c) { mCore.ccdAdvanceCoefficient = c; }
181
182 bool setupSimStateData(Ps::Pool<SimStateData>* simStateDataPool, const bool isKinematic, const bool targetValid = false);
183 void tearDownSimStateData(Ps::Pool<SimStateData>* simStateDataPool, const bool isKinematic);
184
185 bool checkSimStateKinematicStatus(bool) const;
186
187 Ps::IntBool isFrozen() const;
188
189 PX_FORCE_INLINE const SimStateData* getSimStateData(bool isKinematic) const { return (mSimStateData && (checkSimStateKinematicStatus(isKinematic)) ? mSimStateData : NULL); }
190 PX_FORCE_INLINE SimStateData* getSimStateData(bool isKinematic) { return (mSimStateData && (checkSimStateKinematicStatus(isKinematic)) ? mSimStateData : NULL); }
191
192 PX_FORCE_INLINE SimStateData* getSimStateData_Unchecked() const { return mSimStateData; }
193
194 static PX_FORCE_INLINE size_t getCoreOffset() { return PX_OFFSET_OF_RT(BodyCore, mCore); }
195
196 static PX_FORCE_INLINE BodyCore& getCore(PxsBodyCore& core) { return *reinterpret_cast<BodyCore*>(reinterpret_cast<PxU8*>(&core) - getCoreOffset()); }
197
198 void setKinematicLink(const bool value);
199
200 private:
201 void backup(SimStateData&);
202 void restore();
203
204 PX_ALIGN_PREFIX(16) PxsBodyCore mCore PX_ALIGN_SUFFIX(16);
205 SimStateData* mSimStateData;
206 };
207
208 PxActor* getPxActorFromBodyCore(Sc::BodyCore* bodyCore, PxActorType::Enum& type);
209
210} // namespace Sc
211
212}
213
214#endif
215

source code of qtquick3dphysics/src/3rdparty/PhysX/source/simulationcontroller/include/ScBodyCore.h