AGX Dynamics 2.41.2.0
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>
23#include <agx/BitArray.h>
24
26
27#include <agxCollide/Geometry.h>
28
29#include <agx/RigidBodyState.h>
30#include <agx/SetVector.h>
31
32#include <agx/macros.h>
33
34#ifdef _MSC_VER
35# pragma warning(push)
36# pragma warning(disable:4355) //Disable 'this' : used in base member initializer list warning
37#endif
38
39namespace agx
40{
41 class DynamicsSystem;
42 class InternalData;
43
47
52 {
53 public:
63 {
64 STATIC = 1,
65 KINEMATICS = 2,
66 DYNAMICS = 3
67 };
68
69 public:
76 RigidBody( const agx::Name& name = "" );
77
84
88 RigidBody *clone( bool shallowCopyRenderData=false ) const;
89
95 agx::Frame* getFrame();
96
102 const agx::Frame* getFrame() const;
103
109 void setTransform( const agx::AffineMatrix4x4& matrix );
110
115
121
126
131 void setLocalPosition( const agx::Vec3& p );
132
140
145 void setRotation( const agx::Quat& q );
146
152
158
163
168 void setLocalRotation( const agx::Quat& q );
169
175
180
185
199
204 void setPosition( const agx::Vec3& p );
205
213
222 agx::Frame* getCmFrame();
223
232 const agx::Frame* getCmFrame() const;
233
238 const agx::AffineMatrix4x4& getTransform() const;
239
244 CALLABLE_UNIT("m/s")
245 agx::Vec3 getPosition() const;
246
251 agx::Quat getRotation() const;
252
264 void setVelocity( const agx::Vec3& velocity );
265
277 void setVelocity( agx::Real vx, agx::Real vy, agx::Real vz );
278
290 void setAngularVelocity( const agx::Vec3& angularVelocity );
291
303 void setAngularVelocity( agx::Real vx, agx::Real vy, agx::Real vz );
304
310 agx::Vec3 getVelocity() const;
311
318 agx::Vec3 getAngularVelocity() const;
319
328 agx::Vec3 getModelVelocity( const agx::Vec3& relPos = agx::Vec3() ) const;
329
338 agx::Vec3 getModelAcceleration( const agx::Vec3& relPos = agx::Vec3() ) const;
339
345 void setEnable( bool enable );
346
351 bool getEnable() const;
352
357 bool isEnabled() const;
358
362 agx::RigidBody::MotionControl getMotionControl() const;
363
371 void setMotionControl( agx::RigidBody::MotionControl control );
372
376 agx::DynamicsSystem* getSystem();
377
381 const agx::DynamicsSystem* getSystem() const;
382
390 agx::Vec3 getLastForce() const;
391
399 agx::Vec3 getLastTorque() const;
400
411 agx::PropertyContainer* getPropertyContainer() const;
412
416 bool hasPropertyContainer() const;
417
422 void setPropertyContainer( agx::PropertyContainer* container );
423
427 const agx::Name& getName() const;
428
433 void setName( const agx::Name& name );
434
441 agx::UInt32 getId() const;
442
456 const agx::AffineMatrix4x4& getCmTransform() const;
457
468 void setCmTransform( const agx::AffineMatrix4x4& matrix, bool synchronizeModel = true );
469
473 agx::Vec3 getCmLocalTranslate() const;
474
479 void setCmLocalTranslate(const agx::Vec3& translate);
480
484 agx::Vec3 getCmPosition() const;
485
492 void setCmPosition( const agx::Vec3& p, bool synchronizeModel = true );
493
497 agx::Quat getCmRotation() const;
498
507 void setCmRotation( const agx::Quat& q);
508
517 void setCmRotation( const agx::EulerAngles& e);
518
527 void setCmRotation( const agx::OrthoMatrix3x3& m);
528
543 void setInertiaTensor( const agx::SPDMatrix3x3& inertiaTensor, const agx::AffineMatrix4x4& cmLocalTransform = agx::AffineMatrix4x4(), bool autogenerateCmOffset = false, bool autogenerateInertia = false );
544
560 void setInertiaTensor( const agx::Vec3& inertiaDiagonal, const agx::AffineMatrix4x4& cmLocalTransform = agx::AffineMatrix4x4(), bool autogenerateCmOffset = false, bool autogenerateInertia = false );
561
566 bool addAttachment( agx::Frame* frame, const agx::String& name );
567
572 bool removeAttachment( const agx::String& name );
573
579 Frame* getAttachment( const agx::String& name );
580
584 const agx::MassProperties* getMassProperties() const;
585
589 agx::MassProperties* getMassProperties();
590
598 void setForce( const agx::Vec3& force );
599
607 void setForce( agx::Real fx, agx::Real fy, agx::Real fz );
608
616 void setTorque( const agx::Vec3& torque );
617
625 void setTorque( agx::Real tx, agx::Real ty, agx::Real tz );
626
632 void addForce( const agx::Vec3& force );
633
639 void addForce( agx::Real fx, agx::Real fy, agx::Real fz );
640
647 void addForceAtPosition( const agx::Vec3& force, const agx::Vec3& position );
648
655 void addForceAtPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
656
663 void addForceAtLocalPosition( const agx::Vec3& force, const agx::Vec3& position );
664
671 void addForceAtLocalPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
672
679 void addForceAtLocalCmPosition( const agx::Vec3& force, const agx::Vec3& position );
680
687 void addForceAtLocalCmPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz );
688
694 void addTorque( const agx::Vec3& torque );
695
701 void addTorque( agx::Real tx, agx::Real ty, agx::Real tz );
702
708 void addLocalTorque( agx::Real tx, agx::Real ty, agx::Real tz );
709
715 void addLocalTorque( const agx::Vec3& torque );
716
736 bool add( agxCollide::Geometry* geometry , const agx::AffineMatrix4x4& localTransform, bool incrementalMassCalculation = false );
737
761 bool add( agxCollide::Geometry* geometry, bool incrementalMassCalculation = false );
762
773 bool remove( agxCollide::Geometry* geometry, bool incrementalMassCalculation = false );
774
780 const agxCollide::Geometry* getGeometry(const agx::Name& name) const;
781
788 agxCollide::Geometry* getGeometry(const agx::Name& name);
789
793 const agxCollide::GeometryRefVector& getGeometries() const;
794
804 void moveTo( const agx::AffineMatrix4x4& target, agx::Real t );
805
816 void moveTo( const agx::Vec3& targetPosition, const agx::Quat& targetRotation, agx::Real t );
817
824 void updateMassProperties();
825
836 void updateMassProperties( agx::UInt32 mask );
837
844 agx::Real calculateMass() const;
845
852 agx::Vec3 calculateCenterOfMassOffset( agx::Real mass = agx::Real() ) const;
853
859 void setLinearVelocityZeroDamping( const agx::Vec3f& dir );
860
866 void setAngularVelocityZeroDamping( const agx::Vec3f& dir );
867
872 agx::Vec3f getLinearVelocityZeroDamping() const;
873
878 agx::Vec3f getAngularVelocityZeroDamping() const;
879
886 void setLinearVelocityDamping( float damping );
887
894 void setLinearVelocityDamping( const agx::Vec3f& damping );
895
902 void setAngularVelocityDamping( float damping );
903
910 void setAngularVelocityDamping( const agx::Vec3f& damping );
911
917 void setVelocityDamping( float damping );
918
922 agx::Vec3f getLinearVelocityDamping() const;
923
927 agx::Vec3f getAngularVelocityDamping() const;
928
932 agx::Vec3 getLinearMomentum() const;
933
937 agx::Vec3 getAngularMomentum() const;
938
945 void setHandleAsParticle( bool handleAsParticle );
946
950 bool getHandleAsParticle() const;
951
956 agx::Vec3 getAcceleration() const;
957
962 agx::Vec3 getAngularAcceleration() const;
963
970 bool hasConstraints() const;
971
978 agx::UInt16 getNumConstraints() const;
979
984 agx::Referenced* getCustomData() const;
985
995 void setCustomData( agx::Referenced* data );
996
1001 agx::Physics::RigidBodyPtr getEntity() const;
1002
1007 void setEntity( agx::Physics::RigidBodyPtr entity );
1008
1013 void transfer( agxData::EntityStorage* storage );
1014
1018 agx::Vec3 getForce() const;
1019
1023 agx::Vec3 getTorque() const;
1024
1028 bool isPowerlineBody() const;
1029
1033 void setIsPowerlineBody(bool isHydraulicBody);
1034
1035#ifndef SWIG
1037 inline static bool shouldIgnoreGravity(agx::RigidBodyState state)
1038 {
1039 return !state.enabled() ||
1040 state.motionControl() != agx::RigidBody::DYNAMICS ||
1041 state.powerline();
1042 }
1043#endif
1044
1045
1046
1048
1050
1051 protected:
1052 friend class DynamicsSystem;
1053 friend class GeometryListener;
1055
1056 virtual ~RigidBody();
1057
1058 // Never use these
1061 RigidBody& operator = ( const agx::RigidBody& ) { return *this; }
1062
1067 void setId( agx::UInt32 id );
1068
1074
1081 void incrementalMassPropertyUpdate( agx::UInt32 mask, int sign, const agxCollide::Geometry* geometry );
1082
1083 private:
1084 void init( const agx::Name& name );
1085
1086 void incrementNumConstraints();
1087 void decrementNumConstraints();
1088 void resetNumConstraints();
1089
1090 void removeAllGeometries();
1091 void appendGeometry( agxCollide::Geometry* geometry );
1092 void removeGeometry( agx::Physics::GeometryPtr before, agx::Physics::GeometryPtr toBeRemoved );
1093
1095 friend class InternalData;
1099 agx::Referenced* getInternalData() const;
1100
1104 void setInternalData( agx::Referenced* data );
1106
1107 private:
1108 // Low level data.
1109 Physics::RigidBodyRef m_entity;
1110
1111 mutable PropertyContainerRef m_propertyContainer;
1112
1113 DynamicsSystem* m_mainSystem;
1114
1115 FrameRef m_frame;
1116 FrameRef m_cmFrame;
1117
1118 MassProperties m_massProperties;
1119
1120 agxCollide::GeometryRefVector m_geometries;
1121
1123 FrameTable m_namedAttachments;
1124
1125 agx::ref_ptr<agx::Referenced> m_customData;
1126 agx::ref_ptr<agx::Referenced> m_internalData;
1127 };
1128
1129 AGX_FORCE_INLINE bool RigidBody::getEnable() const
1130 {
1131 return m_entity.state().enabled();
1132 }
1133
1134 AGX_FORCE_INLINE bool RigidBody::isEnabled() const
1135 {
1136 return m_entity.state().enabled();
1137 }
1138
1139 AGX_FORCE_INLINE RigidBody::MotionControl RigidBody::getMotionControl() const
1140 {
1141 return (MotionControl)m_entity.state().motionControl();
1142 }
1143
1144 AGX_FORCE_INLINE bool RigidBody::hasPropertyContainer() const
1145 {
1146 return ( m_propertyContainer.isValid() );
1147 }
1148
1149 AGX_FORCE_INLINE agx::PropertyContainer* RigidBody::getPropertyContainer() const
1150 {
1151 if ( m_propertyContainer == nullptr )
1152 m_propertyContainer = new agx::PropertyContainer;
1153 return m_propertyContainer;
1154 }
1155
1156 inline Physics::RigidBodyPtr RigidBody::getEntity() const
1157 {
1158 return m_entity;
1159 }
1160
1161 AGX_FORCE_INLINE UInt32 RigidBody::getId() const
1162 {
1163 return m_entity.id();
1164 }
1165
1166 AGX_FORCE_INLINE Frame* RigidBody::getFrame()
1167 {
1168 return m_frame.get();
1169 }
1170
1171 AGX_FORCE_INLINE const Frame* RigidBody::getFrame() const
1172 {
1173 return m_frame.get();
1174 }
1175
1176 AGX_FORCE_INLINE Frame* RigidBody::getCmFrame()
1177 {
1178 return m_cmFrame.get();
1179 }
1180
1181 AGX_FORCE_INLINE const Frame* RigidBody::getCmFrame() const
1182 {
1183 return m_cmFrame.get();
1184 }
1185
1186 AGX_FORCE_INLINE const AffineMatrix4x4& RigidBody::getCmTransform() const
1187 {
1188 return m_entity.cmTransform();
1189 }
1190
1191 AGX_FORCE_INLINE Vec3 RigidBody::getVelocity() const
1192 {
1193 return m_entity.velocity();
1194 }
1195
1196 AGX_FORCE_INLINE Vec3 RigidBody::getAngularVelocity() const
1197 {
1198 return m_entity.angularVelocity();
1199 }
1200
1201 AGX_FORCE_INLINE Vec3 RigidBody::getCmLocalTranslate() const
1202 {
1203 return getCmFrame()->getLocalTranslate();
1204 }
1205
1206 AGX_FORCE_INLINE Vec3 RigidBody::getCmPosition() const
1207 {
1208 return getCmTransform().getTranslate();
1209 }
1210
1211 AGX_FORCE_INLINE Quat RigidBody::getCmRotation() const
1212 {
1213 return getCmTransform().getRotate();
1214 }
1215
1216 AGX_FORCE_INLINE MassProperties* RigidBody::getMassProperties()
1217 {
1218 return &m_massProperties;
1219 }
1220
1221 AGX_FORCE_INLINE const MassProperties* RigidBody::getMassProperties() const
1222 {
1223 return &m_massProperties;
1224 }
1225
1226 AGX_FORCE_INLINE bool RigidBody::getHandleAsParticle() const
1227 {
1228 return m_entity.state().handleAsParticle();
1229 }
1230
1231 AGX_FORCE_INLINE Vec3 RigidBody::getAcceleration() const
1232 {
1233 return m_entity.linearAcceleration();
1234 }
1235
1236 AGX_FORCE_INLINE Vec3 RigidBody::getAngularAcceleration() const
1237 {
1238 return m_entity.angularAcceleration();
1239 }
1240
1241 AGX_FORCE_INLINE bool RigidBody::hasConstraints() const
1242 {
1243 return m_entity.numConstraints() > 0;
1244 }
1245
1246 AGX_FORCE_INLINE UInt16 RigidBody::getNumConstraints() const
1247 {
1248 return m_entity.numConstraints();
1249 }
1250
1251 AGX_FORCE_INLINE Referenced* RigidBody::getCustomData() const
1252 {
1253 return m_customData.get();
1254 }
1255
1256 AGX_FORCE_INLINE const agx::AffineMatrix4x4& RigidBody::getTransform() const
1257 {
1258 return m_entity.modelTransform();
1259 }
1260
1261 AGX_FORCE_INLINE agx::Vec3 RigidBody::getPosition() const
1262 {
1263 return m_entity.modelTransform().getTranslate();
1264 }
1265
1266 AGX_FORCE_INLINE agx::Quat RigidBody::getRotation() const
1267 {
1268 return m_entity.modelTransform().getRotate();
1269 }
1270
1271 inline Referenced* RigidBody::getInternalData() const
1272 {
1273 return m_internalData;
1274 }
1275
1276 inline void RigidBody::setVelocity( agx::Real vx, agx::Real vy, agx::Real vz )
1277 {
1278 setVelocity(agx::Vec3(vx,vy,vz));
1279 }
1280
1281 inline void RigidBody::setAngularVelocity( agx::Real vx, agx::Real vy, agx::Real vz )
1282 {
1283 setAngularVelocity(agx::Vec3(vx,vy,vz));
1284 }
1285
1286 inline void RigidBody::addForce( agx::Real fx, agx::Real fy, agx::Real fz )
1287 {
1288 addForce( agx::Vec3(fx,fy,fz) );
1289 }
1290
1291 inline void RigidBody::addForceAtPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1292 {
1293 addForceAtPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1294 }
1295
1296 inline void RigidBody::addForceAtLocalPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1297 {
1298 addForceAtLocalPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1299 }
1300
1301 inline void RigidBody::addForceAtLocalCmPosition( agx::Real fx, agx::Real fy, agx::Real fz, agx::Real px, agx::Real py, agx::Real pz )
1302 {
1303 addForceAtLocalCmPosition( agx::Vec3(fx,fy,fz), agx::Vec3(px,py,pz) );
1304 }
1305
1306 inline void RigidBody::addTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1307 {
1308 addTorque( agx::Vec3(tx,ty,tz) );
1309 }
1310
1311 inline void RigidBody::addLocalTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1312 {
1313 addLocalTorque( agx::Vec3(tx, ty, tz) );
1314 }
1315
1316 inline void RigidBody::setForce( agx::Real fx, agx::Real fy, agx::Real fz )
1317 {
1318 setForce( agx::Vec3(fx,fy,fz) );
1319 }
1320
1321 inline void RigidBody::setTorque( agx::Real tx, agx::Real ty, agx::Real tz )
1322 {
1323 setTorque( agx::Vec3(tx,ty,tz) );
1324 }
1325
1326 inline bool RigidBody::isPowerlineBody() const
1327 {
1328 return m_entity.state().powerline();
1329 }
1330
1331 inline void RigidBody::setIsPowerlineBody(bool isHydraulicBody)
1332 {
1333 m_entity.state().setPowerline(isHydraulicBody);
1334 }
1335
1336} // namespace agx
1337
1338#ifdef _MSC_VER
1339# pragma warning(pop)
1340#endif
1341
1342#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
#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:45
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:52
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:63
@ DYNAMICS
This body moves from the influence of forces.
Definition: RigidBody.h:66
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:1037
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:49
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:42
agx::SetVector< ref_ptr< RigidBody > > RigidBodyRefSetVector
Definition: RigidBody.h:46
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.