AGX Dynamics  2.37.3.2
PointGravityField.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #ifndef AGX_POINTGRAVITYFIELD_H
18 #define AGX_POINTGRAVITYFIELD_H
19 
20 #include <agx/GravityField.h>
21 
22 #include <agxData/Value.h>
23 
24 namespace agx
25 {
26 
34  {
35  public:
41  PointGravityField( const Vec3& center = Vec3(), Real gravityMagnitude = agx::GRAVITY_ACCELERATION );
42 
44  void setGravity( const Real gravityMagnitude );
45 
46  //The point toward where gravity accelerates bodies (earthCenter if on earth)
47  void setCenter( const Vec3& center );
48 
50  Real getGravity( ) const;
51 
52 
54  Vec3 getCenter( ) const;
55 
61  virtual Vec3 calculateGravity( const Vec3& position ) const override;
62 
63  public:
65  virtual Task* createRigidBodyTask() override;
66 
68  virtual Task* createParticleSystemTask() override;
69 
71 
72 
73  protected:
74  virtual ~PointGravityField();
75 
76  private:
77  agxData::ValueRefT<Real> m_gravity;
78  agxData::ValueRefT<Vec3> m_center;
79  };
80 
82  inline Vec3 PointGravityField::calculateGravity( const Vec3& position) const
83  {
84  Vec3 pos = m_center->get() - position;
85  pos.normalize();
86 
87  return pos * m_gravity->get();
88  }
89 
91  {
92  return m_gravity->get();
93  }
94 
96  {
97  return m_center->get();
98  }
99 } //namespace agx
100 
101 
102 
103 
104 
105 
106 #endif
107 
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
#define AGXPHYSICS_EXPORT
const Real GRAVITY_ACCELERATION
Definition: Math.h:52
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
A representation of a generic task.
Definition: Task.h:57
AGXMODEL_EXPORT agx::Vec3 getCenter(const agxCollide::Mesh::Triangle &triangle)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
virtual Vec3 calculateGravity(const Vec3 &position) const override
Given position, a gravity acceleration will be calculated and returned.
Real normalize()
Normalize the vector so that it has length unity.
Definition: Vec3Template.h:701
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:45
#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
The class GravityField is responsible for calculating and applying a gravity force on a set of bodies...
Definition: GravityField.h:38
double Real
Definition: Real.h:42
The class PointGravityField calculates a gravity which is uniform in magnitude over the entire space ...