Momentum Scripting v1
Loading...
Searching...
No Matches
RigidBody.h
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 without having a written signed agreement with Algoryx Simulation AB.
9
10Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
11from using this software, unless otherwise stated in written agreements with
12Algoryx Simulation AB.
13*/
14
15#ifndef MOMENTUM_RIGIDBODY_H
16#define MOMENTUM_RIGIDBODY_H
17
18#include "momentum_export.h"
19#include "momentum_namespace.h"
20
21#include "macros.h"
22
23#include "Vec3.h"
24#include "AffineMatrix4x4.h"
25#include "Matrix3x3.h"
26#include "Geometry.h"
27#include "ContactPoint.h"
28
29
30#ifndef SWIG
32#ifndef SWIG
33namespace agx
34{
35 class RigidBody;
36}
37#endif
39#endif
40
41namespace MOMENTUM_NAMESPACE
42{
43#ifndef SWIG
44 class ContactPoint;
45 class Observer;
46#endif
47
51 class MOMENTUM_EXPORT RigidBody
52 {
53 public:
63 {
64 STATIC = 1,
65 KINEMATICS = 2,
66 DYNAMICS = 3
67 };
68
69 public:
70#ifndef SWIG
72
74 RigidBody(agx::RigidBody *);
76#endif
77
78#ifndef AGX_MOMENTUM_ANALYSIS_API
85 void setTransform(const AffineMatrix4x4& matrix);
86#endif
87
88#ifndef AGX_MOMENTUM_ANALYSIS_API
95 void setRotation(const Quat& q);
96
103 void setRotation(const EulerAngles* e);
104
105
112 void setPosition(const Vec3& p);
113
122 void setPosition(double x, double y, double z);
123#endif
124
130
136
142
146 bool isEmittedBody() const;
147
148#ifndef AGX_MOMENTUM_ANALYSIS_API
162 void setLinearVelocity(const Vec3& velocity);
163
177 void setLinearVelocity(double vx, double vy, double vz);
178
192 void setAngularVelocity(const Vec3& angularVelocity);
193
207 void setAngularVelocity(double vx, double vy, double vz);
208#endif
209
216
224
233 Vec3 getModelVelocity(const Vec3& relPos = Vec3()) const;
234
243 Vec3 getModelAcceleration(const Vec3& relPos = Vec3()) const;
244
245#ifndef AGX_MOMENTUM_ANALYSIS_API
253 void setEnable(bool enable);
254#endif
255
260 bool getEnable() const;
261
266
267#ifndef AGX_MOMENTUM_ANALYSIS_API
278#endif
279
288
297
301 std::string getName() const;
302
304 std::string __str__() const;
306
307 bool operator==(const RigidBody& other) const;
308
313
314#ifndef AGX_MOMENTUM_ANALYSIS_API
327 void setCmTransform(const AffineMatrix4x4& matrix);
328#endif
329
334
335#ifndef AGX_MOMENTUM_ANALYSIS_API
342 void setCmLocalTranslate(const Vec3& translate);
343#endif
344
349
350#ifndef AGX_MOMENTUM_ANALYSIS_API
359 void setCmPosition(const Vec3& p);
360
369 bool setCmAndInertiaInObserver(const Observer& observer, const Matrix3x3& inertia);
370#endif
371
372#ifndef AGX_MOMENTUM_ANALYSIS_API
382 void setForce(const Vec3& force);
383
393 void setForce(double fx, double fy, double fz);
394
404 void setTorque(const Vec3& torque);
405
415 void setTorque(double tx, double ty, double tz);
416
424 void addForce(const Vec3& force);
425
433 void addForce(double fx, double fy, double fz);
434
443 void addForceAtPosition(const Vec3& force, const Vec3& position);
444
453 void addForceAtPosition(double fx, double fy, double fz, double px, double py, double pz);
454
463 void addForceAtLocalPosition(const Vec3& force, const Vec3& position);
464
473 void addForceAtLocalPosition(double fx, double fy, double fz, double px, double py, double pz);
474
484 void addForceAtLocalCmPosition(const Vec3& force, const Vec3& position);
485
495 void addForceAtLocalCmPosition(double fx, double fy, double fz, double px, double py, double pz);
496
504 void addTorque(const Vec3& torque);
505
513 void addTorque(double tx, double ty, double tz);
514
522 void addLocalTorque(double tx, double ty, double tz);
523
531 void addLocalTorque(const Vec3& torque);
532
543 void moveTo(const AffineMatrix4x4& target, double t);
544
556 void moveTo(const Vec3& targetPosition, const Quat& targetRotation, double dt);
557
566 void setLinearVelocityDamping(double damping);
567
576 void setLinearVelocityDamping(const Vec3& damping);
577
586 void setAngularVelocityDamping(double damping);
587
596 void setAngularVelocityDamping(const Vec3& damping);
597
605 void setVelocityDamping(double damping);
606#endif
607
612
617
622
627
632
636 double getRotationalEnergy() const;
637
641 double getTotalEnergy() const;
642
648
654
658 size_t getNumConstraints() const;
659
663 Vec3 getForce() const;
664
669
674 double getMass();
675
676#ifndef AGX_MOMENTUM_ANALYSIS_API
683 void setMass(double mass);
684#endif
685
693
694#ifndef AGX_MOMENTUM_ANALYSIS_API
701 bool setInertia(Matrix3x3 inertia);
702#endif // ! AGX_MOMENTUM_ANALYSIS_API
703
704
710
711#ifndef SWIG
717 bool is(agx::RigidBody* body) const;
718
722 agx::RigidBody* body() const;
723#endif
729
731 virtual ~RigidBody();
733
734 protected:
735
737 RigidBody();
738
739 friend class Simulation;
740
741 private:
742#ifndef SWIG
743 agx::RigidBody *m_body;
744#endif
746
747 };
748
749 V1_DECLARE_CONTAINER_TYPE(RigidBody);
750
751} // namespace momentum
752#endif
Matrix class for rigid transformations (translation, rotation).
Definition: AffineMatrix4x4.h:51
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:64
Matrix class for inertia.
Definition: Matrix3x3.h:52
The Observer is a coordinate system which can be used to measure positions,velocities,...
Definition: Observer.h:46
The object holding quaternions and providing operations on these.
Definition: Quat.h:55
A rigid body is a moving (translation/rotation) object with a mass and a inertia.
Definition: RigidBody.h:52
void addForce(const Vec3 &force)
Adds the force, given in world coordinate system, that will be affecting this body in the next solve.
void setTransform(const AffineMatrix4x4 &matrix)
Set the transformation of the body in world coordinate system.
void setCmPosition(const Vec3 &p)
Assign new center of mass position, given in world coordinate frame.
Matrix3x3 getInertia()
Get the inertia of the rigid body in the specified coordinate system.
void addForce(double fx, double fy, double fz)
Adds the force, given in world coordinate system, that will be affecting this body in the next solve.
Vec3 getLinearVelocity() const
Velocity of center of mass in world coordinate system.
void setPosition(const Vec3 &p)
Set the position of the model frame in world coordinate system.
void setCmLocalTranslate(const Vec3 &translate)
Sets the local offset of the center of mass position to the model origin (in the local rigid body coo...
Quat getRotation() const
Current rigid body rotation, given in world coordinate system.
void addTorque(const Vec3 &torque)
Adds the torque, given in world coordinate system, that will be affecting this body in the next solve...
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:63
bool operator==(const RigidBody &other) const
AffineMatrix4x4 getCmTransform() const
void addLocalTorque(const Vec3 &torque)
Adds the torque, given in local coordinate system, that will be affecting this body in the next solve...
double getRotationalEnergy() const
void addTorque(double tx, double ty, double tz)
Adds the torque, given in world coordinate system, that will be affecting this body in the next solve...
double getTranslationalEnergy() const
void setAngularVelocityDamping(double damping)
Set angular velocity damping for the body in all directions x, y and z.
Vec3 getModelAcceleration(const Vec3 &relPos=Vec3()) const
Calculates the linear acceleration at the given point relPos.
Vec3 getAngularAcceleration() const
Will always be 0 for KINEMATIC and STATIC bodies.
Vec3 getAngularVelocityDamping() const
std::string getName() const
void setLinearVelocityDamping(double damping)
Set linear velocity damping for the body in all directions x, y and z.
void setMotionControl(RigidBody::MotionControl control)
Assign new motion control state to this rigid body.
void setForce(const Vec3 &force)
Explicitly set the force, given in world coordinate system, that will be affecting this body in the n...
Vec3 getModelVelocity(const Vec3 &relPos=Vec3()) const
Calculates the linear velocity at the given point relPos.
void setMass(double mass)
Set the mass of the rigid body in kilograms.
void moveTo(const Vec3 &targetPosition, const Quat &targetRotation, double dt)
Utility method to calculate and assign linear- and angular velocity given a target transform and the ...
void setForce(double fx, double fy, double fz)
Explicitly set the force, given in world coordinate system, that will be affecting this body in the n...
void setRotation(const Quat &q)
Set the rotation of the body relative to world coordinate system.
Vec3 getAngularVelocity() const
Angular velocity in world coordinate system.
void setRotation(const EulerAngles *e)
Set the rotation of the body relative to world coordinate system.
void addForceAtLocalCmPosition(const Vec3 &force, const Vec3 &position)
Add a force, given in world coordinate system, applied at a position relative to the center of mass.
AffineMatrix4x4 getTransform() const
Current rigid body transformation, given in world coordinate system.
bool getEnable() const
Access the state enable flag.
void setLinearVelocityDamping(const Vec3 &damping)
Give linear velocity damping in each direction, given in local body coordinate system.
Vec3 getLinearAcceleration() const
Will always be 0 for KINEMATIC and STATIC bodies.
size_t getNumConstraints() const
void setAngularVelocity(double vx, double vy, double vz)
Set the angular velocity of the center of mass of this rigid body.
Vec3 getLinearVelocityDamping() const
void setCmTransform(const AffineMatrix4x4 &matrix)
Assign new center of mass transform, given in world coordinate frame.
ContactPointVector getContacts() const
Get all contacts in which this rigid body is involved.
void addForceAtPosition(double fx, double fy, double fz, double px, double py, double pz)
Add a force, given in world coordinate system, applied at a position given in world coordinate system...
Vec3 getLastForce() const
Access the summed force applied to this rigid body last time the system was integrated.
void moveTo(const AffineMatrix4x4 &target, double t)
Utility method to calculate and assign linear- and angular velocity given a target transform and the ...
RigidBody::MotionControl getMotionControl() const
void setTorque(const Vec3 &torque)
Explicitly set the torque, given in world coordinate system, that will be affecting this body in the ...
void addForceAtLocalPosition(double fx, double fy, double fz, double px, double py, double pz)
Add a force, given in world coordinate system, applied at a position given in local rigid body coordi...
void setLinearVelocity(const Vec3 &velocity)
Set the linear velocity of the center of mass of this rigid body.
bool is(agx::RigidBody *body) const
Check if this a representation of the specified agx::RigidBody.
void addForceAtLocalCmPosition(double fx, double fy, double fz, double px, double py, double pz)
Add a force, given in world coordinate system, applied at a position relative to the center of mass.
void setVelocityDamping(double damping)
Set both linear- and angular velocity damping in all directions.
void setAngularVelocity(const Vec3 &angularVelocity)
Set the angular velocity of the center of mass of this rigid body.
agx::RigidBody * body() const
void addForceAtPosition(const Vec3 &force, const Vec3 &position)
Add a force, given in world coordinate system, applied at a position given in world coordinate system...
Vec3 getPosition() const
Current rigid body position, given in world coordinate system.
void setAngularVelocityDamping(const Vec3 &damping)
Give angular velocity damping in each direction, given in local body coordinate system.
void setTorque(double tx, double ty, double tz)
Explicitly set the torque, given in world coordinate system, that will be affecting this body in the ...
GeometryVector getGeometries() const
Get all geometries of the rigid body.
void addLocalTorque(double tx, double ty, double tz)
Adds the torque, given in local coordinate system, that will be affecting this body in the next solve...
bool setCmAndInertiaInObserver(const Observer &observer, const Matrix3x3 &inertia)
Assign a new center of mass and inertia tensor using an observer.
void addForceAtLocalPosition(const Vec3 &force, const Vec3 &position)
Add a force, given in world coordinate system, applied at a position given in local rigid body coordi...
double getMass()
Get the mass of the rigid body in kilograms.
Vec3 getLastTorque() const
Access the summed torque applied to this rigid body last time the system was integrated.
void setEnable(bool enable)
Change state enable of this rigid body.
void setPosition(double x, double y, double z)
Set the position of the model frame in world coordinate system.
void setLinearVelocity(double vx, double vy, double vz)
Set the linear velocity of the center of mass of this rigid body.
bool setInertia(Matrix3x3 inertia)
Set the inertia of the rigid body in the specified coordinate system.
This class is used to access an existing simulation with all its contents including joints,...
Definition: Simulation.h:70
A 3 dimensional vector which can be used to define a point or a vector and contains basic arithmetic.
Definition: Vec3.h:40
Namespace for Momentum Scripting API.
Definition: AffineMatrix4x4.h:29
std::vector< std::shared_ptr< ContactPoint > > ContactPointVector
A vector with objects of the type ContactPoint .
Definition: ContactPoint.h:43
std::vector< std::shared_ptr< Geometry > > GeometryVector
A vector with objects of the type Geometry .
Definition: Geometry.h:169