1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_SCB_ARTICULATION_JOINT
#define PX_PHYSICS_SCB_ARTICULATION_JOINT
#include "ScArticulationJointCore.h"
#include "ScbBody.h"
#include "ScbBase.h"
#include "ScbDefs.h"
namespace physx
{
namespace Scb
{
struct ArticulationJointBuffer
{
template <PxU32 I, PxU32 Dummy> struct Fns {};
typedef Sc::ArticulationJointCore Core;
typedef ArticulationJointBuffer Buf;
SCB_REGULAR_ATTRIBUTE(0, PxTransform, ParentPose)
SCB_REGULAR_ATTRIBUTE(1, PxTransform, ChildPose)
SCB_REGULAR_ATTRIBUTE(2, PxQuat, TargetOrientation)
SCB_REGULAR_ATTRIBUTE(3, PxVec3, TargetVelocity)
SCB_REGULAR_ATTRIBUTE(4, PxReal, Stiffness)
SCB_REGULAR_ATTRIBUTE(5, PxReal, Damping)
SCB_REGULAR_ATTRIBUTE(6, PxReal, InternalCompliance)
SCB_REGULAR_ATTRIBUTE(7, PxReal, ExternalCompliance)
SCB_REGULAR_ATTRIBUTE(8, PxReal, SwingLimitContactDistance)
SCB_REGULAR_ATTRIBUTE(9, bool, SwingLimitEnabled)
SCB_REGULAR_ATTRIBUTE(10, PxReal, TangentialStiffness)
SCB_REGULAR_ATTRIBUTE(11, PxReal, TangentialDamping)
SCB_REGULAR_ATTRIBUTE(12, PxReal, TwistLimitContactDistance)
SCB_REGULAR_ATTRIBUTE(13, bool, TwistLimitEnabled)
SCB_REGULAR_ATTRIBUTE(14, PxArticulationJointDriveType::Enum, DriveType)
enum { BF_SwingLimit = 1<<15 };
enum { BF_TwistLimit = 1<<16 };
PxReal mSwingLimitY;
PxReal mSwingLimitZ;
PxReal mTwistLimitLower;
PxReal mTwistLimitUpper;
};
class ArticulationJoint : public Base
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format. See comments for
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
typedef ArticulationJointBuffer Buf;
typedef Sc::ArticulationJointCore Core;
public:
// PX_SERIALIZATION
ArticulationJoint(const PxEMPTY) : Base(PxEmpty), mJoint(PxEmpty) {}
static void getBinaryMetaData(PxOutputStream& stream);
//~PX_SERIALIZATION
PX_INLINE ArticulationJoint(const PxTransform& parentFrame,
const PxTransform& childFrame);
PX_INLINE ~ArticulationJoint();
//---------------------------------------------------------------------------------
// Wrapper for Sc::ArticulationJoint interface
//---------------------------------------------------------------------------------
PX_INLINE PxTransform getParentPose() const { return read<Buf::BF_ParentPose>(); }
PX_INLINE void setParentPose(const PxTransform& v) { write<Buf::BF_ParentPose>(v); }
PX_INLINE PxTransform getChildPose() const { return read<Buf::BF_ChildPose>(); }
PX_INLINE void setChildPose(const PxTransform& v) { write<Buf::BF_ChildPose>(v); }
PX_INLINE PxQuat getTargetOrientation() const { return read<Buf::BF_TargetOrientation>(); }
PX_INLINE void setTargetOrientation(const PxQuat& v) { write<Buf::BF_TargetOrientation>(v); }
PX_INLINE PxVec3 getTargetVelocity() const { return read<Buf::BF_TargetVelocity>(); }
PX_INLINE void setTargetVelocity(const PxVec3& v) { write<Buf::BF_TargetVelocity>(v); }
PX_INLINE PxReal getStiffness() const { return read<Buf::BF_Stiffness>(); }
PX_INLINE void setStiffness(PxReal v) { write<Buf::BF_Stiffness>(v); }
PX_INLINE PxReal getDamping() const { return read<Buf::BF_Damping>(); }
PX_INLINE void setDamping(PxReal v) { write<Buf::BF_Damping>(v); }
PX_INLINE PxReal getInternalCompliance() const { return read<Buf::BF_InternalCompliance>(); }
PX_INLINE void setInternalCompliance(PxReal v) { write<Buf::BF_InternalCompliance>(v); }
PX_INLINE PxReal getExternalCompliance() const { return read<Buf::BF_ExternalCompliance>(); }
PX_INLINE void setExternalCompliance(PxReal v) { write<Buf::BF_ExternalCompliance>(v); }
PX_INLINE PxReal getTangentialStiffness() const { return read<Buf::BF_TangentialStiffness>(); }
PX_INLINE void setTangentialStiffness(PxReal v) { write<Buf::BF_TangentialStiffness>(v); }
PX_INLINE PxReal getTangentialDamping() const { return read<Buf::BF_TangentialDamping>(); }
PX_INLINE void setTangentialDamping(PxReal v) { write<Buf::BF_TangentialDamping>(v); }
PX_INLINE PxReal getSwingLimitContactDistance() const { return read<Buf::BF_SwingLimitContactDistance>(); }
PX_INLINE void setSwingLimitContactDistance(PxReal v) { write<Buf::BF_SwingLimitContactDistance>(v); }
PX_INLINE PxReal getTwistLimitContactDistance() const { return read<Buf::BF_TwistLimitContactDistance>(); }
PX_INLINE void setTwistLimitContactDistance(PxReal v) { write<Buf::BF_TwistLimitContactDistance>(v); }
PX_INLINE PxArticulationJointDriveType::Enum
getDriveType() const { return read<Buf::BF_DriveType>(); }
PX_INLINE void setDriveType(PxArticulationJointDriveType::Enum v)
{ write<Buf::BF_DriveType>(v); }
PX_INLINE bool getSwingLimitEnabled() const { return read<Buf::BF_SwingLimitEnabled>(); }
PX_INLINE void setSwingLimitEnabled(bool v) { write<Buf::BF_SwingLimitEnabled>(v); }
PX_INLINE bool getTwistLimitEnabled() const { return read<Buf::BF_TwistLimitEnabled>(); }
PX_INLINE void setTwistLimitEnabled(bool v) { write<Buf::BF_TwistLimitEnabled>(v); }
PX_INLINE void getSwingLimit(PxReal& yLimit, PxReal& zLimit) const;
PX_INLINE void setSwingLimit(PxReal yLimit, PxReal zLimit);
PX_INLINE void getTwistLimit(PxReal &lower, PxReal &upper) const;
PX_INLINE void setTwistLimit(PxReal lower, PxReal upper);
//---------------------------------------------------------------------------------
// Data synchronization
//---------------------------------------------------------------------------------
PX_INLINE void syncState();
PX_FORCE_INLINE const Core& getScArticulationJoint() const { return mJoint; } // Only use if you know what you're doing!
PX_FORCE_INLINE Core& getScArticulationJoint() { return mJoint; } // Only use if you know what you're doing!
private:
Core mJoint;
PX_FORCE_INLINE const Buf* getBuffer() const { return reinterpret_cast<const Buf*>(getStream()); }
PX_FORCE_INLINE Buf* getBuffer() { return reinterpret_cast<Buf*>(getStream()); }
//---------------------------------------------------------------------------------
// Infrastructure for regular attributes
//---------------------------------------------------------------------------------
struct Access: public BufferedAccess<Buf, Core, ArticulationJoint> {};
template<PxU32 f> PX_FORCE_INLINE typename Buf::Fns<f,0>::Arg read() const { return Access::read<Buf::Fns<f,0> >(*this, mJoint); }
template<PxU32 f> PX_FORCE_INLINE void write(typename Buf::Fns<f,0>::Arg v) { Access::write<Buf::Fns<f,0> >(*this, mJoint, v); }
template<PxU32 f> PX_FORCE_INLINE void flush(const Buf& buf) { Access::flush<Buf::Fns<f,0> >(*this, mJoint, buf); }
};
ArticulationJoint::ArticulationJoint(const PxTransform& parentFrame, const PxTransform& childFrame) :
mJoint(parentFrame, childFrame)
{
setScbType(ScbType::eARTICULATION_JOINT);
}
ArticulationJoint::~ArticulationJoint()
{
}
PX_INLINE void ArticulationJoint::getSwingLimit(PxReal &yLimit, PxReal &zLimit) const
{
if(isBuffered(Buf::BF_SwingLimit))
{
yLimit = getBuffer()->mSwingLimitY;
zLimit = getBuffer()->mSwingLimitZ;
}
else
mJoint.getSwingLimit(yLimit, zLimit);
}
PX_INLINE void ArticulationJoint::setSwingLimit(PxReal yLimit, PxReal zLimit)
{
if(!isBuffering())
mJoint.setSwingLimit(yLimit, zLimit);
else
{
getBuffer()->mSwingLimitY = yLimit;
getBuffer()->mSwingLimitZ = zLimit;
markUpdated(Buf::BF_SwingLimit);
}
}
PX_INLINE void ArticulationJoint::getTwistLimit(PxReal &lower, PxReal &upper) const
{
if(isBuffered(Buf::BF_TwistLimit))
{
lower = getBuffer()->mTwistLimitLower;
upper = getBuffer()->mTwistLimitUpper;
}
else
mJoint.getTwistLimit(lower, upper);
}
PX_INLINE void ArticulationJoint::setTwistLimit(PxReal lower, PxReal upper)
{
if(!isBuffering())
mJoint.setTwistLimit(lower, upper);
else
{
getBuffer()->mTwistLimitLower = lower;
getBuffer()->mTwistLimitUpper = upper;
markUpdated(Buf::BF_TwistLimit);
}
}
//--------------------------------------------------------------
//
// Data synchronization
//
//--------------------------------------------------------------
PX_INLINE void ArticulationJoint::syncState()
{
const PxU32 flags = getBufferFlags();
if(flags) // Optimization to avoid all the if-statements below if possible
{
const Buf& buffer = *getBuffer();
flush<Buf::BF_ParentPose>(buffer);
flush<Buf::BF_ChildPose>(buffer);
flush<Buf::BF_TargetOrientation>(buffer);
flush<Buf::BF_TargetVelocity>(buffer);
flush<Buf::BF_Stiffness>(buffer);
flush<Buf::BF_Damping>(buffer);
flush<Buf::BF_InternalCompliance>(buffer);
flush<Buf::BF_ExternalCompliance>(buffer);
flush<Buf::BF_SwingLimitContactDistance>(buffer);
flush<Buf::BF_SwingLimitEnabled>(buffer);
flush<Buf::BF_TwistLimitContactDistance>(buffer);
flush<Buf::BF_TwistLimitEnabled>(buffer);
flush<Buf::BF_TangentialStiffness>(buffer);
flush<Buf::BF_TangentialDamping>(buffer);
flush<Buf::BF_DriveType>(buffer);
if(isBuffered(Buf::BF_SwingLimit))
mJoint.setSwingLimit(buffer.mSwingLimitY, buffer.mSwingLimitZ);
if(isBuffered(Buf::BF_TwistLimit))
mJoint.setTwistLimit(buffer.mTwistLimitLower, buffer.mTwistLimitUpper);
}
postSyncState();
}
} // namespace Scb
}
#endif
|