RavEngine
Loading...
Searching...
No Matches
ScArticulationCore.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_ARTICULATION_CORE_H
30#define SC_ARTICULATION_CORE_H
31
32#include "ScActorCore.h"
33#include "DyFeatherstoneArticulation.h"
34
35namespace physx
36{
37
38class PxvArticulation;
39
40class PxNodeIndex;
41
42namespace Sc
43{
44 //typedef Dy::FsData ArticulationDriveCache;
45
46 class ArticulationSim;
47 class BodyCore;
48 class BodySim;
49 class ArticulationJointCore;
50
52 {
53 //= ATTENTION! =====================================================================================
54 // Changing the data layout of this class breaks the binary serialization format. See comments for
55 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
56 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
57 // accordingly.
58 //==================================================================================================
59
60 //---------------------------------------------------------------------------------
61 // Construction, destruction & initialization
62 //---------------------------------------------------------------------------------
63
64// PX_SERIALIZATION
65 public:
66 ArticulationCore(const PxEMPTY) : mSim(NULL), mCore(PxEmpty) {}
67 static void getBinaryMetaData(PxOutputStream& stream);
68//~PX_SERIALIZATION
71
72 //---------------------------------------------------------------------------------
73 // External API
74 //---------------------------------------------------------------------------------
75 PX_FORCE_INLINE PxReal getSleepThreshold() const { return mCore.sleepThreshold; }
76 PX_FORCE_INLINE void setSleepThreshold(const PxReal v) { mCore.sleepThreshold = v; }
77
78 PX_FORCE_INLINE PxReal getFreezeThreshold() const { return mCore.freezeThreshold; }
79 PX_FORCE_INLINE void setFreezeThreshold(const PxReal v) { mCore.freezeThreshold = v; }
80
81 PX_FORCE_INLINE PxU16 getSolverIterationCounts() const { return mCore.solverIterationCounts; }
82 PX_FORCE_INLINE void setSolverIterationCounts(PxU16 c) { mCore.solverIterationCounts = c; }
83
84 PX_FORCE_INLINE PxReal getWakeCounter() const { return mCore.wakeCounter; }
85 PX_FORCE_INLINE void setWakeCounterInternal(const PxReal v) { mCore.wakeCounter = v; }
86 void setWakeCounter(const PxReal v);
87
88 PX_FORCE_INLINE PxReal getMaxLinearVelocity() const { return mCore.maxLinearVelocity; }
89 void setMaxLinearVelocity(const PxReal max);
90
91 PX_FORCE_INLINE PxReal getMaxAngularVelocity() const { return mCore.maxAngularVelocity; }
92 void setMaxAngularVelocity(const PxReal max);
93
94 bool isSleeping() const;
95 void wakeUp(PxReal wakeCounter);
96 void putToSleep();
97
98 //---------------------------------------------------------------------------------
99 // external reduced coordinate API
100 //---------------------------------------------------------------------------------
101 void setArticulationFlags(PxArticulationFlags flags);
102 PxArticulationFlags getArticulationFlags() const { return mCore.flags; }
103
104 PxU32 getDofs() const;
105
106 PxArticulationCache* createCache() const;
107
108 PxU32 getCacheDataSize() const;
109
110 void zeroCache(PxArticulationCache& cache) const;
111
112 bool applyCache(PxArticulationCache& cache, const PxArticulationCacheFlags flag)const;
113
114 void copyInternalStateToCache(PxArticulationCache& cache, const PxArticulationCacheFlags flag) const;
115
116 void packJointData(const PxReal* maximum, PxReal* reduced) const;
117
118 void unpackJointData(const PxReal* reduced, PxReal* maximum) const;
119
120 void commonInit() const;
121
122 void computeGeneralizedGravityForce(PxArticulationCache& cache) const;
123
124 void computeCoriolisAndCentrifugalForce(PxArticulationCache& cache) const;
125
126 void computeGeneralizedExternalForce(PxArticulationCache& cache) const;
127
128 void computeJointAcceleration(PxArticulationCache& cache) const;
129
130 void computeJointForce(PxArticulationCache& cache) const;
131
132
133 void computeDenseJacobian(PxArticulationCache& cache, PxU32& nRows, PxU32& nCols) const;
134
135 void computeCoefficientMatrix(PxArticulationCache& cache) const;
136
137 bool computeLambda(PxArticulationCache& cache, PxArticulationCache& rollBackCache, const PxReal* const jointTorque, const PxVec3 gravity, const PxU32 maxIter) const;
138
139 void computeGeneralizedMassMatrix(PxArticulationCache& cache) const;
140
141 PxU32 getCoefficientMatrixSize() const;
142
143 PxSpatialVelocity getLinkAcceleration(const PxU32 linkId) const;
144
145 PxU32 getGpuArticulationIndex() const;
146
147 void updateKinematic(PxArticulationKinematicFlags flags);
148 //---------------------------------------------------------------------------------
149 // Internal API
150 //---------------------------------------------------------------------------------
151 public:
152 PX_FORCE_INLINE void setSim(ArticulationSim* sim)
153 {
154 PX_ASSERT((sim==0) ^ (mSim == 0));
155 mSim = sim;
156 }
157 PX_FORCE_INLINE ArticulationSim* getSim() const { return mSim; }
158
159 PX_FORCE_INLINE Dy::ArticulationCore& getCore() { return mCore; }
160
161 static PX_FORCE_INLINE ArticulationCore& getArticulationCore(ArticulationCore& core)
162 {
163 const size_t offset = PX_OFFSET_OF(ArticulationCore, mCore);
164 return *reinterpret_cast<ArticulationCore*>(reinterpret_cast<PxU8*>(&core) - offset);
165 }
166
167 PxNodeIndex getIslandNodeIndex() const;
168
169 void setGlobalPose();
170
171 private:
172 ArticulationSim* mSim;
174 };
175
176} // namespace Sc
177
178}
179
180#endif
Data structure used to read and write internal articulation data.
Definition PxArticulationReducedCoordinate.h:99
PxNodeIndex.
Definition PxNodeIndex.h:51
Output stream class for I/O.
Definition PxIO.h:114
3 Element vector class.
Definition PxVec3.h:50
Definition ScArticulationCore.h:52
Definition ScArticulationSim.h:68
#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
Definition DyArticulationCore.h:39
Data structure to represent spatial velocities.
Definition PxArticulationReducedCoordinate.h:66