AGX Dynamics  2.38.0.2
ElementaryConstraintData.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12  Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13  from using this software, unless otherwise stated in written agreements with
14  Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_ELEMENTARYCONSTRAINTDATA_H
18 #define AGX_ELEMENTARYCONSTRAINTDATA_H
19 
20 #include <agx/Attachment.h>
21 
22 #ifdef _MSC_VER
23 # pragma warning(push)
24 # pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
25 #endif
26 
27 
28 namespace agx
29 {
34  {
35  public:
40 
46 
50  virtual ~ElementaryConstraintData();
51 
56  virtual void set( const agx::AttachmentPair* ap );
57 
61  AGX_FORCE_INLINE const agx::AttachmentPair* getAttachmentPair() const { agxAssert( m_ap != nullptr && m_ap->valid() ); return m_ap; }
62 
67  AGX_FORCE_INLINE const agx::Attachment* getAttachment( agx::UInt index ) const { agxAssert( m_ap != nullptr && m_ap->valid() ); return (*m_ap)[ index ]; }
68 
72  AGX_FORCE_INLINE const agx::Vec3& getSeparation() const { agxAssert( m_ap != nullptr && m_ap->valid() ); return m_ap->get( AttachmentPair::SEPARATION ); }
73 
77  AGX_FORCE_INLINE const agx::Vec3& getCmToAnchorPosition( agx::UInt index ) const { agxAssert( m_ap != nullptr && m_ap->valid() ); return getAttachment( index )->get( Attachment::CM_TO_ANCHOR_POS ); }
78 
82  AGX_FORCE_INLINE const agx::Vec3& getWorldToAnchorPosition( agx::UInt index ) const { agxAssert( m_ap != nullptr && m_ap->valid() ); return getAttachment( index )->get( Attachment::ANCHOR_POS ); }
83 
87  virtual void store( agxStream::OutputArchive& out ) const;
88 
92  virtual void restore( agxStream::InputArchive& in );
93 
94  protected:
96  };
97 
102  {
103  public:
107  Dot1Data();
108 
116 
120  virtual ~Dot1Data();
121 
125  AGX_FORCE_INLINE const agx::Vec3& getDir1() const { return getAttachment( 0 )->get( m_dir1 ); }
126 
130  AGX_FORCE_INLINE const agx::Vec3& getDir2() const { return getAttachment( 1 )->get( m_dir2 ); }
131 
135  virtual void store( agxStream::OutputArchive& out ) const override;
136 
140  virtual void restore( agxStream::InputArchive& in ) override;
141 
142  protected:
145  };
146 
147 
152  {
153  public:
157  Dot1SlackData();
158 
162 
163  virtual ~Dot1SlackData();
164 
169  {
170  m_slack = slack;
171  }
172 
177  {
178  return m_slack;
179  }
180 
184  virtual void store( agxStream::OutputArchive& out ) const override;
185 
189  virtual void restore( agxStream::InputArchive& in ) override;
190 
191 
192  protected:
194  };
195 
200  {
201  public:
205  Dot2Data();
206 
214  Dot2Data(
215  const agx::AttachmentPair* ap,
217  agx::Int body=0
218  );
219 
223  virtual ~Dot2Data();
224 
225  virtual agx::Int getReferenceBody() const { return m_body; }
226 
230  AGX_FORCE_INLINE const agx::Vec3& getDir() const { return getAttachment( m_body )->get( m_dir ); }
231 
235  virtual void store( agxStream::OutputArchive& out ) const override;
236 
240  virtual void restore( agxStream::InputArchive& in ) override;
241 
242  protected:
245  };
246 
247 
248 
253  {
254  public:
258  Dot2SlackData();
259 
267 
271  virtual ~Dot2SlackData();
272 
273 
277  virtual void store( agxStream::OutputArchive& out ) const override;
278 
282  virtual void restore( agxStream::InputArchive& in ) override;
283 
285  {
286  return m_slack;
287  }
288 
290  {
291  m_slack = slack;
292  }
293 
294  protected:
296  };
297 
298 
299 
300 
305  {
306  public:
308 
310 
311  virtual ~Slack3ConstraintData();
312 
313  virtual void store( agxStream::OutputArchive& out ) const override;
314 
315  virtual void restore( agxStream::InputArchive& in ) override;
316 
318  {
319  return m_slack;
320  }
321 
323  {
324  m_slack = slack;
325  }
326 
327  protected:
329  };
330 
331 
332 
337  {
338  public:
343  {
344  public:
348  QuatTransformer();
349 
353  virtual void transform( const agx::AttachmentPair& attachmentPair ) override;
354 
358  AGX_FORCE_INLINE const agx::Quat& operator[] ( agx::UInt i ) const { return m_q[ i ]; }
359 
363  AGX_FORCE_INLINE agx::Quat& operator[] ( agx::UInt i ) { return m_q[ i ]; }
364 
365  protected:
369  virtual ~QuatTransformer() {}
370 
371  protected:
372  agx::Quat m_q[ 3 ];
373  };
374 
376 
377  public:
381  QuatLockData();
382 
387  QuatLockData( const agx::AttachmentPair* ap );
388 
392  virtual ~QuatLockData();
393 
399  void set( const agx::AttachmentPair* ap ) override;
400 
404  AGX_FORCE_INLINE const agx::Quat& operator[] ( agx::UInt i ) const { agxAssert( m_qTransformer != nullptr ); return (*m_qTransformer)[ i ]; }
405 
409  AGX_FORCE_INLINE agx::Quat& operator[] ( agx::UInt i ) { agxAssert( m_qTransformer != nullptr ); return (*m_qTransformer)[ i ]; }
410 
414  virtual void store( agxStream::OutputArchive& out ) const override;
415 
419  virtual void restore( agxStream::InputArchive& in ) override;
420 
421  protected:
423  };
424 
429  {
430  public:
435 
443 
447  virtual ~ConstraintAngleBasedData();
448 
452  const agx::Angle* getAngle() const;
453 
457  const agx::Vec3& getDir1() const;
458 
462  const agx::Vec3& getDir2() const;
463 
467  virtual void store( agxStream::OutputArchive& out ) const override;
468 
472  virtual void restore( agxStream::InputArchive& in ) override;
473 
474  protected:
476  };
477 
482  public:
486  SwingData();
487 
498 
502  virtual ~SwingData();
503 
508  {
509  return getAttachment( 0 )->get( m_dir1U );
510  }
511 
516  {
517  return getAttachment( 0 )->get( m_dir1V );
518  }
519 
524  {
525  return getAttachment( 0 )->get( m_dir1N );
526  }
527 
532  {
533  return getAttachment( 1 )->get( m_dir2N );
534  }
535 
540  {
541  return getDir1N().getPerpendicularUnitVector(getDir2N());
542  }
543 
548  {
549  return std::acos(agx::clamp(getDir1N() * getDir2N(), agx::Real(-1.0), agx::Real(1.0)));
550  }
551 
555  virtual void store(agxStream::OutputArchive& out) const override;
556 
560  virtual void restore(agxStream::InputArchive& in) override;
561 
562  protected:
567  };
568 
570  {
571  return m_angle;
572  }
573 
575  {
576  agxAssert( m_angle != nullptr );
577  return m_angle->getDir( *m_ap, 0 );
578  }
579 
581  {
582  agxAssert( m_angle != nullptr );
583  return m_angle->getDir( *m_ap, 1 );
584  }
585 
586 
587 
592 
593  public:
597  TwistData();
598 
604 
608  virtual ~TwistData();
609 
613  virtual void store(agxStream::OutputArchive& out) const override;
614 
618  virtual void restore(agxStream::InputArchive& in) override;
619 
620 
625  {
626  return getAttachment( 0 )->get( m_dir1 );
627  }
628 
633  {
634  return getAttachment( 1 )->get( m_dir2 );
635  }
636 
637  protected:
640 
641  };
642 
643 
648  {
649  public:
653  ConeLimitData();
654 
662 
666  virtual ~ConeLimitData();
667 
672  void setConeLimitValue(Vec2 limit);
673 
678  Vec2 getConeLimitValue() const;
679 
683  virtual void store(agxStream::OutputArchive& out) const override;
684 
688  virtual void restore(agxStream::InputArchive& in) override;
689 
690  protected:
692  };
693 
694 }
695 
696 #ifdef _MSC_VER
697 # pragma warning(pop)
698 #endif
699 
700 
701 #endif
agx::SwingData::m_dir1U
agx::Attachment::Transformed m_dir1U
Definition: ElementaryConstraintData.h:563
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::Vec3T::getPerpendicularUnitVector
Vec3T getPerpendicularUnitVector() const
Definition: Vec3Template.h:732
agx::ConstraintAngleBasedData
Basic data holder class for "angle based" (secondary) constraints.
Definition: ElementaryConstraintData.h:428
agx::Attachment::Transformed
Transformed
Data access enum.
Definition: Attachment.h:42
agx::Real
double Real
Definition: Real.h:42
agx::SwingData
Data holder class for elementary swing constraint.
Definition: ElementaryConstraintData.h:481
agx::SwingData::m_dir2N
agx::Attachment::Transformed m_dir2N
Definition: ElementaryConstraintData.h:566
agxData::transform
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
agx::ElementaryConstraintData::getAttachment
const agx::Attachment * getAttachment(agx::UInt index) const
Definition: ElementaryConstraintData.h:67
agxStream::out
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Definition: OutputArchive.h:412
agx::SwingData::getDir1N
const agx::Vec3 & getDir1N() const
Definition: ElementaryConstraintData.h:523
agx::Dot1SlackData::m_slack
agx::Real m_slack
Definition: ElementaryConstraintData.h:193
agx::ElementaryConstraintData::m_ap
const agx::AttachmentPair * m_ap
Definition: ElementaryConstraintData.h:95
agx::ElementaryConstraintData
Class to hold data for elementary constraints.
Definition: ElementaryConstraintData.h:33
agx::ConstraintAngleBasedData::m_angle
AngleRef m_angle
Definition: ElementaryConstraintData.h:475
agx::Dot1Data::m_dir1
agx::Attachment::Transformed m_dir1
Definition: ElementaryConstraintData.h:143
agx::Dot1SlackData::setSlack
void setSlack(agx::Real slack)
Set amount of slack in constraint.
Definition: ElementaryConstraintData.h:168
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agx::Dot2Data::m_body
agx::Int m_body
Definition: ElementaryConstraintData.h:244
agx::TwistData::getDir1
const agx::Vec3 & getDir1() const
Definition: ElementaryConstraintData.h:624
agx::AttachmentPair
Constraint attachment pair class.
Definition: Attachment.h:300
agx::ConstraintAngleBasedData::getAngle
const agx::Angle * getAngle() const
Definition: ElementaryConstraintData.h:569
agx::QuatLockData
Data holder class for elementary constraint QuatLock.
Definition: ElementaryConstraintData.h:336
agx::Attachment::ANCHOR_POS
@ ANCHOR_POS
Constraint attachment world position.
Definition: Attachment.h:47
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::Dot2SlackData
Data holder class for elementary constraint Dot2Slack.
Definition: ElementaryConstraintData.h:252
agxStream::in
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:399
agx::Dot1Data::m_dir2
agx::Attachment::Transformed m_dir2
Definition: ElementaryConstraintData.h:144
agx::ConeLimitData::ConeLimitAngleRef
agx::ref_ptr< agx::ConeLimitAngle > ConeLimitAngleRef
Definition: ElementaryConstraintData.h:691
agx::Dot1SlackData
Extended Dot1Data with additional slack parameter.
Definition: ElementaryConstraintData.h:151
agx::QuatLockData::QuatTransformer
The class holding the actual data and that transforms the data.
Definition: ElementaryConstraintData.h:342
agx::SwingData::getDir1U
const agx::Vec3 & getDir1U() const
Definition: ElementaryConstraintData.h:507
agx::SwingData::m_dir1N
agx::Attachment::Transformed m_dir1N
Definition: ElementaryConstraintData.h:565
agx::clamp
T1 clamp(T1 v, T2 minimum, T3 maximum)
Definition: Math.h:318
agx::TwistData::m_dir2
agx::Attachment::Transformed m_dir2
Definition: ElementaryConstraintData.h:639
agx::Int
int64_t Int
Definition: Integer.h:28
agx::ElementaryConstraintData::getCmToAnchorPosition
const agx::Vec3 & getCmToAnchorPosition(agx::UInt index) const
Definition: ElementaryConstraintData.h:77
agx::ref_ptr< QuatTransformer >
agx::TwistData::getDir2
const agx::Vec3 & getDir2() const
Definition: ElementaryConstraintData.h:632
agx::Slack3ConstraintData
Generic class for holding constraint data including 3 slack parameters.
Definition: ElementaryConstraintData.h:304
agx::Dot2SlackData::m_slack
agx::Real m_slack
Definition: ElementaryConstraintData.h:295
agx::SwingData::getDir2N
const agx::Vec3 & getDir2N() const
Definition: ElementaryConstraintData.h:531
agx::ElementaryConstraintData::getSeparation
const agx::Vec3 & getSeparation() const
Definition: ElementaryConstraintData.h:72
agx::Dot2SlackData::getSlack
agx::Real getSlack() const
Definition: ElementaryConstraintData.h:284
agx::SwingData::m_dir1V
agx::Attachment::Transformed m_dir1V
Definition: ElementaryConstraintData.h:564
agx::Vec2T< Real >
agx::Dot1SlackData::getSlack
agx::Real getSlack() const
Definition: ElementaryConstraintData.h:176
agx::Dot2Data::getReferenceBody
virtual agx::Int getReferenceBody() const
Definition: ElementaryConstraintData.h:225
agx::ConstraintAngleBasedData::getDir2
const agx::Vec3 & getDir2() const
Definition: ElementaryConstraintData.h:580
agx::TwistData::m_dir1
agx::Attachment::Transformed m_dir1
Definition: ElementaryConstraintData.h:638
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agx::Angle::getDir
virtual const agx::Vec3 & getDir(const agx::AttachmentPair &ap, agx::UInt index) const
agx::QuatT< Real >
agx::ElementaryConstraintData::getWorldToAnchorPosition
const agx::Vec3 & getWorldToAnchorPosition(agx::UInt index) const
Definition: ElementaryConstraintData.h:82
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
agx::QuatLockData::m_qTransformer
QuatTransformerRef m_qTransformer
Definition: ElementaryConstraintData.h:422
agx::Dot2Data
Data holder class for elementary constraint Dot2.
Definition: ElementaryConstraintData.h:199
agx::Dot2Data::getDir
const agx::Vec3 & getDir() const
Definition: ElementaryConstraintData.h:230
agx::getAngle
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
Definition: ConstraintImplementation.h:1419
agx::SwingData::getSwingAngle
agx::Real getSwingAngle() const
Definition: ElementaryConstraintData.h:547
agx::SwingData::getSwingAxis
agx::Vec3 getSwingAxis() const
Definition: ElementaryConstraintData.h:539
agx::TwistData
Data holder class for elementary constraint Twist.
Definition: ElementaryConstraintData.h:591
agx::Attachment
Constraint attachment base class for any type of frame.
Definition: Attachment.h:36
agx::QuatLockData::QuatTransformer::~QuatTransformer
virtual ~QuatTransformer()
Reference counted object, protected destructor.
Definition: ElementaryConstraintData.h:369
agx::Angle
Constraint angle class.
Definition: ConstraintAngle.h:31
agx::QuatLockData::QuatTransformerRef
agx::ref_ptr< QuatTransformer > QuatTransformerRef
Definition: ElementaryConstraintData.h:375
agx::Dot1Data::getDir2
const agx::Vec3 & getDir2() const
Definition: ElementaryConstraintData.h:130
agx::Slack3ConstraintData::getSlack
const agx::Vec3 getSlack() const
Definition: ElementaryConstraintData.h:317
agx::Vec3T< Real >
agx::SwingData::getDir1V
const agx::Vec3 & getDir1V() const
Definition: ElementaryConstraintData.h:515
agx::ConeLimitData
Basic data holder class for cone limit constraint data.
Definition: ElementaryConstraintData.h:647
agx::AttachmentPair::CustomData
Custom data for separation pair.
Definition: Attachment.h:318
agx::Slack3ConstraintData::m_slack
agx::Vec3 m_slack
Definition: ElementaryConstraintData.h:328
agx::AttachmentPair::SEPARATION
@ SEPARATION
Separation vector, i.e., the vector from frame 2 to frame 1.
Definition: Attachment.h:308
agx::Dot1Data
Data holder class for elementary constraint Dot1.
Definition: ElementaryConstraintData.h:101
agx::Dot1Data::getDir1
const agx::Vec3 & getDir1() const
Definition: ElementaryConstraintData.h:125
agx::Slack3ConstraintData::setSlack
void setSlack(agx::Vec3 slack)
Definition: ElementaryConstraintData.h:322
agx::ConeLimitAngle
Implementation of angle for the cone limit.
Definition: ConstraintAngle.h:250
agx::Attachment::CM_TO_ANCHOR_POS
@ CM_TO_ANCHOR_POS
Vector from center of mass (if moving) to anchor point given in world frame.
Definition: Attachment.h:48
agx::Dot2SlackData::setSlack
void setSlack(agx::Real slack)
Definition: ElementaryConstraintData.h:289
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
Attachment.h
agx::ElementaryConstraintData::getAttachmentPair
const agx::AttachmentPair * getAttachmentPair() const
Definition: ElementaryConstraintData.h:61
agx::ConstraintAngleBasedData::getDir1
const agx::Vec3 & getDir1() const
Definition: ElementaryConstraintData.h:574
agx::Dot2Data::m_dir
agx::Attachment::Transformed m_dir
Definition: ElementaryConstraintData.h:243