AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
PointGravityField.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#pragma once
17
18#include <agx/GravityField.h>
19
20#include <agxData/Value.h>
21
22namespace agx
23{
24
32 {
33 public:
39 PointGravityField( const Vec3& center = Vec3(), Real gravityMagnitude = agx::GRAVITY_ACCELERATION );
40
42 void setGravity( const Real gravityMagnitude );
43
44 //The point toward where gravity accelerates bodies (earthCenter if on earth)
45 void setCenter( const Vec3& center );
46
48 Real getGravity( ) const;
49
50
52 Vec3 getCenter( ) const;
53
59 virtual Vec3 calculateGravity( const Vec3& position ) const override;
60
61 public:
63 virtual Task* createRigidBodyTask() override;
64
66 virtual Task* createParticleSystemTask() override;
67
69
70
71 protected:
73
74 private:
77 };
78
80 inline Vec3 PointGravityField::calculateGravity( const Vec3& position) const
81 {
82 Vec3 pos = m_center->get() - position;
83 pos.normalize();
84
85 return pos * m_gravity->get();
86 }
87
89 {
90 return m_gravity->get();
91 }
92
94 {
95 return m_center->get();
96 }
97} //namespace agx
#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
Templated value-reference.
Definition: Value.h:263
The class GravityField is responsible for calculating and applying a gravity force on a set of bodies...
Definition: GravityField.h:38
The class PointGravityField calculates a gravity which is uniform in magnitude over the entire space ...
PointGravityField(const Vec3 &center=Vec3(), Real gravityMagnitude=agx::GRAVITY_ACCELERATION)
Constructor.
void setGravity(const Real gravityMagnitude)
Set the gravity direction/magnitude.
void setCenter(const Vec3 &center)
virtual Task * createRigidBodyTask() override
Internal use.
virtual ~PointGravityField()
virtual Vec3 calculateGravity(const Vec3 &position) const override
Given position, a gravity acceleration will be calculated and returned.
virtual Task * createParticleSystemTask() override
Internal use.
A representation of a generic task.
Definition: Task.h:58
Real normalize()
Normalize the vector so that it has length unity.
Definition: Vec3Template.h:701
T * get() const
Definition: ref_ptr.h:256
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
static constexpr Real GRAVITY_ACCELERATION
Definition: Math.h:52
double Real
Definition: Real.h:42