AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
RigidBodyEmitter.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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
18#ifndef AGX_RIGIDBODY_EMITTER_H
19#define AGX_RIGIDBODY_EMITTER_H
20
21#include <agx/Emitter.h>
22#include <agx/InternalData.h>
23#include <agx/BitState.h>
24#include <agx/ICloneable.h>
25#include <agx/ObserverFrame.h>
26
27namespace agxSDK
28{
29 class Simulation;
30}
31
32
33namespace agx
34{
37
44 {
45 private:
50 struct RigidBodyEmitterInternalData : public agx::ICloneable
51 {
52 enum EState
53 {
54 CREATED_BY_RIGIDBODYEMITTER = 1 << 0,
55 CREATED_BY_SNAPSHOT_LOADING = 1 << 1,
56 IS_BODYMODEL_TEMPLATE = 1 << 2
57 };
58 typedef agx::BitState< EState, agx::Int32 > State;
59
60 RigidBodyEmitterInternalData() : state() {}
61
62 State state;
63 protected:
64 virtual ~RigidBodyEmitterInternalData() {}
65
66 private:
67 virtual agx::ICloneableRef clone(agx::ICloneable* child) override
68 {
69 if (child == nullptr)
70 child = new RigidBodyEmitterInternalData();
71
72 child->as<RigidBodyEmitterInternalData>()->state = this->state;
73
74 return agx::ICloneableRef(child);
75 }
76 };
77 public:
78
79
80 AGX_DECLARE_POINTER_TYPES( DistributionModel );
81
84
85 public:
86
91 RigidBodyEmitter(Quantity quantity = QUANTITY_COUNT);
92
102 const agx::Vec3& spacing,
103 agx::Real jitterfactor = agx::Real(0));
104
108 static bool rigidBodyIsEmitted( const agx::RigidBody * body );
109
113 static bool rigidBodyIsLoaded( const agx::RigidBody * body );
114
120 static bool rigidBodyIsTemplate(const agx::RigidBody* body);
121
128 static void setRigidBodyIsEmitted( agx::RigidBody * body, bool isEmitted );
129
136 static void setRigidBodyIsLoaded( agx::RigidBody * body, bool isLoaded );
137
148 static void setRigidBodyIsTemplate(agx::RigidBody* body, bool isTemplate);
149
155
157
158 static void storePersistentData(const agx::RigidBody* rb, agxStream::OutputArchive& out);
159
160 static void restorePersistentData(agx::RigidBody* rb, agxStream::InputArchive& in);
161
163
164 private:
165 static RigidBodyEmitterInternalData* getRigidBodyEmitterData(const agx::RigidBody* obj);
166
167 static RigidBodyEmitterInternalData* getOrCreateRigidBodyEmitterData(agx::RigidBody* obj);
168
170
171 protected:
172
175
176 virtual void emitBody(const Vec3& position,
177 const Quat& rotation,
178 const Vec3& velocity,
179 Emitter::DistributionModel *model) override;
180 virtual bool preEmit() override;
181 virtual void postEmit() override;
182
183 virtual void transfer(agxSDK::Simulation *simulation) override;
184
185 private:
186 // Creates and initializes the parameters.
187 void init();
188
189
190
191 private:
192 agxSDK::Simulation *m_simulation;
193 };
194
198 class AGXPHYSICS_EXPORT RigidBodyEmitter::DistributionModel : public Emitter::DistributionModel
199 {
200 public:
205
218 agx::Real probabilityWeight,
219 agx::ObserverFrame* placementObserver=nullptr);
220
225
231
233
235
237
238 protected:
239 virtual ~DistributionModel();
240 virtual agx::Real calculateVolume() override;
241 virtual agx::Real calculateMass() override;
242
243 private:
244 agx::RigidBodyRef m_bodyTemplate;
245 agx::ObserverFrameRef m_placementObserver;
246 };
247}
248
249#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...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
Spawns new bodys inside a given volume.
Definition Emitter.h:45
friend class DistributionTable
Definition Emitter.h:388
An event with three arguments.
Definition Event.h:141
Interface class for a cloneable reference counted object.
Definition ICloneable.h:30
With this class you can attach an ObserverFrame object relative to a RigidBody.
T * as()
Subclass casting.
Spawns new Rigid Bodies inside a volume given to the Emitter.
agx::ObserverFrame * getPlacementObserver() const
static void setRigidBodyIsLoaded(agx::RigidBody *body, bool isLoaded)
Manually override setting that specifies if a RigidBody was loaded from an snapshot.
static void setRigidBodyIsEmitted(agx::RigidBody *body, bool isEmitted)
Manually override setting that specifies if a RigidBody was created from an Emitter.
static agx::RigidBodyPtrVector getEmittedBodiesInSimulation(agxSDK::Simulation *simulation)
static agx::RigidBodyRefVector spawnBodiesInBound(const agx::Bound3 &bound, agx::Emitter::DistributionTable *sourceTable, const agx::Vec3 &spacing, agx::Real jitterfactor=agx::Real(0))
Spawn Rigid Bodies inside a 3D bound based on a specified distribution table of rigid bodies.
DistributionModel(agx::RigidBody *bodyTemplate, agx::Real probabilityWeight, agx::ObserverFrame *placementObserver=nullptr)
Create a Rigid Body Distribution model for usage in the Emitter::DistributionTable class.
static bool rigidBodyIsLoaded(const agx::RigidBody *body)
static bool rigidBodyIsEmitted(const agx::RigidBody *body)
agx::RigidBody * getBodyTemplate()
DistributionModel()
Default constructor.
static bool rigidBodyIsTemplate(const agx::RigidBody *body)
Event3< RigidBodyEmitter *, agx::RigidBody *, DistributionModel * > Event
RigidBodyEmitter(Quantity quantity=QUANTITY_COUNT)
Default constructor for a RigidBodyEmitter.
static void setRigidBodyIsTemplate(agx::RigidBody *body, bool isTemplate)
Set state bit in the RigidBodyEmitterData for the specifed RigidBody that signals if it is used as a ...
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real
Definition Real.h:42
agx::ref_ptr< ICloneable > ICloneableRef
Definition ICloneable.h:24