RavEngine
Loading...
Searching...
No Matches
DyArticulationJointCore.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 DV_ARTICULATION_JOINT_CORE_H
30#define DV_ARTICULATION_JOINT_CORE_H
31
32#include "DyArticulationCore.h"
33#include "solver/PxSolverDefs.h"
34#include "PxArticulationJointReducedCoordinate.h"
35
36namespace physx
37{
38 namespace Dy
39 {
40 class ArticulationJointCoreData;
41
42 PX_ALIGN_PREFIX(16)
44 {
45 //= ATTENTION! =====================================================================================
46 // Changing the data layout of this class breaks the binary serialization format. See comments for
47 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
48 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
49 // accordingly.
50 //==================================================================================================
51 public:
52
53 // PX_SERIALIZATION
54 ArticulationJointCore(const PxEMPTY&) : jointDirtyFlag(PxEmpty)
55 {
56 PX_COMPILE_TIME_ASSERT(sizeof(PxArticulationMotions) == sizeof(PxU8));
57 }
58 //~PX_SERIALIZATION
59
60 ArticulationJointCore(const PxTransform& parentFrame, const PxTransform& childFrame)
61 {
62 //PxMarkSerializedMemory(this, sizeof(ArticulationJointCore));
63 init(parentFrame, childFrame);
64 }
65
66 // PT: these ones don't update the dirty flags
67 PX_FORCE_INLINE void initLimit(PxArticulationAxis::Enum axis, const PxArticulationLimit& limit) { limits[axis] = limit; }
68 PX_FORCE_INLINE void initDrive(PxArticulationAxis::Enum axis, const PxArticulationDrive& drive) { drives[axis] = drive; }
69 PX_FORCE_INLINE void initJointType(PxArticulationJointType::Enum type) { jointType = PxU8(type); }
70 PX_FORCE_INLINE void initMaxJointVelocity(const PxReal maxJointV) { maxJointVelocity = maxJointV; }
71 PX_FORCE_INLINE void initFrictionCoefficient(const PxReal coefficient) { frictionCoefficient = coefficient; }
72
73 void init(const PxTransform& parentFrame, const PxTransform& childFrame)
74 {
75 PX_ASSERT(parentFrame.isValid());
76 PX_ASSERT(childFrame.isValid());
77
78 parentPose = parentFrame;
79 childPose = childFrame;
80 jointOffset = 0;
81 // PT: TODO: don't we need ArticulationJointCoreDirtyFlag::eFRAME here?
82 jointDirtyFlag = ArticulationJointCoreDirtyFlag::eMOTION;
83
84 initFrictionCoefficient(0.05f);
85 initMaxJointVelocity(100.0f);
86 initJointType(PxArticulationJointType::eUNDEFINED);
87
88 for(PxU32 i=0; i<PxArticulationAxis::eCOUNT; i++)
89 {
90 initLimit(PxArticulationAxis::Enum(i), PxArticulationLimit(0.0f, 0.0f));
91 initDrive(PxArticulationAxis::Enum(i), PxArticulationDrive(0.0f, 0.0f, 0.0f, PxArticulationDriveType::eNONE));
92
93 targetP[i] = 0.0f;
94 targetV[i] = 0.0f;
95 armature[i] = 0.0f;
96 jointPos[i] = 0.0f;
97 jointVel[i] = 0.0f;
98
99 dofIds[i] = 0xff;
100 invDofIds[i] = 0xff;
102 }
103 }
104
105 PX_CUDA_CALLABLE bool setJointFrame(PxQuat& relativeQuat)
106 {
107 if (jointDirtyFlag & ArticulationJointCoreDirtyFlag::eFRAME)
108 {
109 relativeQuat = (childPose.q * (parentPose.q.getConjugate())).getNormalized();
110
111 //ML: this way work in GPU
112 PxU8 flag = PxU8(ArticulationJointCoreDirtyFlag::eFRAME);
113 jointDirtyFlag &= ArticulationJointCoreDirtyFlags(~flag);
114
115 return true;
116 }
117
118 return false;
119 }
120
121 PX_CUDA_CALLABLE PX_FORCE_INLINE void operator=(ArticulationJointCore& other)
122 {
123 parentPose = other.parentPose;
124 childPose = other.childPose;
125
126 //KS - temp place to put reduced coordinate limit and drive values
127 for(PxU32 i=0; i<PxArticulationAxis::eCOUNT; i++)
128 {
129 limits[i] = other.limits[i];
130 drives[i] = other.drives[i];
131 targetP[i] = other.targetP[i];
132 targetV[i] = other.targetV[i];
133 armature[i] = other.armature[i];
134
135 jointPos[i] = other.jointPos[i];
136 jointVel[i] = other.jointVel[i];
137
138 dofIds[i] = other.dofIds[i];
139 invDofIds[i] = other.invDofIds[i];
140 motion[i] = other.motion[i];
141 }
142
143 frictionCoefficient = other.frictionCoefficient;
144 maxJointVelocity = other.maxJointVelocity;
145 jointOffset = other.jointOffset;
146 jointDirtyFlag = other.jointDirtyFlag;
147 jointType = other.jointType;
148 }
149
150 //Implementation is in DyFeatherstoneArticulation.cpp
151 void setJointFrame( ArticulationJointCoreData& jointDatum, Cm::UnAlignedSpatialVector* motionMatrix,
152 const Cm::UnAlignedSpatialVector* jointAxis, bool forceUpdate, PxQuat& relativeRot);
153
154 PX_FORCE_INLINE void setParentPose(const PxTransform& t) { parentPose = t; jointDirtyFlag |= ArticulationJointCoreDirtyFlag::eFRAME; }
155 PX_FORCE_INLINE void setChildPose(const PxTransform& t) { childPose = t; jointDirtyFlag |= ArticulationJointCoreDirtyFlag::eFRAME; }
156 PX_FORCE_INLINE void setMotion(PxArticulationAxis::Enum axis, PxArticulationMotion::Enum m) { motion[axis] = PxU8(m); jointDirtyFlag |= Dy::ArticulationJointCoreDirtyFlag::eMOTION; }
157 PX_FORCE_INLINE void setTargetP(PxArticulationAxis::Enum axis, PxReal value) { targetP[axis] = value; jointDirtyFlag |= Dy::ArticulationJointCoreDirtyFlag::eTARGETPOSE; }
158 PX_FORCE_INLINE void setTargetV(PxArticulationAxis::Enum axis, PxReal value) { targetV[axis] = value; jointDirtyFlag |= Dy::ArticulationJointCoreDirtyFlag::eTARGETVELOCITY; }
159 PX_FORCE_INLINE void setArmature(PxArticulationAxis::Enum axis, PxReal value) { armature[axis] = value; jointDirtyFlag |= Dy::ArticulationJointCoreDirtyFlag::eARMATURE; }
160
161 // attachment points, don't change the order, otherwise it will break GPU code
162 PxTransform parentPose; //28 28
163 PxTransform childPose; //28 56
164
165 //KS - temp place to put reduced coordinate limit and drive values
166 PxArticulationLimit limits[PxArticulationAxis::eCOUNT]; //48 104
167 PxArticulationDrive drives[PxArticulationAxis::eCOUNT]; //96 200
168 PxReal targetP[PxArticulationAxis::eCOUNT]; //24 224
169 PxReal targetV[PxArticulationAxis::eCOUNT]; //24 248
170 PxReal armature[PxArticulationAxis::eCOUNT]; //24 272
171
172 PxReal jointPos[PxArticulationAxis::eCOUNT]; //24 296
173 PxReal jointVel[PxArticulationAxis::eCOUNT]; //24 320
174
175 PxReal frictionCoefficient; //4 324
176 PxReal maxJointVelocity; //4 328
177
178 //this is the dof offset for the joint in the cache.
179 PxU32 jointOffset; //4 332
180
181 PxU8 dofIds[PxArticulationAxis::eCOUNT]; //6 338
182 PxU8 motion[PxArticulationAxis::eCOUNT]; //6 344
183 PxU8 invDofIds[PxArticulationAxis::eCOUNT]; //6 350
184
185 ArticulationJointCoreDirtyFlags jointDirtyFlag; //1 351
186 PxU8 jointType; //1 352
187 }PX_ALIGN_SUFFIX(16);
188 }
189}
190
191#endif
Definition DyFeatherstoneArticulationJointData.h:50
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
PX_CUDA_CALLABLE bool isValid() const
returns true if finite and q is a unit quaternion
Definition PxTransform.h:148
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
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 CmSpatialVector.h:310
Definition DyArticulationJointCore.h:44
Enum
Definition PxSolverDefs.h:252
Data structure for articulation joint drive configuration.
Definition PxSolverDefs.h:359
Enum
Definition PxSolverDefs.h:281
Data structure to set articulation joint limits.
Definition PxSolverDefs.h:327
Enum
Definition PxSolverDefs.h:268
@ eLOCKED
Locked axis, i.e. degree of freedom (DOF)
Definition PxSolverDefs.h:269