TDME2  1.9.200
Lines.cpp
Go to the documentation of this file.
1 #include <tdme/engine/Lines.h>
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
8 #include <tdme/engine/Engine.h>
10 #include <tdme/engine/Transform.h>
11 #include <tdme/math/Matrix4x4.h>
12 #include <tdme/math/Quaternion.h>
13 #include <tdme/math/Vector3.h>
14 
15 using std::string;
16 
24 
25 Lines::Lines(const string& id, float lineWidth, const vector<Vector3>& points, const Color4& color, const vector<Color4>& colors, Texture* texture):
26  LinesInternal(id, lineWidth, points, color, colors, texture)
27 {
28 }
29 
30 void Lines::setEngine(Engine* engine) {
31  if (this->engine != nullptr) this->engine->deregisterEntity(this);
32  this->engine = engine;
33  if (engine != nullptr) engine->registerEntity(this);
34  LinesInternal::setEngine(engine);
35 }
36 
37 void Lines::setTransform(const Transform& transform)
38 {
39  LinesInternal::setTransform(transform);
40  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
41 }
42 
44 {
45  LinesInternal::update();
46  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
47 }
48 
49 void Lines::setEnabled(bool enabled)
50 {
51  // return if enable state has not changed
52  if (this->enabled == enabled) return;
53 
54  // frustum if root entity
55  if (parentEntity == nullptr) {
56  // frustum culling enabled?
57  if (frustumCulling == true) {
58  // yeo, add or remove from partition
59  if (enabled == true) {
60  if (engine != nullptr) engine->partition->addEntity(this);
61  } else {
62  if (engine != nullptr) engine->partition->removeEntity(this);
63  }
64  }
65  }
66  // call parent class::setEnabled()
67  LinesInternal::setEnabled(enabled);
68 }
69 
70 void Lines::setFrustumCulling(bool frustumCulling) {
71  // check if enabled and engine attached
72  if (enabled == true && engine != nullptr) {
73  // had frustum culling
74  if (this->frustumCulling == true) {
75  // yep, remove if set to false now
76  if (frustumCulling == false) engine->partition->removeEntity(this);
77  } else {
78  // yep, add if set to true now
79  if (frustumCulling == true) engine->partition->addEntity(this);
80  }
81  }
82  this->frustumCulling = frustumCulling;
83  // delegate change to engine
84  if (engine != nullptr) engine->updateEntityRegistration(this);
85 }
86 
Color 4 definition class.
Definition: Color4.h:18
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
Lines entity to be used with engine class.
Definition: Lines.h:38
Engine * engine
Definition: Lines.h:43
void update() override
Update transform.
Definition: Lines.cpp:43
void setTransform(const Transform &transform) override
Set transform.
Definition: Lines.cpp:37
bool frustumCulling
Definition: Lines.h:44
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
Definition: Lines.cpp:70
void setEngine(Engine *engine) override
Set up engine.
Definition: Lines.cpp:30
void setEnabled(bool enabled) override
Enable/disable rendering.
Definition: Lines.cpp:49
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Quaternion class representing quaternion mathematical structure and operations with x,...
Definition: Quaternion.h:24
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Partition interface.
Definition: Partition.h:18