RavEngine
Loading...
Searching...
No Matches
ScBodyCore.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 SC_BODY_CORE_H
30#define SC_BODY_CORE_H
31
32#include "foundation/PxTransform.h"
33#include "ScRigidCore.h"
34#include "PxRigidDynamic.h"
35#include "PxvDynamics.h"
36#include "PxvConfig.h"
37#include "foundation/PxPool.h"
38
39namespace physx
40{
41class PxRigidBodyDesc;
42
43namespace Sc
44{
45 class BodySim;
46 struct SimStateData;
47
48 class BodyCore : public RigidCore
49 {
50 //= ATTENTION! =====================================================================================
51 // Changing the data layout of this class breaks the binary serialization format. See comments for
52 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
53 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
54 // accordingly.
55 //==================================================================================================
56
57 //---------------------------------------------------------------------------------
58 // Construction, destruction & initialization
59 //---------------------------------------------------------------------------------
60 public:
61// PX_SERIALIZATION
62 BodyCore(const PxEMPTY) : RigidCore(PxEmpty), mCore(PxEmpty) {}
63 static void getBinaryMetaData(PxOutputStream& stream);
64 void restoreDynamicData();
65
66//~PX_SERIALIZATION
67 BodyCore(PxActorType::Enum type, const PxTransform& bodyPose);
68 ~BodyCore();
69
70 //---------------------------------------------------------------------------------
71 // External API
72 //---------------------------------------------------------------------------------
73 PX_FORCE_INLINE const PxTransform& getBody2World() const { return mCore.body2World; }
74 void setBody2World(const PxTransform& p);
75
76 PX_FORCE_INLINE const PxVec3& getLinearVelocity() const { return mCore.linearVelocity; }
77 void setLinearVelocity(const PxVec3& v, bool skipBodySimUpdate=false);
78
79 PX_FORCE_INLINE const PxVec3& getAngularVelocity() const { return mCore.angularVelocity; }
80 void setAngularVelocity(const PxVec3& v, bool skipBodySimUpdate=false);
81
82 PX_FORCE_INLINE PxReal getCfmScale() const { return mCore.cfmScale; }
83 void setCfmScale(PxReal d);
84
85 PX_FORCE_INLINE void updateVelocities(const PxVec3& linearVelModPerStep, const PxVec3& angularVelModPerStep)
86 {
87 mCore.linearVelocity += linearVelModPerStep;
88 mCore.angularVelocity += angularVelModPerStep;
89 }
90
91 PX_FORCE_INLINE const PxTransform& getBody2Actor() const { return mCore.getBody2Actor(); }
92 void setBody2Actor(const PxTransform& p);
93
94 void addSpatialAcceleration(PxPool<SimStateData>* simStateDataPool, const PxVec3* linAcc, const PxVec3* angAcc);
95 void setSpatialAcceleration(PxPool<SimStateData>* simStateDataPool, const PxVec3* linAcc, const PxVec3* angAcc);
96 void clearSpatialAcceleration(bool force, bool torque);
97 void addSpatialVelocity(PxPool<SimStateData>* simStateDataPool, const PxVec3* linVelDelta, const PxVec3* angVelDelta);
98 void clearSpatialVelocity(bool force, bool torque);
99
100 PX_FORCE_INLINE PxReal getMaxPenetrationBias() const { return mCore.maxPenBias; }
101 PX_FORCE_INLINE void setMaxPenetrationBias(PxReal p) { mCore.maxPenBias = p; }
102
103 PxReal getInverseMass() const;
104 void setInverseMass(PxReal m);
105 const PxVec3& getInverseInertia() const;
106 void setInverseInertia(const PxVec3& i);
107
108 PxReal getLinearDamping() const;
109 void setLinearDamping(PxReal d);
110
111 PxReal getAngularDamping() const;
112 void setAngularDamping(PxReal d);
113
114 PX_FORCE_INLINE PxRigidBodyFlags getFlags() const { return mCore.mFlags; }
115 void setFlags(PxPool<SimStateData>* simStateDataPool, PxRigidBodyFlags f);
116
117 PX_FORCE_INLINE PxRigidDynamicLockFlags getRigidDynamicLockFlags() const { return mCore.lockFlags; }
118
119 PX_FORCE_INLINE void setRigidDynamicLockFlags(PxRigidDynamicLockFlags flags) { mCore.lockFlags = flags; }
120
121 PX_FORCE_INLINE PxReal getSleepThreshold() const { return mCore.sleepThreshold; }
122 void setSleepThreshold(PxReal t);
123
124 PX_FORCE_INLINE PxReal getFreezeThreshold() const { return mCore.freezeThreshold; }
125 void setFreezeThreshold(PxReal t);
126
127 PX_FORCE_INLINE PxReal getMaxContactImpulse() const { return mCore.maxContactImpulse; }
128 void setMaxContactImpulse(PxReal m);
129
130 PX_FORCE_INLINE PxReal getOffsetSlop() const { return mCore.offsetSlop; }
131 void setOffsetSlop(PxReal slop);
132
133 PxNodeIndex getInternalIslandNodeIndex() const;
134
135 PX_FORCE_INLINE PxReal getWakeCounter() const { return mCore.wakeCounter; }
136 void setWakeCounter(PxReal wakeCounter, bool forceWakeUp=false);
137
138 bool isSleeping() const;
139 PX_FORCE_INLINE void wakeUp(PxReal wakeCounter) { setWakeCounter(wakeCounter, true); }
140 void putToSleep();
141
142 PxReal getMaxAngVelSq() const;
143 void setMaxAngVelSq(PxReal v);
144
145 PxReal getMaxLinVelSq() const;
146 void setMaxLinVelSq(PxReal v);
147
148 PX_FORCE_INLINE PxU16 getSolverIterationCounts() const { return mCore.solverIterationCounts; }
149 void setSolverIterationCounts(PxU16 c);
150
151 bool getKinematicTarget(PxTransform& p) const;
152 bool getHasValidKinematicTarget() const;
153 void setKinematicTarget(const PxTransform& p, PxReal wakeCounter);
154 void invalidateKinematicTarget();
155
156 PX_FORCE_INLINE PxReal getContactReportThreshold() const { return mCore.contactReportThreshold; }
157 void setContactReportThreshold(PxReal t) { mCore.contactReportThreshold = t; }
158
159 void onOriginShift(const PxVec3& shift);
160
161 //---------------------------------------------------------------------------------
162 // Internal API
163 //---------------------------------------------------------------------------------
164
165 PX_FORCE_INLINE void setLinearVelocityInternal(const PxVec3& v) { mCore.linearVelocity = v; }
166 PX_FORCE_INLINE void setAngularVelocityInternal(const PxVec3& v) { mCore.angularVelocity = v; }
167 PX_FORCE_INLINE void setWakeCounterFromSim(PxReal c) { mCore.wakeCounter = c; }
168
169 BodySim* getSim() const;
170
171 PX_FORCE_INLINE PxsBodyCore& getCore() { return mCore; }
172 PX_FORCE_INLINE const PxsBodyCore& getCore() const { return mCore; }
173 static PX_FORCE_INLINE size_t getCoreOffset() { return PX_OFFSET_OF_RT(BodyCore, mCore); }
174
175 PX_FORCE_INLINE PxReal getCCDAdvanceCoefficient() const { return mCore.ccdAdvanceCoefficient; }
176 PX_FORCE_INLINE void setCCDAdvanceCoefficient(PxReal c) { mCore.ccdAdvanceCoefficient = c; }
177
178 void onRemoveKinematicFromScene();
179
180 PxIntBool isFrozen() const;
181
182 static PX_FORCE_INLINE BodyCore& getCore(PxsBodyCore& core)
183 {
184 return *reinterpret_cast<BodyCore*>(reinterpret_cast<PxU8*>(&core) - getCoreOffset());
185 }
186
187 void setKinematicLink(const bool value);
188 private:
189 PX_ALIGN_PREFIX(16) PxsBodyCore mCore PX_ALIGN_SUFFIX(16);
190 };
191
192} // namespace Sc
193
194}
195
196#endif
PxNodeIndex.
Definition PxNodeIndex.h:51
Output stream class for I/O.
Definition PxIO.h:114
Definition PxPool.h:248
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
Definition ScBodyCore.h:49
Definition ScBodySim.h:60
Definition ScRigidCore.h:61
#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
PxEMPTY
Definition Px.h:87
Enum
Definition PxActor.h:121
Definition PxvDynamics.h:74