AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
agx/Frame.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#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
31#include <agx/SetVector.h>
32#include <agxData/EntityPtr.h>
35
36namespace agxSDK
37{
38 class Assembly;
39}
40
41namespace agxCollide
42{
43 class Geometry;
44}
45
46namespace agx
47{
48 class RigidBody;
49 class EulerAngles;
50 class OrthoMatrix3x3;
51
53
68 {
69 public:
74
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
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
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
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
249 agx::Vec3 transformVectorToWorld( agx::Real vx, agx::Real vy, agx::Real vz ) const;
250
257 agx::Vec3& transformVectorToWorld( const agx::Vec3& localVector, agx::Vec3& worldVector ) const;
258
264 agx::Vec3 transformPointToWorld( const agx::Vec3& pointLocal ) const;
265
273 agx::Vec3 transformPointToWorld( agx::Real px, agx::Real py, agx::Real pz ) const;
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
394
399
404
410
415
420 void updateLocalMatrix();
421
431
433
434 protected:
438 virtual ~Frame();
439
440 private:
441 friend class RigidBody;
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
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
501 {
502 m_localTransform.get() = m_parent ? m_globalTransform.get() * m_parent->m_globalTransform.get().inverse() : m_globalTransform.get();
503 }
504
505
507 {
508 return m_parent;
509 }
510
512 {
513 return m_parent;
514 }
515
517 {
518 return m_parent != nullptr;
519 }
520
522 {
523 return m_localTransform.get();
524 }
525
527 {
528 m_localTransform.get() = matrix;
529 this->postTransformUpdate();
530 }
531
533 {
534 return getMatrix().getTranslate();
535 }
536
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
548 {
549 setTranslate( Vec3( x, y, z ) );
550 }
551
553 {
554 return m_localTransform.get().getTranslate();
555 }
556
558 {
559 m_localTransform.get().setTranslate( translate );
560 this->postTransformUpdate();
561 }
562
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
607 {
608 Vec3 localVector;
609 return transformVectorToLocal( worldVector, localVector );
610 }
611
613 {
614 return transformVectorToLocal( Vec3( vx, vy, vz ) );
615 }
616
617 AGX_FORCE_INLINE Vec3& Frame::transformVectorToLocal( const Vec3& vectorWorld, Vec3& vectorLocal ) const
618 {
620
621 m.setTranslate( 0, 0, 0 );
622 vectorLocal = m.postMult( vectorWorld );
623 return vectorLocal;
624 }
625
627 {
628 Vec3 pointLocal;
629 return transformPointToLocal( pointWorld, pointLocal );
630 }
631
633 {
634 return transformPointToLocal( Vec3( px, py, pz ) );
635 }
636
637 AGX_FORCE_INLINE Vec3& Frame::transformPointToLocal( const Vec3& pointWorld, Vec3& pointLocal ) const
638 {
640
641 pointLocal = m.preMult( pointWorld );
642 return pointLocal;
643 }
644
646 {
647 return m_allowTransferDataIntoChildren;
648 }
649
651 {
652 m_allowTransferDataIntoChildren = allow;
653 }
654
656 {
657 return !m_children.empty();
658 }
659
660 #define AGX_ADD_FRAME_TRANSFORM_INTERFACE() \
661 AGX_FORCE_INLINE const agx::AffineMatrix4x4& getTransform() const { return getFrame()->getMatrix(); } \
662 AGX_FORCE_INLINE agx::Vec3 getPosition() const { return getFrame()->getTranslate(); } \
663 AGX_FORCE_INLINE agx::Quat getRotation() const { return getFrame()->getRotate(); }
664
665} // namespace agx
666
667#ifdef _MSC_VER
668# pragma warning(pop)
669#endif
670
671#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
void postMult(const AffineMatrix4x4T< T > &)
void preMult(const AffineMatrix4x4T< T > &)
AffineMatrix4x4T< T > & setTranslate(const Vec3T< T > &t)
Set the translational part of the matrix using the vector t.
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:70
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
void transferDataIntoLeaves(bool keepLocalVelocity=true, bool clearTransform=true)
This method takes the transformation stored in this frame, and concatenates it to all of its children...
void setTranslate(const agx::Vec3 &translate)
Assign the final (world) translate of this frame.
Definition: agx/Frame.h:537
Quat getLocalRotate() const
void setMatrix(const agx::AffineMatrix4x4 &matrix)
This method will set the local matrix of this frame to be the matrix m multiplied with the inverse of...
Definition: agx/Frame.h:490
void setEntityData(agxData::AttributePtr< agx::AffineMatrix4x4 > localTransform, agxData::AttributePtr< agx::AffineMatrix4x4 > globalTransform)
Assign entity data.
void setRotate(const agx::Quat &rotation)
Assign the final (world) rotation of this frame.
void setAllowTransferIntoChildren(bool allow)
Specifies whether a transferDataIntoLeaves() operation will go into this frames children (including a...
Definition: agx/Frame.h:650
agx::Vec3 transformPointToLocal(const agx::Vec3 &pointWorld) const
Transform point from the world coordinate frame to this frame.
Definition: agx/Frame.h:626
const agx::AffineMatrix4x4 & getMatrix() const
agx::Vec3 transformVectorToWorld(const agx::Vec3 &vectorLocal) const
Transform vector from this frame to the world frame.
Definition: agx/Frame.h:568
void setLocalMatrix(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this frame ignoring any eventual parent transformation.
Definition: agx/Frame.h:526
agx::Vec3 transformVectorToLocal(const agx::Vec3 &worldVector) const
Transform vector from the world coordinate frame to this frame.
Definition: agx/Frame.h:606
agx::RigidBody * getRigidBody()
bool removeChild(agx::Frame *frame)
Remove a specified frame from the list of children.
const agx::RigidBody * getRigidBody() const
void setMatrixPointers(const agxData::AttributePtr< agx::AffineMatrix4x4 > &localTransform, const agxData::AttributePtr< agx::AffineMatrix4x4 > &globalTransform)
Internal method.
bool setParent(agx::Frame *frame)
Set the parent of this Frame.
void setRotate(const agx::OrthoMatrix3x3 &rotation)
Assign the final (world) rotation of this frame.
bool hasParent() const
Definition: agx/Frame.h:516
bool allowTransferDataIntoChildren() const
Definition: agx/Frame.h:645
void removeAllChildren()
Remove all children of this frame.
const agx::AffineMatrix4x4 & getLocalMatrix() const
Definition: agx/Frame.h:521
Frame()
Default constructor.
void transferChildren(agx::Frame *newParent)
Move all the frame children of this frame to the new parent while retaining the original global trans...
void updateLocalMatrix()
Internal method.
Definition: agx/Frame.h:500
agx::Vec3 getTranslate() const
Definition: agx/Frame.h:532
Frame(const agxData::AttributePtr< AffineMatrix4x4 > &localTransform, const agxData::AttributePtr< AffineMatrix4x4 > &globalTransform)
Frame with existing matrix storage.
void setLocalTranslate(const agx::Vec3 &translate)
Assign the parent relative translate of this frame.
Definition: agx/Frame.h:557
void setLocalRotate(const agx::Quat &rotation)
Assign the parent relative rotation of this frame.
agx::Vec3 getLocalTranslate() const
Definition: agx/Frame.h:552
agx::Vec3 transformPointToWorld(const agx::Vec3 &pointLocal) const
Transform point from this frame to the world frame.
Definition: agx/Frame.h:587
void setRotate(const agx::EulerAngles &euler)
Assign the final (world) rotation of this frame.
bool hasChildren() const
Definition: agx/Frame.h:655
agx::Quat getRotate() const
agx::Frame * getParent()
Definition: agx/Frame.h:506
bool isFinite() const
Frame(const agx::Frame &frame)
Copy constructor.
virtual ~Frame()
Protected destructor - reference counted object.
Frame(const agx::AffineMatrix4x4 matrix)
Instantiate a frame with relative transformation matrix.
void updateLocalMatrixSSE()
Internal method.
void setLocalRotate(const agx::EulerAngles &rotation)
Assign the parent relative rotation of this frame.
Vec3T< T > & transform3x3(const Vec3T< T > &vIn, Vec3T< T > &vOut) const
Definition: Matrix4x4.h:969
Vec3T< T > getTranslate() const
Definition: Matrix4x4.h:663
Specialized types of matrices for holding orthogonal transformation matrices.
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
bool empty() const
Return true if the container is empty.
Definition: SetVector.h:128
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:61
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
double Real
Definition: Real.h:42