AGXDynamics  2.31.1.0
LinkedSegment.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 #pragma once
18 
20 
21 #include <agx/RigidBody.h>
22 #include <agx/Constraint.h>
23 
24 #include <agxUtil/agxUtil.h>
25 
26 namespace agxSDK
27 {
30 
39  {
40  public:
48  LinkedSegment( const agx::AffineMatrix4x4& transform, const agx::Vec3& halfExtents );
49 
53  agx::RigidBody* getRigidBody() const;
54 
62  agx::Constraint* getConstraint() const;
63 
67  const agx::Vec3& getHalfExtents() const;
68 
72  agx::Real getLength() const;
73 
78  agx::Real getCurrentLength() const;
79 
84  agx::Vec3 getBeginPosition() const;
85 
90  agx::Vec3 getEndPosition() const;
91 
95  agx::Vec3 getCenterPosition() const;
96 
100  agx::Vec3 getDirection() const;
101 
105  agx::UInt getIndex() const;
106 
110  agxSDK::LinkedStructure* getLinkedStructure() const;
111 
112  public:
114 
121  template<typename T>
122  T* createConstraintWithPrev( const agxSDK::LinkedSegment& prev,
123  const agx::Vec3& localConstraintAxis,
124  const agx::Vec3& localConstraintY,
125  agx::Bool disableCollisions );
127 
128  protected:
132  LinkedSegment();
133  LinkedSegment(agx::RigidBody* body, const agx::Vec3& halfExtents, agx::Constraint* constraint);
134 
138  virtual ~LinkedSegment();
139 
140  void setHalfExtents(const agx::Vec3& halfExtens);
141  void setRigidBody(agx::RigidBody* body);
142  void setConstraint(agx::Constraint* constraint);
143 
144  private:
145  friend class LinkedStructure;
146 
151  LinkedStructureObjectData* getData() const;
152 
156  void setIndex( agx::UInt index );
158 
159  private:
160  agx::UInt m_index;
161  agx::RigidBodyRef m_rb;
162  agx::Vec3 m_halfExtents;
163  agx::ConstraintRef m_constraint;
164  };
165 
166  inline agx::UInt LinkedSegment::getIndex() const
167  {
168  return m_index;
169  }
170 
171  inline LinkedStructureObjectData* LinkedSegment::getData() const
172  {
173  return LinkedStructureObjectData::get<LinkedStructureObjectData>( m_rb );
174  }
175 
177  {
178  const auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( m_rb );
179  return data != nullptr ? data->linkedStructure : nullptr;
180  }
181 
182  template<typename T>
183  T* LinkedSegment::createConstraintWithPrev( const LinkedSegment& prev,
184  const agx::Vec3& localConstraintAxis,
185  const agx::Vec3& localConstraintY,
186  agx::Bool disableCollisions )
187  {
188  agxAssert( m_constraint == nullptr );
189  if ( m_constraint != nullptr )
190  return nullptr;
191 
192  const auto localConstraintX = localConstraintY ^ localConstraintAxis;
193  agx::OrthoMatrix3x3 localRotation = agx::OrthoMatrix3x3( localConstraintX.x(), localConstraintX.y(), localConstraintX.z(),
194  localConstraintY.x(), localConstraintY.y(), localConstraintY.z(),
195  localConstraintAxis.x(), localConstraintAxis.y(), localConstraintAxis.z() );
196 
197  agx::FrameRef prevFrame = new agx::Frame();
198  agx::FrameRef thisFrame = new agx::Frame();
199 
200  prevFrame->setLocalMatrix( agx::AffineMatrix4x4( localRotation,
201  agx::Vec3( 0, 0, prev.getLength() ) ) );
202  thisFrame->setLocalMatrix( agx::AffineMatrix4x4( localRotation, agx::Vec3( 0, 0, 0 ) ) );
203 
204  m_constraint = new T( prev.getRigidBody(), prevFrame, getRigidBody(), thisFrame );
205 
206  if ( disableCollisions )
207  agxUtil::setEnableCollisions( prev.getRigidBody(), getRigidBody(), false );
208 
209  return m_constraint->as<T>();
210  }
211 }
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
bool Bool
Definition: Integer.h:48
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:86
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
void setLocalMatrix(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this frame ignoring any eventual parent transformation...
Definition: Frame.h:526
Base class providing referencing counted objects.
Definition: Referenced.h:113
agx::ref_ptr< Constraint > ConstraintRef
Definition: Constraint.h:53
uint32_t UInt
Definition: Integer.h:34
Namespace agx contains the dynamics/math part of the AGX Dynamics API.
agx::Real getLength() const
agx::RigidBody * getRigidBody() const
#define agxAssert(expr)
Definition: debug.h:143
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2...
agx::ref_ptr< RigidBody > RigidBodyRef
Definition: RigidBody.h:46
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:206
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Segment object in a linked structure.
Definition: LinkedSegment.h:38
Connection back from bodies, constraints etc.
double Real
Definition: Real.h:42
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::LinkedStructure * getLinkedStructure() const
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:102
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101
Specialized types of matrices for holding orthogonal transformation matrices.