TDME2  1.9.200
EnvironmentMapping.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 #include <tdme/tdme.h>
11 #include <tdme/engine/Engine.h>
12 #include <tdme/engine/Partition.h>
13 #include <tdme/engine/Transform.h>
14 #include <tdme/math/Matrix4x4.h>
15 #include <tdme/math/Quaternion.h>
16 #include <tdme/math/Vector3.h>
17 
18 using std::make_unique;
19 using std::string;
20 
30 
31 EnvironmentMapping::EnvironmentMapping(const string& id, int width, int height, BoundingBox boundingBox)
32 {
33  this->id = id;
34  this->width = width;
35  this->height = height;
36  this->boundingBox = boundingBox;
38 }
39 
41  if (this->engine != nullptr) this->engine->deregisterEntity(this);
42  this->engine = engine;
43  if (engine != nullptr) engine->registerEntity(this);
44 }
45 
47  environmentMappingRenderer = make_unique<EnvironmentMappingRenderer>(engine, width, height);
48  environmentMappingRenderer->setRenderPassMask(renderPassMask);
49  environmentMappingRenderer->setTimeRenderUpdateFrequency(timeRenderUpdateFrequency);
50  environmentMappingRenderer->initialize();
51 
52 }
54  environmentMappingRenderer->dispose();
55 }
56 
58 {
59  Transform::setTransform(transform);
60  //
61  auto entityTransform = parentTransform * (*this);
62  entityTransformMatrix = entityTransform.getTransformMatrix();
63  //
64  Transform translationTransform;
65  translationTransform.setTranslation(entityTransform.getTranslation());
66  translationTransform.update();
68  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
69 }
70 
72 {
74  //
75  auto entityTransform = parentTransform * (*this);
76  entityTransformMatrix = entityTransform.getTransformMatrix();
77  //
78  Transform translationTransform;
79  translationTransform.setTranslation(entityTransform.getTranslation());
80  translationTransform.update();
82  if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
83 }
84 
86 {
87  // return if enable state has not changed
88  if (this->enabled == enabled) return;
89 
90  // frustum if root entity
91  if (parentEntity == nullptr) {
92  // frustum culling enabled?
93  if (frustumCulling == true) {
94  // yeo, add or remove from partition
95  if (enabled == true) {
96  if (engine != nullptr) engine->partition->addEntity(this);
97  } else {
98  if (engine != nullptr) engine->partition->removeEntity(this);
99  }
100  }
101  }
102 }
103 
104 void EnvironmentMapping::setFrustumCulling(bool frustumCulling) {
105  // check if enabled and engine attached
106  if (enabled == true && engine != nullptr) {
107  // had frustum culling
108  if (this->frustumCulling == true) {
109  // yep, remove if set to false now
110  if (frustumCulling == false) engine->partition->removeEntity(this);
111  } else {
112  // yep, add if set to true now
113  if (frustumCulling == true) engine->partition->addEntity(this);
114  }
115  }
116  this->frustumCulling = frustumCulling;
117  // delegate change to engine
118  if (engine != nullptr) engine->updateEntityRegistration(this);
119 }
120 
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
Environment mapping 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 setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
unique_ptr< EnvironmentMappingRenderer > environmentMappingRenderer
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
virtual void setTransform(const Transform &transform)
Set transform.
Definition: Transform.h:177
void setTranslation(const Vector3 &translation)
Set translation.
Definition: Transform.h:64
virtual void update()
Computes transform matrix.
Definition: Transform.cpp:33
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
void fromBoundingVolumeWithTransform(BoundingBox *original, const Transform &transform)
Create bounding volume from given original(of same type) with applied transform.
Definition: BoundingBox.h:150
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 & identity()
Creates identity matrix.
Definition: Matrix4x4.h:158
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