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 PX_PHYSICS_SCP_ARTICULATION_JOINT_CORE
32#define PX_PHYSICS_SCP_ARTICULATION_JOINT_CORE
33
34#include "foundation/PxTransform.h"
35#include "common/PxMetaData.h"
36#include "CmPhysXCommon.h"
37#include "PsUserAllocated.h"
38#include "DyArticulation.h"
39
40namespace physx
41{
42namespace Sc
43{
44 class BodyCore;
45 class ArticulationJointSim;
46 class ArticulationCore;
47
48 class ArticulationJointDesc
49 {
50 public:
51 BodyCore* parent;
52 BodyCore* child;
53 PxTransform parentPose;
54 PxTransform childPose;
55 };
56
57 class ArticulationJointCore : public Ps::UserAllocated
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 ArticulationJointCore(const PxEMPTY) : mSim(NULL), mCore(PxEmpty) {}
72 void preExportDataReset() { mCore.dirtyFlag = Dy::ArticulationJointCoreDirtyFlag::eALL; }
73 static void getBinaryMetaData(PxOutputStream& stream);
74//~PX_SERIALIZATION
75 ArticulationJointCore( const PxTransform& parentFrame, const PxTransform& childFrame, bool reducedCoordinate);
76 ~ArticulationJointCore();
77
78 //---------------------------------------------------------------------------------
79 // External API
80 //---------------------------------------------------------------------------------
81
82 PX_FORCE_INLINE const PxTransform& getParentPose() const { return mCore.parentPose; }
83 void setParentPose(const PxTransform&);
84
85 PX_FORCE_INLINE const PxTransform& getChildPose() const { return mCore.childPose; }
86 void setChildPose(const PxTransform&);
87
88 PX_FORCE_INLINE const PxQuat& getTargetOrientation() const { return mCore.targetPosition; }
89 void setTargetOrientation(const PxQuat&);
90
91 PX_FORCE_INLINE const PxVec3& getTargetVelocity() const { return mCore.targetVelocity; }
92 void setTargetVelocity(const PxVec3&);
93
94 PX_FORCE_INLINE PxReal getStiffness() const { return mCore.spring; }
95 void setStiffness(PxReal);
96
97 PX_FORCE_INLINE PxReal getDamping() const { return mCore.damping; }
98 void setDamping(PxReal);
99
100 PX_FORCE_INLINE PxReal getInternalCompliance() const { return mCore.internalCompliance; }
101 void setInternalCompliance(PxReal);
102
103 PX_FORCE_INLINE PxReal getExternalCompliance() const { return mCore.externalCompliance; }
104 void setExternalCompliance(PxReal);
105
106 PX_FORCE_INLINE void getSwingLimit(PxReal& yLimit, PxReal& zLimit) const { yLimit = mCore.limits[PxArticulationAxis::eSWING1].low; zLimit = mCore.limits[PxArticulationAxis::eSWING2].low; }
107 void setSwingLimit(PxReal yLimit, PxReal zLimit);
108
109 PX_FORCE_INLINE PxReal getTangentialStiffness() const { return mCore.tangentialStiffness; }
110 void setTangentialStiffness(PxReal);
111
112 PX_FORCE_INLINE PxReal getTangentialDamping() const { return mCore.tangentialDamping; }
113 void setTangentialDamping(PxReal);
114
115 PX_FORCE_INLINE bool getSwingLimitEnabled() const { return mCore.swingLimited; }
116 void setSwingLimitEnabled(bool);
117
118 PX_FORCE_INLINE PxReal getSwingLimitContactDistance() const { return mCore.swingLimitContactDistance; }
119 void setSwingLimitContactDistance(PxReal);
120
121 PX_FORCE_INLINE void getTwistLimit(PxReal& lower, PxReal& upper) const { lower = mCore.limits[PxArticulationAxis::eTWIST].low; upper = mCore.limits[PxArticulationAxis::eTWIST].high; }
122 void setTwistLimit(PxReal lower, PxReal upper);
123
124 void getLimit(PxArticulationAxis::Enum axis, PxReal& lower, PxReal& upper) const
125 {
126 lower = mCore.limits[axis].low;
127 upper = mCore.limits[axis].high;
128 }
129
130 void setLimit(PxArticulationAxis::Enum axis, PxReal lower, PxReal upper);
131
132 void getDrive(PxArticulationAxis::Enum axis, PxReal& stiffness, PxReal& damping, PxReal& maxForce, PxArticulationDriveType::Enum& driveType) const
133 {
134 stiffness = mCore.drives[axis].stiffness;
135 damping = mCore.drives[axis].damping;
136 maxForce = mCore.drives[axis].maxForce;
137 driveType = mCore.drives[axis].driveType;
138 }
139
140 void setDrive(PxArticulationAxis::Enum axis, PxReal stiffness, PxReal damping, PxReal maxForce, PxArticulationDriveType::Enum driveType);
141
142 void setTargetP(PxArticulationAxis::Enum axis, PxReal targetP);
143 PX_FORCE_INLINE PxReal getTargetP(PxArticulationAxis::Enum axis) const { return mCore.targetP[axis]; }
144
145 void setTargetV(PxArticulationAxis::Enum axis, PxReal targetV);
146 PX_FORCE_INLINE PxReal getTargetV(PxArticulationAxis::Enum axis) const { return mCore.targetV[axis]; }
147
148 PX_FORCE_INLINE bool getTwistLimitEnabled() const { return mCore.twistLimited; }
149 void setTwistLimitEnabled(bool);
150
151 PX_FORCE_INLINE PxReal getTwistLimitContactDistance() const { return mCore.twistLimitContactDistance; }
152 void setTwistLimitContactDistance(PxReal);
153
154 void setDriveType(PxArticulationJointDriveType::Enum type);
155 PxArticulationJointDriveType::Enum getDriveType() const { return PxArticulationJointDriveType::Enum(mCore.driveType); }
156
157 void setJointType(PxArticulationJointType::Enum type);
158 PxArticulationJointType::Enum getJointType() const;
159
160 void setMotion(PxArticulationAxis::Enum axis, PxArticulationMotion::Enum motion);
161 PxArticulationMotion::Enum getMotion(PxArticulationAxis::Enum axis) const;
162
163 void setFrictionCoefficient(const PxReal coefficient);
164 PxReal getFrictionCoefficient() const;
165
166 void setMaxJointVelocity(const PxReal maxJointV);
167 PxReal getMaxJointVelocity() const;
168
169 PxArticulationJointBase* getPxArticulationJointBase();
170 const PxArticulationJointBase* getPxArticulationJointBase() const;
171
172 //---------------------------------------------------------------------------------
173 // Low Level data access - some wouldn't be needed if the interface wasn't virtual
174 //---------------------------------------------------------------------------------
175
176 PX_FORCE_INLINE ArticulationJointSim* getSim() const { return mSim; }
177 PX_FORCE_INLINE void setSim(ArticulationJointSim* sim)
178 {
179 PX_ASSERT((sim==0) ^ (mSim == 0));
180 mSim = sim;
181 }
182
183 PX_FORCE_INLINE Dy::ArticulationJointCore& getCore() { return mCore; }
184
185 PX_FORCE_INLINE void setArticulation(ArticulationCore* articulation) { mArticulation = articulation; }
186 PX_FORCE_INLINE const ArticulationCore* getArticulation() const { return mArticulation; }
187
188 PX_FORCE_INLINE void setRoot(PxArticulationJointBase* base) { mRootType = base; }
189 PX_FORCE_INLINE PxArticulationJointBase* getRoot() const { return mRootType; }
190
191 private:
192
193 void setDirty(Dy::ArticulationJointCoreDirtyFlag::Enum dirtyFlag);
194 ArticulationJointSim* mSim;
195 Dy::ArticulationJointCore mCore;
196 ArticulationCore* mArticulation;
197 PxArticulationJointBase* mRootType;
198 };
199
200} // namespace Sc
201
202}
203
204#endif
205

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