TDME2  1.9.200
ObjectParticleSystem.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
8 #include <tdme/engine/Engine.h>
9 #include <tdme/engine/Object.h>
10 #include <tdme/engine/Partition.h>
11 #include <tdme/engine/Transform.h>
12 
13 using std::string;
14 using std::vector;
15 
22 
23 ObjectParticleSystem::ObjectParticleSystem(const string& id, Model* model, const Vector3& scale, bool autoEmit, bool contributesShadows, bool receivesShadows, int32_t maxCount, ParticleEmitter* emitter) :
24  ObjectParticleSystemInternal(id, model, scale, autoEmit, contributesShadows, receivesShadows, maxCount, emitter)
25 {
26 }
27 
29 {
30  for (auto object: objects) object->setParentEntity(this);
31 }
32 
34 {
35  ObjectParticleSystemInternal::setTransform(transform);
36  //
37  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
38 }
39 
41 {
42  ObjectParticleSystemInternal::update();
43  //
44  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
45 }
46 
48 {
49  // return if enable state has not changed
50  if (this->enabled == enabled) return;
51  // frustum if root entity
52  if (parentEntity == nullptr) {
53  // frustum culling enabled?
54  if (frustumCulling == true) {
55  // yeo, add or remove from partition
56  if (enabled == true) {
57  if (engine != nullptr) engine->partition->addEntity(this);
58  } else {
59  if (engine != nullptr) engine->partition->removeEntity(this);
60  }
61  }
62  }
63  // call parent class::setEnabled()
64  ObjectParticleSystemInternal::setEnabled(enabled);
65 }
66 
68 {
69  ObjectParticleSystemInternal::updateParticles();
70  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
71 }
72 
74  return frustumCulling;
75 }
76 
77 void ObjectParticleSystem::setFrustumCulling(bool frustumCulling) {
78  // check if enabled and engine attached
79  if (enabled == true && engine != nullptr) {
80  // had frustum culling
81  if (this->frustumCulling == true) {
82  // yep, remove if set to false now
83  if (frustumCulling == false) engine->partition->removeEntity(this);
84  } else {
85  // yep, add if set to true now
86  if (frustumCulling == true) engine->partition->addEntity(this);
87  }
88  }
89  this->frustumCulling = frustumCulling;
90  // delegate change to engine
91  engine->registerEntity(this);
92 }
93 
94 void ObjectParticleSystem::setAutoEmit(bool autoEmit) {
95  if (this->isAutoEmit() == autoEmit) return;
96  // delegate to base class
97  ObjectParticleSystemInternal::setAutoEmit(autoEmit);
98  // delegate change to engine
99  engine->registerEntity(this);
100 }
101 
103 {
104  ObjectParticleSystemInternal::dispose();
105 }
106 
108 {
109  if (this->engine != nullptr) this->engine->deregisterEntity(this);
110  this->engine = engine;
111  if (engine != nullptr) engine->registerEntity(this);
112  ObjectParticleSystemInternal::setEngine(engine);
113 }
114 
116 {
117  ObjectParticleSystemInternal::setRenderer(renderer);
118 }
119 
Engine main class.
Definition: Engine.h:131
unique_ptr< Partition > partition
Definition: Engine.h:289
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
Definition: Engine.cpp:382
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Definition: Engine.cpp:437
Entity * parentEntity
Definition: Entity.h:39
Object particle system entity to be used with engine class.
void updateParticles() override
Updates the particle entity.
void dispose() override
Dispose this entity.
void initialize() override
Initiates this entity.
void update() override
Update transform.
void setTransform(const Transform &transform) override
Set transform.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setAutoEmit(bool autoEmit) override
Set auto emit.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
void setRenderer(Renderer *renderer) override
Set up renderer.
Object to be used with engine class.
Definition: Object.h:60
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Representation of a 3D model.
Definition: Model.h:35
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Partition interface.
Definition: Partition.h:18