AGX Dynamics 2.42.0.2
Loading...
Searching...
No Matches
RigidBody.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_RIGIDBODY_H
18#define AGX_RIGIDBODY_H
19
20#include <agx/agx.h>
21#include <agx/Frame.h>
22#include <agx/MassProperties.h>
24
25#include <agxCollide/Geometry.h>
26
27#include <agx/RigidBodyState.h>
28#include <agx/SetVector.h>
29#include <agx/macros.h>
30
31#ifdef _MSC_VER
32# pragma warning(push)
33# pragma warning(disable:4355) //Disable 'this' : used in base member initializer list warning
34#endif
35
36namespace agx
37{
38 class DynamicsSystem;
39 class InternalData;
40
44
49 {
50 public:
60 {
61 STATIC = 1,
62 KINEMATICS = 2,
63 DYNAMICS = 3
64 };
65
66 public:
73 RigidBody( const agx::Name& name = "" );
74
81
85 RigidBody *clone( bool shallowCopyRenderData=false ) const;
86
92 agx::Frame* getFrame();
93
99 const agx::Frame* getFrame() const;
100
106 void setTransform( const agx::AffineMatrix4x4& matrix );
107
112
118
123
128 void setLocalPosition( const agx::Vec3& p );
129
137
142 void setRotation( const agx::Quat& q );
143
149
155
160
165 void setLocalRotation( const agx::Quat& q );
166
172
177
182
196
201 void setPosition( const agx::Vec3& p );
202
210
219 agx::Frame* getCmFrame();
220
229 const agx::Frame* getCmFrame() const;
230
235 const agx::AffineMatrix4x4& getTransform() const;
236
241 CALLABLE_UNIT("m/s")
242 agx::Vec3 getPosition() const;
243
248 agx::Quat getRotation() const;
249
261 void setVelocity( const agx::Vec3& velocity );
262
274 void setVelocity( agx::Real vx, agx::Real vy, agx::Real vz );
275
287 void setAngularVelocity( const agx::Vec3& angularVelocity );
288
300 void setAngularVelocity( agx::Real vx, agx::Real vy, agx::Real vz );
301
307 agx::Vec3 getVelocity() const;
308
315 agx::Vec3 getAngularVelocity() const;
316
325 agx::Vec3 getModelVelocity( const agx::Vec3& relPos = agx::Vec3() ) const;
326
335 agx::Vec3 getModelAcceleration( const agx::Vec3& relPos = agx::Vec3() ) const;
336
342 void setEnable( bool enable );
343
348 bool getEnable() const;
349
354 bool isEnabled() const;
355
359 agx::RigidBody::MotionControl getMotionControl() const;
360
368 void setMotionControl( agx::RigidBody::MotionControl control );
369
373 agx::DynamicsSystem* getSystem();
374
378 const agx::DynamicsSystem* getSystem() const;
379
387 agx::Vec3 getLastForce() const;
388
396 agx::Vec3 getLastTorque() const;
397
408 agx::PropertyContainer* getPropertyContainer() const;
409
413 bool hasPropertyContainer() const;
414
419 void setPropertyContainer( agx::PropertyContainer* container );
420
424 const agx::Name& getName() const;
425
430 void setName( const agx::Name& name );
431
438 agx::UInt32 getId() const;
439
453 const agx::AffineMatrix4x4& getCmTransform() const;
454
465 void setCmTransform( const agx::AffineMatrix4x4& matrix, bool synchronizeModel = true );
466
470 agx::Vec3 getCmLocalTranslate() const;
471
476 void setCmLocalTranslate(const agx::Vec3& translate);
477
481 agx::Vec3 getCmPosition() const;
482
489 void setCmPosition( const agx::Vec3& p, bool synchronizeModel = true );
490
494 agx::Quat getCmRotation() const;
495
504 void setCmRotation( const agx::Quat& q);
505
514 void setCmRotation( const agx::EulerAngles& e);
515
524 void setCmRotation( const agx::OrthoMatrix3x3& m);
525
540 void setInertiaTensor( const agx::SPDMatrix3x3& inertiaTensor, const agx::AffineMatrix4x4& cmLocalTransform = agx::AffineMatrix4x4(), bool autogenerateCmOffset = false, bool autogenerateInertia = false );
541
557 void setInertiaTensor( const agx::Vec3& inertiaDiagonal, const agx::AffineMatrix4x4& cmLocalTransform = agx::AffineMatrix4x4(), bool autogenerateCmOffset = false, bool autogenerateInertia = false );
558
563 bool addAttachment( agx::Frame* frame, const agx::String& name );
564
569 bool removeAttachment( const agx::String& name );
570
576 Frame* getAttachment( const agx::String& name );
577
581 const agx::MassProperties* getMassProperties() const;
582
586 agx::MassProperties* getMassProperties();
587
595 void setForce( const agx::Vec3& force );
596
604 void setForce( agx::Real fx, agx::Real fy, agx::Real fz );
605
613 void setTorque( const agx::Vec3& torque );
614
622 void setTorque( agx::Real tx, agx::Real ty, agx::Real tz );
623
629 void addForce( const agx::Vec3& force );
630
636 void addForce( agx::Real fx, agx::Real fy, agx::Real fz );
637
644 void addForceAtPosition( const agx::Vec3& force, const agx::Vec3& position );
645
652 void addForceAtPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
653
660 void addForceAtLocalPosition( const agx::Vec3& force, const agx::Vec3& position );
661
668 void addForceAtLocalPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
669
676 void addForceAtLocalCmPosition( const agx::Vec3& force, const agx::Vec3& position );
677
684 void addForceAtLocalCmPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
685
691 void addTorque( const agx::Vec3& torque );
692
698 void addTorque( agx::Real tx, agx::Real ty, agx::Real tz );
699
705 void addLocalTorque( agx::Real tx, agx::Real ty, agx::Real tz );
706
712 void addLocalTorque( const agx::Vec3& torque );
713
733 bool add( agxCollide::Geometry* geometry , const agx::AffineMatrix4x4& localTransform, bool incrementalMassCalculation = false );
734
758 bool add( agxCollide::Geometry* geometry, bool incrementalMassCalculation = false );
759
770 bool remove( agxCollide::Geometry* geometry, bool incrementalMassCalculation = false );
771
777 const agxCollide::Geometry* getGeometry(const agx::Name& name) const;
778
785 agxCollide::Geometry* getGeometry(const agx::Name& name);
786
790 const agxCollide::GeometryRefVector& getGeometries() const;
791
801 void moveTo( const agx::AffineMatrix4x4& target, agx::Real t );
802
813 void moveTo( const agx::Vec3& targetPosition, const agx::Quat& targetRotation, agx::Real t );
814
821 void updateMassProperties();
822
833 void updateMassProperties( agx::UInt32 mask );
834
841 agx::Real calculateMass() const;
842
849 agx::Vec3 calculateCenterOfMassOffset( agx::Real mass = agx::Real() ) const;
850
856 void setLinearVelocityZeroDamping( const agx::Vec3f& dir );
857
863 void setAngularVelocityZeroDamping( const agx::Vec3f& dir );
864
869 agx::Vec3f getLinearVelocityZeroDamping() const;
870
875 agx::Vec3f getAngularVelocityZeroDamping() const;
876
883 void setLinearVelocityDamping( float damping );
884
891 void setLinearVelocityDamping( const agx::Vec3f& damping );
892
899 void setAngularVelocityDamping( float damping );
900
907 void setAngularVelocityDamping( const agx::Vec3f& damping );
908
914 void setVelocityDamping( float damping );
915
919 agx::Vec3f getLinearVelocityDamping() const;
920
924 agx::Vec3f getAngularVelocityDamping() const;
925
929 agx::Vec3 getLinearMomentum() const;
930
934 agx::Vec3 getAngularMomentum() const;
935
942 void setHandleAsParticle( bool handleAsParticle );
943
947 bool getHandleAsParticle() const;
948
953 agx::Vec3 getAcceleration() const;
954
959 agx::Vec3 getAngularAcceleration() const;
960
967 bool hasConstraints() const;
968
975 agx::UInt16 getNumConstraints() const;
976
981 agx::Referenced* getCustomData() const;
982
992 void setCustomData( agx::Referenced* data );
993
998 agx::Physics::RigidBodyPtr getEntity() const;
999
1004 void setEntity( agx::Physics::RigidBodyPtr entity );
1005
1010 void transfer( agxData::EntityStorage* storage );
1011
1015 agx::Vec3 getForce() const;
1016
1020 agx::Vec3 getTorque() const;
1021
1025 bool isPowerlineBody() const;
1026
1030 void setIsPowerlineBody(bool isHydraulicBody);
1031
1032#ifndef SWIG
1034 inline static bool shouldIgnoreGravity(agx::RigidBodyState state)
1035 {
1036 return !state.enabled() ||
1037 state.motionControl() != agx::RigidBody::DYNAMICS ||
1038 state.powerline();
1039 }
1040#endif
1041
1042
1043
1045
1047
1048 protected:
1049 friend class DynamicsSystem;
1050 friend class GeometryListener;
1052
1053 virtual ~RigidBody();
1054
1055 // Never use these
1058 RigidBody& operator = ( const agx::RigidBody& ) { return *this; }
1059
1064 void setId( agx::UInt32 id );
1065
1071
1078 void incrementalMassPropertyUpdate( agx::UInt32 mask, int sign, const agxCollide::Geometry* geometry );
1079
1080 private:
1081 void init( const agx::Name& name );
1082
1083 void incrementNumConstraints();
1084 void decrementNumConstraints();
1085 void resetNumConstraints();
1086
1087 void removeAllGeometries();
1088 void appendGeometry( agxCollide::Geometry* geometry );
1089 void removeGeometry( agx::Physics::GeometryPtr before, agx::Physics::GeometryPtr toBeRemoved );
1090
1092 friend class InternalData;
1096 agx::Referenced* getInternalData() const;
1097
1101 void setInternalData( agx::Referenced* data );
1103
1104 private:
1105 // Low level data.
1106 Physics::RigidBodyRef m_entity;
1107
1108 mutable PropertyContainerRef m_propertyContainer;
1109
1110 DynamicsSystem* m_mainSystem;
1111
1112 FrameRef m_frame;
1113 FrameRef m_cmFrame;
1114
1115 MassProperties m_massProperties;
1116
1117 agxCollide::GeometryRefVector m_geometries;
1118
1120 FrameTable m_namedAttachments;
1121
1122 agx::ref_ptr<agx::Referenced> m_customData;
1123 agx::ref_ptr<agx::Referenced> m_internalData;
1124 };
1125
1126 AGX_FORCE_INLINE bool RigidBody::getEnable() const
1127 {
1128 return m_entity.state().enabled();
1129 }
1130
1131 AGX_FORCE_INLINE bool RigidBody::isEnabled() const
1132 {
1133 return m_entity.state().enabled();
1134 }
1135
1136 AGX_FORCE_INLINE RigidBody::MotionControl RigidBody::getMotionControl() const
1137 {
1138 return (MotionControl)m_entity.state().motionControl();
1139 }
1140
1141 AGX_FORCE_INLINE bool RigidBody::hasPropertyContainer() const
1142 {
1143 return ( m_propertyContainer.isValid() );
1144 }
1145
1146 AGX_FORCE_INLINE agx::PropertyContainer* RigidBody::getPropertyContainer() const
1147 {
1148 if ( m_propertyContainer == nullptr )
1149 m_propertyContainer = new agx::PropertyContainer;
1150 return m_propertyContainer;
1151 }
1152
1153 inline Physics::RigidBodyPtr RigidBody::getEntity() const
1154 {
1155 return m_entity;
1156 }
1157
1158 AGX_FORCE_INLINE UInt32 RigidBody::getId() const
1159 {
1160 return m_entity.id();
1161 }
1162
1163 AGX_FORCE_INLINE Frame* RigidBody::getFrame()
1164 {
1165 return m_frame.get();
1166 }
1167
1168 AGX_FORCE_INLINE const Frame* RigidBody::getFrame() const
1169 {
1170 return m_frame.get();
1171 }
1172
1173 AGX_FORCE_INLINE Frame* RigidBody::getCmFrame()
1174 {
1175 return m_cmFrame.get();
1176 }
1177
1178 AGX_FORCE_INLINE const Frame* RigidBody::getCmFrame() const
1179 {
1180 return m_cmFrame.get();
1181 }
1182
1183 AGX_FORCE_INLINE const AffineMatrix4x4& RigidBody::getCmTransform() const
1184 {
1185 return m_entity.cmTransform();
1186 }
1187
1188 AGX_FORCE_INLINE Vec3 RigidBody::getVelocity() const
1189 {
1190 return m_entity.velocity();
1191 }
1192
1193 AGX_FORCE_INLINE Vec3 RigidBody::getAngularVelocity() const
1194 {
1195 return m_entity.angularVelocity();
1196 }
1197
1198 AGX_FORCE_INLINE Vec3 RigidBody::getCmLocalTranslate() const
1199 {
1200 return getCmFrame()->getLocalTranslate();
1201 }
1202
1203 AGX_FORCE_INLINE Vec3 RigidBody::getCmPosition() const
1204 {
1205 return getCmTransform().getTranslate();
1206 }
1207
1208 AGX_FORCE_INLINE Quat RigidBody::getCmRotation() const
1209 {
1210 return getCmTransform().getRotate();
1211 }
1212
1213 AGX_FORCE_INLINE MassProperties* RigidBody::getMassProperties()
1214 {
1215 return &m_massProperties;
1216 }
1217
1218 AGX_FORCE_INLINE const MassProperties* RigidBody::getMassProperties() const
1219 {
1220 return &m_massProperties;
1221 }
1222
1223 AGX_FORCE_INLINE bool RigidBody::getHandleAsParticle() const
1224 {
1225 return m_entity.state().handleAsParticle();
1226 }
1227
1228 AGX_FORCE_INLINE Vec3 RigidBody::getAcceleration() const
1229 {
1230 return m_entity.linearAcceleration();
1231 }
1232
1233 AGX_FORCE_INLINE Vec3 RigidBody::getAngularAcceleration() const
1234 {
1235 return m_entity.angularAcceleration();
1236 }
1237
1238 AGX_FORCE_INLINE bool RigidBody::hasConstraints() const
1239 {
1240 return m_entity.numConstraints() > 0;
1241 }
1242
1243 AGX_FORCE_INLINE UInt16 RigidBody::getNumConstraints() const
1244 {
1245 return m_entity.numConstraints();
1246 }
1247
1248 AGX_FORCE_INLINE Referenced* RigidBody::getCustomData() const
1249 {
1250 return m_customData.get();
1251 }
1252
1253 AGX_FORCE_INLINE const agx::AffineMatrix4x4& RigidBody::getTransform() const
1254 {
1255 return m_entity.modelTransform();
1256 }
1257
1258 AGX_FORCE_INLINE agx::Vec3 RigidBody::getPosition() const
1259 {
1260 return m_entity.modelTransform().getTranslate();
1261 }
1262
1263 AGX_FORCE_INLINE agx::Quat RigidBody::getRotation() const
1264 {
1265 return m_entity.modelTransform().getRotate();
1266 }
1267
1268 inline Referenced* RigidBody::getInternalData() const
1269 {
1270 return m_internalData;
1271 }
1272
1273 inline void RigidBody::setVelocity( agx::Real vx, agx::Real vy, agx::Real vz )
1274 {
1275 setVelocity(agx::Vec3(vx,vy,vz));
1276 }
1277
1278 inline void RigidBody::setAngularVelocity( agx::Real vx, agx::Real vy, agx::Real vz )
1279 {
1280 setAngularVelocity(agx::Vec3(vx,vy,vz));
1281 }
1282
1283 inline void RigidBody::addForce( agx::Real fx, agx::Real fy, agx::Real fz )
1284 {
1285 addForce( agx::Vec3(fx,fy,fz) );
1286 }
1287
1288 inline void RigidBody::addForceAtPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1289 {
1290 addForceAtPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1291 }
1292
1293 inline void RigidBody::addForceAtLocalPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1294 {
1295 addForceAtLocalPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1296 }
1297
1298 inline void RigidBody::addForceAtLocalCmPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1299 {
1300 addForceAtLocalCmPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1301 }
1302
1303 inline void RigidBody::addTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1304 {
1305 addTorque( agx::Vec3(tx,ty,tz) );
1306 }
1307
1308 inline void RigidBody::addLocalTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1309 {
1310 addLocalTorque( agx::Vec3(tx, ty, tz) );
1311 }
1312
1313 inline void RigidBody::setForce( agx::Real fx, agx::Real fy, agx::Real fz )
1314 {
1315 setForce( agx::Vec3(fx,fy,fz) );
1316 }
1317
1318 inline void RigidBody::setTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1319 {
1320 setTorque( agx::Vec3(tx,ty,tz) );
1321 }
1322
1323 inline bool RigidBody::isPowerlineBody() const
1324 {
1325 return m_entity.state().powerline();
1326 }
1327
1328 inline void RigidBody::setIsPowerlineBody(bool isHydraulicBody)
1329 {
1330 m_entity.state().setPowerline(isHydraulicBody);
1331 }
1332
1333} // namespace agx
1334
1335#ifdef _MSC_VER
1336# pragma warning(pop)
1337#endif
1338
1339#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:207
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
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:44
The complete physical system with bodies, interactions, data layout, time stepper,...
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
Internal data for any object, ObjT, with methods: agx::Referenced* ObjT::getInternalData() const; voi...
Definition: InternalData.h:33
Inheritance with partial specialization due to bug with ref_ptr containers.
Class for rigid body inertia tensor and mass.
Representation of a name string.
Definition: Name.h:33
Specialized types of matrices for holding orthogonal transformation matrices.
Pointer to a entity instance of type Physics.Geometry.
Pointer to a entity instance of type Physics.RigidBody.
Class that is a container of named properties.
Definition: Property.h:129
void getRotate(T &angle, T &x, T &y, T &z) const
Get the angle and vector components represented by the quaternion.
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:49
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:60
@ DYNAMICS
This body moves from the influence of forces.
Definition: RigidBody.h:63
void setLocalPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the body relative to its model frame's parent frame.
void setLocalRotation(const agx::Quat &q)
Set the rotation of the body relative to its model frame's parent frame.
bool hasValidEntityIndex() const
void setLocalTransform(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this body, ignoring any eventual parent transformation.
void setPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the model frame in world coordinates.
const agx::AffineMatrix4x4 & getLocalTransform() const
void setRotation(const agx::Quat &q)
Set the rotation of the body relative to world frame.
void setSystem(agx::DynamicsSystem *system)
Assign dynamics system where this body belongs to.
const agx::Frame * getParentFrame() const
void incrementalMassPropertyUpdate(agx::UInt32 mask, int sign, const agxCollide::Geometry *geometry)
Will calculate new mass properties for this rigid body as the previously calculated one +/- the speci...
RigidBody(agxCollide::Geometry *geometry)
Construct given geometry.
void setTransform(const agx::AffineMatrix4x4 &matrix)
Set the transform of the body.
agx::Frame * getParentFrame()
RigidBody * clone(bool shallowCopyRenderData=false) const
Create a clone of the rigid body.
void setRotation(const agx::OrthoMatrix3x3 &m)
Set the rotation of the body relative to world frame.
RigidBody(const agx::Name &name, agx::Physics::RigidBodyPtr entity)
bool setParentFrame(agx::Frame *frame)
Set the parent frame of this body's model frame.
void setPosition(const agx::Vec3 &p)
Set the position of the model frame in world coordinates.
void setRotation(const agx::EulerAngles &e)
Set the rotation of the body relative to world frame.
void setId(agx::UInt32 id)
Assign dynamics system unique id to this rigid body.
RigidBody(const agx::Name &name="")
Construct given name.
void setLocalPosition(const agx::Vec3 &p)
Set the position of the body relative to its model frame's parent frame.
static bool shouldIgnoreGravity(agx::RigidBodyState state)
Definition: RigidBody.h:1034
virtual ~RigidBody()
void setLocalRotation(const agx::EulerAngles &e)
Set the rotation of the body relative to its model frame's parent frame.
RigidBody(const agx::RigidBody &)
agx::Vec3 getLocalPosition() const
agx::Quat getLocalRotation() const
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
#define CALLABLE_UNIT(param)
Definition: macros.h:73
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define CALLABLE
Definition: macros.h:72
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contains classes for low level data storage for AGX.
Definition: Container.h:23
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:31
uint32_t UInt32
Definition: Integer.h:32
double Real
Definition: Real.h:41
agx::SetVector< ref_ptr< RigidBody > > RigidBodyRefSetVector
Definition: RigidBody.h:43
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.