AGX Dynamics  2.37.3.2
Frame.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_FRAME_H
18 #define AGX_FRAME_H
19 
20 #ifdef _MSC_VER
21 # pragma warning(push)
22 # pragma warning( disable: 4290) //: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
23 #endif
24 
25 #include <agx/observer_ptr.h>
26 #include <agx/Vec3.h>
27 #include <agx/AffineMatrix4x4.h>
28 #include <agx/OrthoMatrix3x3.h>
29 
30 #include <agxStream/Serializable.h>
31 #include <agx/SetVector.h>
32 #include <agxData/EntityPtr.h>
33 #include <agxData/AttributePtr.h>
35 
36 namespace agxSDK
37 {
38  class Assembly;
39 }
40 
41 namespace agxCollide
42 {
43  class Geometry;
44 }
45 
46 namespace agx
47 {
48  class RigidBody;
49  class EulerAngles;
50  class OrthoMatrix3x3;
51 
53 
68  {
69  public:
73  Frame();
74 
78  Frame( const agxData::AttributePtr< AffineMatrix4x4 >& localTransform, const agxData::AttributePtr< AffineMatrix4x4 >& globalTransform );
79 
84  explicit Frame( const agx::AffineMatrix4x4 matrix );
85 
90  Frame( const agx::Frame& frame );
91 
96  Frame& operator = ( const agx::Frame& frame );
97 
98  public:
108  bool setParent( agx::Frame* frame );
109 
113  agx::Frame* getParent();
114 
118  const agx::Frame* getParent() const;
119 
123  bool hasParent() const;
124 
132  void setMatrix( const agx::AffineMatrix4x4& matrix );
133 
138  const agx::AffineMatrix4x4& getMatrix() const;
139 
140 
144  bool isFinite() const;
145 
150  void setLocalMatrix( const agx::AffineMatrix4x4& matrix );
151 
155  const agx::AffineMatrix4x4& getLocalMatrix() const;
156 
160  agx::Vec3 getTranslate() const;
161 
166  void setTranslate( const agx::Vec3& translate );
167 
174  void setTranslate( agx::Real x, agx::Real y, agx::Real z );
175 
179  agx::Vec3 getLocalTranslate() const;
180 
185  void setLocalTranslate( const agx::Vec3& translate );
186 
193  void setLocalTranslate( agx::Real x, agx::Real y, agx::Real z );
194 
198  agx::Quat getRotate() const;
199 
204  void setRotate( const agx::Quat& rotation );
205 
210  void setRotate( const agx::OrthoMatrix3x3& rotation );
211 
216  void setRotate( const agx::EulerAngles& euler);
217 
221  Quat getLocalRotate() const;
222 
227  void setLocalRotate( const agx::Quat& rotation );
228 
233  void setLocalRotate( const agx::EulerAngles& rotation );
234 
240  agx::Vec3 transformVectorToWorld( const agx::Vec3& vectorLocal ) const;
241 
250 
257  agx::Vec3& transformVectorToWorld( const agx::Vec3& localVector, agx::Vec3& worldVector ) const;
258 
264  agx::Vec3 transformPointToWorld( const agx::Vec3& pointLocal ) const;
265 
274 
281  agx::Vec3& transformPointToWorld( const agx::Vec3& localPoint, agx::Vec3& worldPoint ) const;
282 
288  agx::Vec3 transformVectorToLocal( const agx::Vec3& worldVector ) const;
289 
297  agx::Vec3 transformVectorToLocal( agx::Real vx, agx::Real vy, agx::Real vz ) const;
298 
305  agx::Vec3& transformVectorToLocal( const agx::Vec3& vectorWorld, agx::Vec3& vectorLocal ) const;
306 
312  agx::Vec3 transformPointToLocal( const agx::Vec3& pointWorld ) const;
313 
321  agx::Vec3 transformPointToLocal( agx::Real px, agx::Real py, agx::Real pz ) const;
322 
329  agx::Vec3& transformPointToLocal( const agx::Vec3& pointWorld, agx::Vec3& pointLocal ) const;
330 
350  void transferDataIntoLeaves( bool keepLocalVelocity = true, bool clearTransform=true );
351 
362  void setAllowTransferIntoChildren( bool allow );
363 
367  bool allowTransferDataIntoChildren() const;
368 
376  void transferChildren( agx::Frame* newParent );
377 
381  bool hasChildren() const;
382 
388  bool removeChild( agx::Frame* frame );
389 
393  void removeAllChildren();
394 
398  agx::RigidBody* getRigidBody();
399 
403  const agx::RigidBody* getRigidBody() const;
404 
409  void setMatrixPointers( const agxData::AttributePtr< agx::AffineMatrix4x4 >& localTransform, const agxData::AttributePtr< agx::AffineMatrix4x4 >& globalTransform );
410 
414  void setEntityData(agxData::AttributePtr< agx::AffineMatrix4x4 > localTransform, agxData::AttributePtr< agx::AffineMatrix4x4 > globalTransform);
415 
420  void updateLocalMatrix();
421 
430  void updateLocalMatrixSSE();
431 
433 
434  protected:
438  virtual ~Frame();
439 
440  private:
441  friend class RigidBody;
442  friend class agxCollide::Geometry;
443 
447  void setRigidBody( agx::RigidBody* body );
448 
452  void setGeometry( agxCollide::Geometry* geometry );
453 
457  void propagateUpdate();
458 
464  void postTransformUpdate();
465 
471  bool addChild( agx::Frame* frame );
472 
473 
474 
475  private:
477 
478  private:
479  Physics::FrameRef m_entity;
480  mutable agxData::AttributePtr< AffineMatrix4x4 > m_globalTransform;
482 
485  bool m_allowTransferDataIntoChildren;
486  Frame* m_parent;
487  FramePtrVector m_children;
488  };
489 
490  AGX_FORCE_INLINE void Frame::setMatrix( const AffineMatrix4x4& matrix )
491  {
492  m_localTransform.get() = matrix;
493  const Frame* parent = getParent();
494  if (parent)
495  m_localTransform.get().postMult(parent->getMatrix().inverse());
496 
497  this->postTransformUpdate();
498  }
499 
500  AGX_FORCE_INLINE void Frame::updateLocalMatrix()
501  {
502  m_localTransform.get() = m_parent ? m_globalTransform.get() * m_parent->m_globalTransform.get().inverse() : m_globalTransform.get();
503  }
504 
505 
506  AGX_FORCE_INLINE Frame* Frame::getParent()
507  {
508  return m_parent;
509  }
510 
511  AGX_FORCE_INLINE const Frame* Frame::getParent() const
512  {
513  return m_parent;
514  }
515 
516  AGX_FORCE_INLINE bool Frame::hasParent() const
517  {
518  return m_parent != nullptr;
519  }
520 
521  AGX_FORCE_INLINE const AffineMatrix4x4& Frame::getLocalMatrix() const
522  {
523  return m_localTransform.get();
524  }
525 
526  AGX_FORCE_INLINE void Frame::setLocalMatrix( const AffineMatrix4x4& matrix )
527  {
528  m_localTransform.get() = matrix;
529  this->postTransformUpdate();
530  }
531 
532  AGX_FORCE_INLINE Vec3 Frame::getTranslate() const
533  {
534  return getMatrix().getTranslate();
535  }
536 
537  AGX_FORCE_INLINE void Frame::setTranslate( const Vec3& translate )
538  {
539  if ( getParent() )
540  m_localTransform.get().setTranslate ( translate * m_parent->getMatrix().inverse() );
541  else
542  m_localTransform.get().setTranslate( translate );
543 
544  this->postTransformUpdate();
545  }
546 
547  AGX_FORCE_INLINE void Frame::setTranslate( Real x, Real y, Real z )
548  {
549  setTranslate( Vec3( x, y, z ) );
550  }
551 
552  AGX_FORCE_INLINE Vec3 Frame::getLocalTranslate() const
553  {
554  return m_localTransform.get().getTranslate();
555  }
556 
557  AGX_FORCE_INLINE void Frame::setLocalTranslate( const Vec3& translate )
558  {
559  m_localTransform.get().setTranslate( translate );
560  this->postTransformUpdate();
561  }
562 
563  AGX_FORCE_INLINE void Frame::setLocalTranslate( Real x, Real y, Real z )
564  {
565  setLocalTranslate( Vec3( x, y, z ) );
566  }
567 
569  {
570  Vec3 vectorWorld;
571  return transformVectorToWorld( vectorLocal, vectorWorld );
572  }
573 
575  {
576  return transformVectorToWorld( Vec3( vx, vy, vz ) );
577  }
578 
579  AGX_FORCE_INLINE Vec3& Frame::transformVectorToWorld( const Vec3& localVector, Vec3& worldVector ) const
580  {
581  const AffineMatrix4x4& m = getMatrix();
582 
583  m.transform3x3( localVector, worldVector );
584  return worldVector;
585  }
586 
588  {
589  Vec3 wP;
590  return transformPointToWorld( pointLocal, wP);
591  }
592 
594  {
595  return transformPointToWorld( Vec3( px, py, pz ) );
596  }
597 
598  AGX_FORCE_INLINE Vec3& Frame::transformPointToWorld( const Vec3& localPoint, Vec3& worldPoint ) const
599  {
600  const AffineMatrix4x4& m = getMatrix();
601 
602  worldPoint = m.preMult( localPoint );
603  return worldPoint;
604  }
605 
606  AGX_FORCE_INLINE Vec3 Frame::transformVectorToLocal( const Vec3& worldVector ) const
607  {
608  Vec3 localVector;
609  return transformVectorToLocal( worldVector, localVector );
610  }
611 
612  AGX_FORCE_INLINE Vec3 Frame::transformVectorToLocal( Real vx, Real vy, Real vz ) const
613  {
614  return transformVectorToLocal( Vec3( vx, vy, vz ) );
615  }
616 
617  AGX_FORCE_INLINE Vec3& Frame::transformVectorToLocal( const Vec3& vectorWorld, Vec3& vectorLocal ) const
618  {
619  AffineMatrix4x4 m = getMatrix();
620 
621  m.setTranslate( 0, 0, 0 );
622  vectorLocal = m.postMult( vectorWorld );
623  return vectorLocal;
624  }
625 
626  AGX_FORCE_INLINE Vec3 Frame::transformPointToLocal( const Vec3& pointWorld ) const
627  {
628  Vec3 pointLocal;
629  return transformPointToLocal( pointWorld, pointLocal );
630  }
631 
632  AGX_FORCE_INLINE Vec3 Frame::transformPointToLocal( Real px, Real py, Real pz ) const
633  {
634  return transformPointToLocal( Vec3( px, py, pz ) );
635  }
636 
637  AGX_FORCE_INLINE Vec3& Frame::transformPointToLocal( const Vec3& pointWorld, Vec3& pointLocal ) const
638  {
639  AffineMatrix4x4 m = getMatrix().inverse();
640 
641  pointLocal = m.preMult( pointWorld );
642  return pointLocal;
643  }
644 
645  AGX_FORCE_INLINE bool Frame::allowTransferDataIntoChildren() const
646  {
647  return m_allowTransferDataIntoChildren;
648  }
649 
650  AGX_FORCE_INLINE void Frame::setAllowTransferIntoChildren( bool allow )
651  {
652  m_allowTransferDataIntoChildren = allow;
653  }
654 
655  AGX_FORCE_INLINE bool Frame::hasChildren() const
656  {
657  return !m_children.empty();
658  }
659 
660  AGX_FORCE_INLINE void Frame::removeAllChildren()
661  {
662  FramePtrVector::iterator it = m_children.begin();
663  for(; it != m_children.end(); ++it)
664  {
665  (*it)->m_parent = nullptr;
666  }
667  m_children.clear();
668  }
669 
670  AGX_FORCE_INLINE bool Frame::removeChild( Frame* frame )
671  {
672  if(m_children.erase( frame ))
673  {
674  frame->m_parent = nullptr;
675  return true;
676  }
677  return false;
678  }
679 
680  AGX_FORCE_INLINE agx::RigidBody* Frame::getRigidBody()
681  {
682  return m_rigidBody.get();
683  }
684 
685  AGX_FORCE_INLINE const agx::RigidBody* Frame::getRigidBody() const
686  {
687  return m_rigidBody;
688  }
689 
690  #define AGX_ADD_FRAME_TRANSFORM_INTERFACE() \
691  AGX_FORCE_INLINE const agx::AffineMatrix4x4& getTransform() const { return getFrame()->getMatrix(); } \
692  AGX_FORCE_INLINE agx::Vec3 getPosition() const { return getFrame()->getTranslate(); } \
693  AGX_FORCE_INLINE agx::Quat getRotation() const { return getFrame()->getRotate(); }
694 
695 } // namespace agx
696 
697 #ifdef _MSC_VER
698 # pragma warning(pop)
699 #endif
700 
701 #endif
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
void postMult(const AffineMatrix4x4T< T > &)
This namespace consists of a set of classes for handling geometric intersection tests including boole...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
VectorType::iterator iterator
Definition: SetVector.h:62
Vec3T< T > & transform3x3(const Vec3T< T > &vIn, Vec3T< T > &vOut) const
Definition: Matrix4x4.h:971
void get(QuatT< T > &q) const
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
const agx::AffineMatrix4x4 & getMatrix() const
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void preMult(const AffineMatrix4x4T< T > &)
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#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
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
agx::VectorPOD< FramePtr > FramePtrVector
Definition: FrameEntity.h:232
static agx::Vec3 transformVectorToWorld(const agx::Vec3 &v, const agxCollide::Geometry *g)
Transforms a vector given in shape coordinates to world coordinates given geometry g...
Definition: WireUtils.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
double Real
Definition: Real.h:42
bool isFinite(T v)
Definition: Math.h:309
static agx::Vec3 transformPointToWorld(const agx::Vec3 &p, const agxCollide::Geometry *g)
Transforms a point given in shape coordinates to world given geometry g.
Definition: WireUtils.h:81
AffineMatrix4x4T< T > & setTranslate(const Vec3T< T > &t)
Set the translational part of the matrix using the vector t.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
Specialized types of matrices for holding orthogonal transformation matrices.