TDME2  1.9.200
Decal.cpp
Go to the documentation of this file.
1 #include <tdme/engine/Decal.h>
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
7 #include <tdme/engine/Engine.h>
10 
11 using std::string;
12 
18 
19 Decal::Decal(const string& id, OrientedBoundingBox* obb, Texture* texture, int32_t textureHorizontalSprites, int32_t textureVerticalSprites, float fps):
20  DecalInternal(id, obb, texture, textureHorizontalSprites, textureVerticalSprites, fps)
21 {
22 }
23 
24 void Decal::setEngine(Engine* engine) {
25  if (this->engine != nullptr) this->engine->deregisterEntity(this);
26  this->engine = engine;
27  if (engine != nullptr) engine->registerEntity(this);
28  DecalInternal::setEngine(engine);
29 }
30 
31 void Decal::setTransform(const Transform& transform)
32 {
33  DecalInternal::setTransform(transform);
34  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
35 }
36 
38 {
39  DecalInternal::update();
40  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
41 }
42 
43 void Decal::setEnabled(bool enabled)
44 {
45  // return if enable state has not changed
46  if (this->enabled == enabled) return;
47 
48  // frustum if root entity
49  if (parentEntity == nullptr) {
50  // frustum culling enabled?
51  if (frustumCulling == true) {
52  // yeo, add or remove from partition
53  if (enabled == true) {
54  if (engine != nullptr) engine->partition->addEntity(this);
55  } else {
56  if (engine != nullptr) engine->partition->removeEntity(this);
57  }
58  }
59  }
60  // call parent class::setEnabled()
61  DecalInternal::setEnabled(enabled);
62 }
63 
64 void Decal::setFrustumCulling(bool frustumCulling) {
65  // check if enabled and engine attached
66  if (enabled == true && engine != nullptr) {
67  // had frustum culling
68  if (this->frustumCulling == true) {
69  // yep, remove if set to false now
70  if (frustumCulling == false) engine->partition->removeEntity(this);
71  } else {
72  // yep, add if set to true now
73  if (frustumCulling == true) engine->partition->addEntity(this);
74  }
75  }
76  this->frustumCulling = frustumCulling;
77  // delegate change to engine
78  if (engine != nullptr) engine->updateEntityRegistration(this);
79 }
80 
Decal entity to be used with engine class.
Definition: Decal.h:36
Engine * engine
Definition: Decal.h:41
void update() override
Update transform.
Definition: Decal.cpp:37
void setTransform(const Transform &transform) override
Set transform.
Definition: Decal.cpp:31
bool frustumCulling
Definition: Decal.h:42
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
Definition: Decal.cpp:64
void setEngine(Engine *engine) override
Set up engine.
Definition: Decal.cpp:24
void setEnabled(bool enabled) override
Enable/disable rendering.
Definition: Decal.cpp:43
Engine main class.
Definition: Engine.h:131
unique_ptr< Partition > partition
Definition: Engine.h:289
void updateEntityRegistration(Entity *entity)
Updates registration of engine by performing deregisterEntity() and registerEntity()
Definition: Engine.h:1489
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
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Oriented bounding box physics primitive.
Partition interface.
Definition: Partition.h:18