AGXDynamics  2.35.0.2
PointGravityField.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
agx::Real
double Real
Definition: Real.h:42
agx::PointGravityField
The class PointGravityField calculates a gravity which is uniform in magnitude over the entire space ...
Definition: PointGravityField.h:33
agx::PointGravityField::calculateGravity
virtual Vec3 calculateGravity(const Vec3 &position) const override
Given position, a gravity acceleration will be calculated and returned.
Definition: PointGravityField.h:82
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::Task
A representation of a generic task.
Definition: Task.h:57
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agxModel::getCenter
AGXMODEL_EXPORT agx::Vec3 getCenter(const agxCollide::Mesh::Triangle &triangle)
agx::GRAVITY_ACCELERATION
const Real GRAVITY_ACCELERATION
Definition: Math.h:52
agx::PointGravityField::getCenter
Vec3 getCenter() const
Definition: PointGravityField.h:95
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::PointGravityField::getGravity
Real getGravity() const
Definition: PointGravityField.h:90
agxData::ValueRefT< Real >
GravityField.h
agx::Vec3T< Real >
agx::GravityField
The class GravityField is responsible for calculating and applying a gravity force on a set of bodies...
Definition: GravityField.h:38
agx::Vec3T::normalize
Real normalize()
Normalize the vector so that it has length unity.
Definition: Vec3Template.h:707
Value.h
agx::ref_ptr::get
T * get() const
Definition: ref_ptr.h:256