AGX Dynamics 2.42.3.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
17#pragma once
18
19#include <agx/ConstraintAngle.h>
20#include <agx/RigidBody.h>
21#include <agx/BitState.h>
22
23#ifdef _MSC_VER
24# pragma warning( push )
25# pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
26# pragma warning(disable: 6385) // Disable warning C6385: Reading invalid data
27#endif
28
29
30namespace agx
31{
32 class ConstraintImplementation;
33
39 {
40 public:
45 {
46 U,
47 V,
48 N,
51 NUM_ELEMENTS
52 };
53
54 public:
61 static void createAttachmentBase( const agx::Vec3d& N, agx::Vec3d& U, agx::Vec3d& V );
62 static void createAttachmentBase( const agx::Vec3f& N, agx::Vec3f& U, agx::Vec3f& V );
63
64 public:
69 Attachment( agx::Frame* relFrame );
70
77 virtual void transform();
78
82 virtual agx::Bool objectDeleted() const;
83
87 virtual agx::Bool valid() const;
88
92 const agx::Vec3& get( agx::Attachment::Transformed entry ) const;
93
98
103 void setFrame( agx::Frame* frame );
104
108 agx::Frame* getFrame() const;
109
114 virtual agx::Real calculateDistance( const agx::Attachment* other ) const;
115
119 virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const;
120
124 virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const;
125
129 virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const;
130
135
140
144 template<typename T>
145 agx::Bool is() const;
146
152 template<typename T>
153 T* as();
154
159 template<typename T>
160 T* safeAs();
161
167 template<typename T>
168 const T* as() const;
169
174 template<typename T>
175 const T* safeAs() const;
176
178
179 protected:
184
188 virtual ~Attachment();
189
197 void transform( const agx::AffineMatrix4x4& cmTransform, const agx::Vec3& cmToModel, const agx::AffineMatrix4x4& localConstraintTransform );
198
199 protected:
200 agx::Vec3 m_transformed[ NUM_ELEMENTS ];
202 };
203
205
210 {
211 public:
218
222 virtual agx::Bool objectDeleted() const override;
223
227 virtual agx::Bool valid() const override;
228
233 virtual agx::Real calculateDistance( const agx::Attachment* other ) const override;
234
238 virtual agx::Real calculateLinearDistance( const agx::Attachment* other ) const override;
239
243 virtual agx::Real calculateLinearSpeed( const agx::Attachment* other ) const override;
244
248 virtual agx::Real calculateAngularSpeed( const agx::Attachment* other ) const override;
249
253 virtual agx::Vec3 getLinearVelocity() const override;
254
258 virtual agx::Vec3 getAngularVelocity() const override;
259
263 virtual void transform() override;
264
271
275 agx::RigidBody* getRigidBody() const;
276
278
279 protected:
284
289
290 protected:
293 };
294
296
303 {
304 public:
309 {
311 NUM_ELEMENTS
312 };
313
314 public:
321 {
322 public:
326 virtual void transform( const agx::AttachmentPair& attachmentPair ) = 0;
327
328 protected:
332 virtual ~CustomData() {}
333 };
334
336
337 public:
342
347
354
359 void add( agx::Angle* angle );
360
367
372
376 agx::Bool hasAngle( const agx::Angle* angle ) const;
377
384
391
397
402
406 agx::Attachment* operator[] ( agx::UInt i ) const;
407
411 agx::Attachment* getAttachment1() const;
412
416 agx::Attachment* getAttachment2() const;
417
422
426 virtual void transform();
427
433 virtual void onPostIntegrate( 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:
490 void setEnableAttachmentProjections( bool enable, bool projectBody2ToReference = true );
491
495 bool getEnableAttachmentProjections() const;
496
503 void setAttachmentMinimumProjectionsSpeed( agx::Real minimumProjectionsSpeed );
504
508 agx::Real getAttachmentMinimumProjectionsSpeed() const;
509
511
512 protected:
514 {
516 {
517 ATTACHMENT_PROJECTIONS_ENABLED = 1 << 0,
518 // By default, body 1 is reference and body 2 is projected to
519 // the frame of body 1. This option enables for projection of
520 // body 1 to the constraint frame of body 2.
521 ATTACHMENT_PROJECTIONS_PROJECT_BODY_1 = 1 << 1,
522 };
523 using Flags = BitState<Flag, std::underlying_type_t<Flag>>;
524
526 agx::Real minimumProjectionSpeed = 15.0;
530 };
531
532 protected:
533 AttachmentRef m_attachments[ 2 ];
534 agx::Vec3 m_transformed[ NUM_ELEMENTS ];
538 };
539
541 {
542 return m_transformed[ entry ];
543 }
544
546 {
547 return m_relFrame;
548 }
549
550 template<typename T>
552 {
553 return dynamic_cast<const T*>( this ) != nullptr;
554 }
555
556 template<>
557 AGX_FORCE_INLINE Bool Attachment::is<Attachment>() const
558 {
559 return true;
560 }
561
562 template<typename T>
564 {
565 // Compiler warns on 'this == nullptr' because it is illegal to call member
566 // functions on nullptr. However, if it helps us find a nullptr dereference
567 // earlier, and with an assert instead of segmentation fault, then I think
568 // it's ok to leave the check.
570 agxAssert( (void *)this == nullptr || this->is<T>() );
571 return static_cast<T*>( this );
572 #include <agx/PopDisableWarnings.h>
573 }
574
575 template<typename T>
577 {
578 return dynamic_cast<T*>( this );
579 }
580
581 template<typename T>
583 {
584 // Compiler warns on 'this == nullptr' because it is illegal to call member
585 // functions on nullptr. However, if it helps us find a nullptr dereference
586 // earlier, and with an assert instead of segmentation fault, then I think
587 // it's ok to leave the check.
589 agxAssert( (void *)this == nullptr || this->is<T>() ); return static_cast<const T*>( this );
590 #include <agx/PopDisableWarnings.h>
591 }
592
593 template<typename T>
595 {
596 return dynamic_cast<const T*>( this );
597 }
598
600 {
601 return m_rb;
602 }
603
605 {
606 agxAssert( i < 2 );
607 return m_attachments[ i ].get();
608 }
609
611 {
612 return (*this)[ 0 ];
613 }
614
616 {
617 return (*this)[ 1 ];
618 }
619
621 {
622 return m_transformed[ entry ];
623 }
624} // namespace agx
625
626#ifdef _MSC_VER
627#pragma warning( pop )
628#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:207
#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:44
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.
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 void onPostIntegrate(agx::Real dt, const agx::ConstraintImplementation &context)
Post transform updates.
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:49
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:41
BitState< Flag, std::underlying_type_t< Flag > > Flags