Atoms Crowd  7.0.0
RigidBodyConstraint.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 #ifndef ATOMS_UNREAL
10 #include <Atoms/Globals.h>
11 #include <AtomsCore/AtomsMath.h>
12 #include <AtomsCore/Metadata/MapMetadata.h>
13 #include <limits>
14 
15 namespace physx
16 {
17  class PxJoint;
18 }
19 
20 namespace Atoms
21 {
22  class ATOMS_EXPORT RigidBodyConstraintAttributes
23  {
24  public:
25 
26  struct Type
27  {
28  enum Enum
29  {
30  kFixed = 0,
31  kDistance,
32  kSpherical,
33  kRevolute,
34  kPrismatic,
35  kD6
36  };
37  };
38 
39  struct D6Drive
40  {
41  enum Enum
42  {
43  kX = 0,
44  kY = 1,
45  kZ = 2,
46  kSWING = 3,
47  kTWIST = 4,
48  kSLERP = 5,
49  kCOUNT = 6
50  };
51  };
52 
53  struct D6Axis
54  {
55  enum Enum
56  {
57  kX = 0,
58  kY = 1,
59  kZ = 2,
60  kTWIST = 3,
61  kSWING1 = 4,
62  kSWING2 = 5,
63  kCOUNT = 6
64  };
65  };
66 
67  struct D6Motion
68  {
69  enum Enum
70  {
73  kFREE
74  };
75  };
76 
77  class Drive
78  {
79  public:
80  Drive():
81  stiffness(0.0f),
82  damping(0.0f),
83  restitution(0.0f),
84  bounceThreshold(0.5f),
85  forceLimit(std::numeric_limits<float>::max()),
86  isAcceleration(false),
87  enable(false)
88  {}
89  float stiffness;
90  float damping;
91  float restitution;
92  float bounceThreshold;
93  float forceLimit;
94  bool isAcceleration;
95  bool enable;
96  };
97 
99 
101 
102  public:
103 
105  bool serialise(std::string& outStream) const;
106 
108  bool deserialise(const std::string& inStream);
109 
111  bool serialise(AtomsCore::MapMetadata* outStream) const;
112 
114  bool deserialise(const AtomsCore::MapMetadata* inStream);
115 
116  public:
117 
118  static const size_t version;
119 
120  public:
121 
122  std::string name;
123 
124  short constraintType;
125 
126  // Flags
127  bool enableCollision;
128  bool driveLimitsAreForces;
129  bool improveSlerp;
130  bool disablePreprocessing;
131  bool enableExtendedLimits;
132 
133  //Projection
134  bool enableProjection;
135  float projectionLinearTollerance;
136  float projectionAngularTollerance;
137 
138  // limit spring
139  bool enableSpring;
140  float stiffness;
141  float damping;
142  float restitution;
143  float bounceThreshold;
144 
145  // limits
146  bool enableLimit;
147  AtomsCore::Vector3f limit;
148 
149  // breakable
150  bool breakable;
151  AtomsCore::Vector2f breakForce;
152 
153  // Distant joint
154  bool enableMinDistance;
155  float minDistance;
156  bool enableMaxDistance;
157  float maxDistance;
158  float tollerance;
159 
160  // Revolute
161  bool enableDrive;
162  bool enableFreeSpin;
163  float driveVelocity;
164  float driveForceLimit;
165  float driveGearRatio;
166 
167  // D6
168  short linearMotionX;
169  short linearMotionY;
170  short linearMotionZ;
171 
172  short angularMotionX;
173  short angularMotionY;
174  short angularMotionZ;
175 
176  bool enableDistanceLimit;
177  bool enableTwistLimit;
178  bool enableSwingLimit;
179  bool enablePyramidLimit;
180  AtomsCore::Vector2f distanceLimit;
181  AtomsCore::Vector3f twistLimit;
182  AtomsCore::Vector3f swingLimit;
183  AtomsCore::Vector3f pyramidYSwingLimit;
184  AtomsCore::Vector3f pyramidZSwingLimit;
185 
186  bool enableLinearXLimit;
187  bool enableLinearYLimit;
188  bool enableLinearZLimit;
189  AtomsCore::Vector3f linearXlimit;
190  AtomsCore::Vector3f linearYlimit;
191  AtomsCore::Vector3f linearZlimit;
192 
193  bool enableXLimitSpring;
194  bool enableYLimitSpring;
195  bool enableZLimitSpring;
196  float xLimitStiffnessSpring;
197  float xLimitDampingSpring;
198  float xLimitRestitutionSpring;
199  float xLimitBounceThresholdSpring;
200  float yLimitStiffnessSpring;
201  float yLimitDampingSpring;
202  float yLimitRestitutionSpring;
203  float yLimitBounceThresholdSpring;
204  float zLimitStiffnessSpring;
205  float zLimitDampingSpring;
206  float zLimitRestitutionSpring;
207  float zLimitBounceThresholdSpring;
208 
209  Drive drive[6];
210  AtomsCore::Vector3f driveLinearVelocity;
211  AtomsCore::Vector3f driveAngularVelocity;
212  AtomsCore::Matrixf drivePose;
213  };
214 
215  class ATOMS_EXPORT RigidBodyConstraint
216  {
217  public:
219 
221 
222  void setDrivePose();
223 
224  void updateDrivePose(const AtomsCore::Matrixf& matrix);
225 
226  void updateDrive(short driveType, RigidBodyConstraintAttributes::Drive& driveAttributes);
227 
228  void force(AtomsCore::Vector3f& linear, AtomsCore::Vector3f& angular) const;
229 
230  void setBreakForce(float force, float torque);
231 
232  AtomsCore::Matrixf localPose(size_t actor) const;
233 
234  AtomsCore::Matrixf relativePose() const;
235 
236  void breakConstraint();
237 
238  void remove();
239 
240  void release();
241 
242  public:
243 
244  physx::PxJoint* joint;
245 
246  AtomsCore::Matrixf drivePose;
247 
248  bool drivePoseUpdated;
249 
250  bool removeFlag;
251  };
252 }
253 #endif
Definition: RigidBodyConstraint.h:78
Definition: RigidBodyConstraint.h:23
bool serialise(std::string &outStream) const
Binary Serialise.
bool deserialise(const AtomsCore::MapMetadata *inStream)
Binary Deserialise.
bool deserialise(const std::string &inStream)
Binary Deserialise.
bool serialise(AtomsCore::MapMetadata *outStream) const
Binary Serialise.
Definition: RigidBodyConstraint.h:216
MapMetadata class.
Definition: MapMetadata.h:24
AtomsMath::Matrixf Matrixf
Matrix class.
Definition: AtomsMath.h:64
AtomsMath::Vector2f Vector2f
Vector2 class.
Definition: AtomsMath.h:55
AtomsMath::Vector3f Vector3f
Vector3 class.
Definition: AtomsMath.h:58
Atoms namespace.
Definition: Agent.h:29
Definition: RigidBodyConstraint.h:54
Enum
Definition: RigidBodyConstraint.h:56
Definition: RigidBodyConstraint.h:40
Enum
Definition: RigidBodyConstraint.h:42
Definition: RigidBodyConstraint.h:68
Enum
Definition: RigidBodyConstraint.h:70
@ kLOCKED
The DOF is locked, it does not allow relative motion.
Definition: RigidBodyConstraint.h:71
@ kLIMITED
The DOF is limited, it only allows motion within a specific range.
Definition: RigidBodyConstraint.h:72
Definition: RigidBodyConstraint.h:27