AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
agx/Attachment.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17
18#include <agx/ConstraintAngle.h>
19#include <agx/RigidBody.h>
20#include <agx/BitState.h>
21
22#ifdef _MSC_VER
23# pragma warning( push )
24# pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
25# pragma warning(disable: 6385) // Disable warning C6385: Reading invalid data
26#endif
27
28
29namespace agx
30{
31 class ConstraintImplementation;
32
38 {
39 public:
44 {
45 U,
46 V,
47 N,
50 NUM_ELEMENTS
51 };
52
53 public:
60 static void createAttachmentBase( const agx::Vec3d& N, agx::Vec3d& U, agx::Vec3d& V );
61 static void createAttachmentBase( const agx::Vec3f& N, agx::Vec3f& U, agx::Vec3f& V );
62
63 public:
68 Attachment( agx::Frame* relFrame );
69
76 virtual void transform();
77
81 virtual agx::Bool objectDeleted() const;
82
86 virtual agx::Bool valid() const;
87
91 const agx::Vec3& get( agx::Attachment::Transformed entry ) const;
92
97
102 void setFrame( agx::Frame* frame );
103
107 agx::Frame* getFrame() const;
108
113 virtual agx::Real calculateDistance( const agx::Attachment* other ) const;
114
118 virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const;
119
123 virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const;
124
128 virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const;
129
134
139
143 template<typename T>
144 agx::Bool is() const;
145
151 template<typename T>
152 T* as();
153
158 template<typename T>
159 T* safeAs();
160
166 template<typename T>
167 const T* as() const;
168
173 template<typename T>
174 const T* safeAs() const;
175
177
178 protected:
183
187 virtual ~Attachment();
188
196 void transform( const agx::AffineMatrix4x4& cmTransform, const agx::Vec3& cmToModel, const agx::AffineMatrix4x4& localConstraintTransform );
197
198 protected:
199 agx::Vec3 m_transformed[ NUM_ELEMENTS ];
201 };
202
204
209 {
210 public:
217
221 virtual agx::Bool objectDeleted() const override;
222
226 virtual agx::Bool valid() const override;
227
232 virtual agx::Real calculateDistance( const agx::Attachment* other ) const override;
233
237 virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const override;
238
242 virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const override;
243
247 virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const override;
248
252 virtual agx::Vec3 getLinearVelocity() const override;
253
257 virtual agx::Vec3 getAngularVelocity() const override;
258
262 virtual void transform() override;
263
270
274 agx::RigidBody* getRigidBody() const;
275
277
278 protected:
283
288
289 protected:
292 };
293
295
302 {
303 public:
308 {
310 NUM_ELEMENTS
311 };
312
313 public:
320 {
321 public:
325 virtual void transform( const agx::AttachmentPair& attachmentPair ) = 0;
326
327 protected:
331 virtual ~CustomData() {}
332 };
333
335
336 public:
341
346
353
358 void add( agx::Angle* angle );
359
366
371
375 agx::Bool hasAngle( const agx::Angle* angle ) const;
376
383
390
396
401
405 agx::Attachment* operator[] ( agx::UInt i ) const;
406
410 agx::Attachment* getAttachment1() const;
411
415 agx::Attachment* getAttachment2() const;
416
421
425 virtual void transform();
426
433 virtual void onPreSolve( agx::Real dt, const agx::ConstraintImplementation& context );
434
440 virtual void onPostSolve( agx::Real dt, const agx::ConstraintImplementation& context );
441
445 virtual agx::Bool rebind();
446
450 const agx::Vec3& get( agx::AttachmentPair::Transformed entry ) const;
451
455 virtual void store( agxStream::OutputArchive& out ) const;
456
460 virtual void restore( agxStream::InputArchive& in );
461
465 virtual void storeLightData( agxStream::StorageStream& str ) const;
466
471
473
474 public:
487 void setEnableAttachmentProjections( bool enable );
488
492 bool getEnableAttachmentProjections() const;
493
495
496
497 protected:
499 {
501 {
502 ATTACHMENT_PROJECTIONS_ENABLAD = 1 << 0,
503 };
504 using Flags = BitState<Flag, std::underlying_type_t<Flag>>;
505
507 };
508
509 protected:
510 AttachmentRef m_attachments[ 2 ];
511 agx::Vec3 m_transformed[ NUM_ELEMENTS ];
515 };
516
518 {
519 return m_transformed[ entry ];
520 }
521
523 {
524 return m_relFrame;
525 }
526
527 template<typename T>
529 {
530 return dynamic_cast<const T*>( this ) != nullptr;
531 }
532
533 template<>
534 AGX_FORCE_INLINE Bool Attachment::is<Attachment>() const
535 {
536 return true;
537 }
538
539 template<typename T>
541 {
542 // Compiler warns on 'this == nullptr' because it is illegal to call member
543 // functions on nullptr. However, if it helps us find a nullptr dereference
544 // earlier, and with an assert instead of segmentation fault, then I think
545 // it's ok to leave the check.
547 agxAssert( (void *)this == nullptr || this->is<T>() );
548 return static_cast<T*>( this );
549 #include <agx/PopDisableWarnings.h>
550 }
551
552 template<typename T>
554 {
555 return dynamic_cast<T*>( this );
556 }
557
558 template<typename T>
560 {
561 // Compiler warns on 'this == nullptr' because it is illegal to call member
562 // functions on nullptr. However, if it helps us find a nullptr dereference
563 // earlier, and with an assert instead of segmentation fault, then I think
564 // it's ok to leave the check.
566 agxAssert( (void *)this == nullptr || this->is<T>() ); return static_cast<const T*>( this );
567 #include <agx/PopDisableWarnings.h>
568 }
569
570 template<typename T>
572 {
573 return dynamic_cast<const T*>( this );
574 }
575
577 {
578 return m_rb;
579 }
580
582 {
583 agxAssert( i < 2 );
584 return m_attachments[ i ].get();
585 }
586
588 {
589 return (*this)[ 0 ];
590 }
591
593 {
594 return (*this)[ 1 ];
595 }
596
598 {
599 return m_transformed[ entry ];
600 }
601} // namespace agx
602
603#ifdef _MSC_VER
604#pragma warning( pop )
605#endif
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:208
#define AGXPHYSICS_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
Constraint angle class.
Custom data for separation pair.
virtual void transform(const agx::AttachmentPair &attachmentPair)=0
Called after the other attachments have been transformed.
virtual ~CustomData()
Reference counted object, protected destructor.
Constraint attachment pair class.
AttachmentPair()
Default constructor, attachment frame 1 = attachment frame 2 = 0.
virtual void transform()
Transform attachment frames and updates data.
void setCustomData(agx::AttachmentPair::CustomData *customData)
Assign custom data to receive transform calls.
virtual void restoreLightData(agxStream::StorageStream &str)
Restore structural independent data from stream.
virtual void onPreSolve(agx::Real dt, const agx::ConstraintImplementation &context)
Pre solvers, position/orientation dependent variables (used in Jacobians) should be updated.
agx::Attachment * getAttachment2() const
virtual void store(agxStream::OutputArchive &out) const
Store given stream.
void add(agx::Angle *angle)
Add constraint angle.
agx::Attachment * operator[](agx::UInt i) const
agx::Bool valid() const
agx::Attachment * getAttachment1() const
virtual agx::Bool rebind()
Rebind given first frame.
agx::AttachmentPair::CustomData * getCustomData() const
virtual void storeLightData(agxStream::StorageStream &str) const
Store structural independent data to stream.
Transformed
Data access enum.
@ SEPARATION
Separation vector, i.e., the vector from frame 2 to frame 1.
const agx::Vec3 & get(agx::AttachmentPair::Transformed entry) const
agx::Real calculateLinearSpeed() const
Calculates the linear speed between the two attachments, along the constraint axis.
agx::ref_ptr< CustomData > CustomDataRef
agx::Angle * getAngle(agx::UInt index) const
Access constraint angle given index.
virtual void restore(agxStream::InputArchive &in)
Restore given stream.
InternalState m_state
AngleContainer m_angles
const agx::AngleContainer & getAngles() const
agx::Real calculateAngularSpeed() const
Calculates the rotational/angular speed between the two attachments, about the constraint axis.
virtual ~AttachmentPair()
Destructor.
virtual void onPostSolve(agx::Real dt, const agx::ConstraintImplementation &context)
Post solvers, velocity dependent variables should be updated.
agx::Bool hasAngle(const agx::Angle *angle) const
AttachmentRef m_attachments[2]
CustomDataRef m_customData
void set(agx::Attachment *a1, agx::Attachment *a2)
Assign constraint attachment frames.
agx::Vec3 m_transformed[NUM_ELEMENTS]
Constraint attachment base class for any type of frame.
static void createAttachmentBase(const agx::Vec3d &N, agx::Vec3d &U, agx::Vec3d &V)
Given vector N, create orthonormal base.
virtual agx::Bool valid() const
Transformed
Data access enum.
@ ANCHOR_POS
Constraint attachment world position.
@ V
Constraint attachment y-axis.
@ U
Constraint attachment x-axis.
@ N
Constraint attachment z-axis.
@ CM_TO_ANCHOR_POS
Vector from center of mass (if moving) to anchor point given in world frame.
agx::Frame * getFrame() const
virtual ~Attachment()
Reference counted object, protected destructor.
const agx::Vec3 & get(agx::Attachment::Transformed entry) const
T * safeAs()
Dynamic cast of this to T.
virtual agx::Vec3 getLinearVelocity() const
agx::Vec3 m_transformed[NUM_ELEMENTS]
static void createAttachmentBase(const agx::Vec3f &N, agx::Vec3f &U, agx::Vec3f &V)
virtual agx::Vec3 getAngularVelocity() const
virtual agx::Real calculateLinearDistance(const agx::Attachment *other) const
Attachment(agx::Frame *relFrame)
Construct given frame.
T * as()
Unsafe version, static cast of this to T.
Attachment()
Constructor to use during restore.
agx::Vec3 getLocal(agx::Attachment::Transformed entry) const
virtual agx::Real calculateLinearSpeed(const agx::Attachment *other) const
virtual agx::Real calculateDistance(const agx::Attachment *other) const
void setFrame(agx::Frame *frame)
Assign a new frame - transformed data will be updated.
virtual void transform()
Subclass - implement this method!
agx::Bool is() const
void transform(const agx::AffineMatrix4x4 &cmTransform, const agx::Vec3 &cmToModel, const agx::AffineMatrix4x4 &localConstraintTransform)
Fill Transformed data given center of mass transform and offset from model frame to center of mass fr...
virtual agx::Bool objectDeleted() const
agx::FrameRef m_relFrame
virtual agx::Real calculateAngularSpeed(const agx::Attachment *other) const
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Base class providing referencing counted objects.
Definition: Referenced.h:120
Constraint attachment class for agx::RigidBody.
RigidBodyAttachment()
Protected default constructor used by restore.
virtual agx::Bool objectDeleted() const override
virtual agx::Vec3 getAngularVelocity() const override
agx::RigidBodyObserver m_rb
virtual agx::Real calculateDistance(const agx::Attachment *other) const override
virtual agx::Vec3 getLinearVelocity() const override
virtual agx::Real calculateAngularSpeed(const agx::Attachment *other) const override
virtual ~RigidBodyAttachment()
Reference counted object, protected destructor.
virtual agx::Bool valid() const override
virtual agx::Real calculateLinearSpeed(const agx::Attachment *other) const override
agx::RigidBody * getRigidBody() const
virtual agx::Real calculateLinearDistance(const agx::Attachment *other) const override
virtual void transform() override
Transform given rigid body and frame.
void setRigidBody(agx::RigidBody *rb)
Assign rigid body to this constraint frame.
RigidBodyAttachment(agx::RigidBody *rb, agx::Frame *relFrame)
Construct given rigid body and relative frame.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:46
T * get() const
Definition: ref_ptr.h:256
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:31
bool Bool
Definition: Integer.h:40
agx::ref_ptr< Attachment > AttachmentRef
agx::ref_ptr< RigidBodyAttachment > RigidBodyAttachmentRef
uint64_t UInt
Definition: Integer.h:27
double Real
Definition: Real.h:42
BitState< Flag, std::underlying_type_t< Flag > > Flags