AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
LinkedSegment.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
20
21#include <agx/RigidBody.h>
22#include <agx/Constraint.h>
23
24#include <agxUtil/agxUtil.h>
25
26namespace agxSDK
27{
30
39 {
40 public:
48 LinkedSegment( const agx::AffineMatrix4x4& transform, const agx::Vec3& halfExtents );
49
54
63
67 const agx::Vec3& getHalfExtents() const;
68
73
79
85
91
96
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 );
126
131 static LinkedSegment* get( agx::RigidBody* rb );
132
137 static const LinkedSegment* get( const agx::RigidBody* rb );
138
143 template<typename T>
144 static T* getT( agx::RigidBody* rb );
145
150 template<typename T>
151 static const T* getT( const agx::RigidBody* rb );
153
154 protected:
159 LinkedSegment(agx::RigidBody* body, const agx::Vec3& halfExtents, agx::Constraint* constraint);
160
164 virtual ~LinkedSegment();
165
166 void setHalfExtents(const agx::Vec3& halfExtens);
167 void setRigidBody(agx::RigidBody* body);
168 void setConstraint(agx::Constraint* constraint);
169
170 private:
171 friend class LinkedStructure;
172
177 LinkedStructureObjectData* getData() const;
178
182 void setIndex( agx::UInt index );
184
185 private:
186 agx::UInt m_index;
187 agx::RigidBodyRef m_rb;
188 agx::Vec3 m_halfExtents;
189 agx::ConstraintRef m_constraint;
190 };
191
192 inline agx::UInt LinkedSegment::getIndex() const
193 {
194 return m_index;
195 }
196
197 inline LinkedStructureObjectData* LinkedSegment::getData() const
198 {
199 return LinkedStructureObjectData::get<LinkedStructureObjectData>( m_rb );
200 }
201
202 inline LinkedStructure* LinkedSegment::getLinkedStructure() const
203 {
204 const auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( m_rb );
205 return data != nullptr ? data->linkedStructure : nullptr;
206 }
207
208 template<typename T>
209 T* LinkedSegment::createConstraintWithPrev( const LinkedSegment& prev,
210 const agx::Vec3& localConstraintAxis,
211 const agx::Vec3& localConstraintY,
212 agx::Bool disableCollisions )
213 {
214 agxAssert( m_constraint == nullptr );
215 if ( m_constraint != nullptr )
216 return nullptr;
217
218 const auto localConstraintX = localConstraintY ^ localConstraintAxis;
219 agx::OrthoMatrix3x3 localRotation = agx::OrthoMatrix3x3( localConstraintX.x(), localConstraintX.y(), localConstraintX.z(),
220 localConstraintY.x(), localConstraintY.y(), localConstraintY.z(),
221 localConstraintAxis.x(), localConstraintAxis.y(), localConstraintAxis.z() );
222
223 agx::FrameRef prevFrame = new agx::Frame();
224 agx::FrameRef thisFrame = new agx::Frame();
225
226 prevFrame->setLocalMatrix( agx::AffineMatrix4x4( localRotation,
227 agx::Vec3( 0, 0, prev.getLength() ) ) );
228 thisFrame->setLocalMatrix( agx::AffineMatrix4x4( localRotation, agx::Vec3( 0, 0, 0 ) ) );
229
230 m_constraint = new T( prev.getRigidBody(), prevFrame, getRigidBody(), thisFrame );
231
232 if ( disableCollisions )
233 agxUtil::setEnableCollisions( prev.getRigidBody(), getRigidBody(), false );
234
235 return m_constraint->as<T>();
236 }
237
238 inline LinkedSegment* LinkedSegment::get( agx::RigidBody* rb )
239 {
240 auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( rb );
241 if ( data == nullptr )
242 return nullptr;
243 return data->segment;
244 }
245
246 inline const LinkedSegment* LinkedSegment::get( const agx::RigidBody* rb )
247 {
248 const auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( rb );
249 if ( data == nullptr )
250 return nullptr;
251 return data->segment;
252 }
253
254 template<typename T>
255 T* LinkedSegment::getT( agx::RigidBody* rb )
256 {
257 auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( rb );
258 if ( data == nullptr || data->segment == nullptr )
259 return nullptr;
260 return data->segment->template asSafe<T>();
261 }
262
263 template<typename T>
264 const T* LinkedSegment::getT( const agx::RigidBody* rb )
265 {
266 const auto data = LinkedStructureObjectData::get<LinkedStructureObjectData>( rb );
267 if ( data == nullptr || data->segment == nullptr )
268 return nullptr;
269 return data->segment->template asSafe<T>();
270 }
271}
#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...
#define AGXPHYSICS_EXPORT
Segment object in a linked structure.
const agx::Vec3 & getHalfExtents() const
agx::Vec3 getEndPosition() const
LinkedSegment(const agx::AffineMatrix4x4 &transform, const agx::Vec3 &halfExtents)
Construct given transform and half extents of the shape.
agx::Constraint * getConstraint() const
Returns the constraint created between this segment and the previous one in the linked structure.
agx::Vec3 getDirection() const
agx::RigidBody * getRigidBody() const
agx::Real getLength() const
agx::Real getCurrentLength() const
agx::Vec3 getCenterPosition() const
agx::Vec3 getBeginPosition() const
Basic implementation of any structure where bodies are linked/constrained together in a well defined ...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
The base class for a constraint.
Definition Constraint.h:89
The object defining a frame of reference and providing transformations operations.
Definition agx/Frame.h:68
void setLocalMatrix(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this frame ignoring any eventual parent transformation.
Definition agx/Frame.h:526
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
#define agxAssert(expr)
Definition debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
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.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition Integer.h:40
uint64_t UInt
Definition Integer.h:27
double Real
Definition Real.h:42
Connection back from bodies, constraints etc.