TDME2 1.9.121
LODObject3DImposter.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <vector>
5
6#include <tdme/tdme.h>
11
12using std::string;
13using std::vector;
14
20
21LODObject3DImposter::LODObject3DImposter(
22 const string& id,
23 Model* modelLOD1,
24 const vector<Model*>& imposterModelsLOD2,
25 float lod2MinDistance,
26 float lodNoneMinDistance
27):
28 id(id),
29 modelLOD1(modelLOD1),
30 lod2MinDistance(lod2MinDistance),
31 lodNoneMinDistance(lodNoneMinDistance)
32{
33 this->enabled = true;
34 this->pickable = false;
35 this->contributesShadows = false;
36 this->receivesShadows = false;
37 this->effectColorMul.set(1.0f, 1.0f, 1.0f, 1.0f);
38 this->effectColorAdd.set(0.0f, 0.0f, 0.0f, 0.0f);
39 this->effectColorMulLOD2.set(1.0f, 1.0f, 1.0f, 1.0f);
40 this->effectColorAddLOD2.set(0.0f, 0.0f, 0.0f, 0.0f);
41
42 objectLOD1 = new Object3D(id + ".lod1", modelLOD1);
44
45 objectLOD2 = new ImposterObject3D(id + ".lod2", imposterModelsLOD2);
47
50
53
56
59
60 levelLOD = 1;
61}
62
64 // delegate to LOD objects
65 delete objectLOD1;
66 delete objectLOD2;
67}
68
70{
71 if (this->engine != nullptr) this->engine->deregisterEntity(this);
72 this->engine = engine;
73 if (engine != nullptr) engine->registerEntity(this);
76}
77
79{
80}
81
83{
85 // delegate to LOD objects
88 // update entity
89 if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
90 // reset current LOD object
91 objectLOD = nullptr;
92}
93
95{
97 // delegate to LOD objects
100 // update entity
101 if (parentEntity == nullptr && frustumCulling == true && engine != nullptr && enabled == true) engine->partition->updateEntity(this);
102 // reset current LOD object
103 objectLOD = nullptr;
104}
105
107{
108 // return if enable state has not changed
109 if (this->enabled == enabled) return;
110 // frustum if root entity
111 if (parentEntity == nullptr) {
112 // frustum culling enabled?
113 if (frustumCulling == true) {
114 // yeo, add or remove from partition
115 if (enabled == true) {
116 if (engine != nullptr) engine->partition->addEntity(this);
117 } else {
118 if (engine != nullptr) engine->partition->removeEntity(this);
119 }
120 }
121 }
122 // reset current LOD object
123 objectLOD = nullptr;
124}
125
127 return frustumCulling;
128}
129
130void LODObject3DImposter::setFrustumCulling(bool frustumCulling) {
131 // check if enabled and engine attached
132 if (enabled == true && engine != nullptr) {
133 // had frustum culling
134 if (this->frustumCulling == true) {
135 // yep, remove if set to false now
136 if (frustumCulling == false) engine->partition->removeEntity(this);
137 } else {
138 // yep, add if set to true now
139 if (frustumCulling == true) engine->partition->addEntity(this);
140 }
141 }
142 this->frustumCulling = frustumCulling;
143 // delegate change to engine
144 if (engine != nullptr) engine->registerEntity(this);
145}
146
148{
149 // delegate to LOD objects
152}
153
155{
156 // delegate to LOD objects
159}
160
161void LODObject3DImposter::setEnableEarlyZRejection(bool enableEarlyZRejection) {
162 // delegate to LOD objects
165}
Engine main class.
Definition: Engine.h:122
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
Definition: Engine.cpp:392
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:406
Partition * partition
Definition: Engine.h:255
Imposter object 3d to be used with engine class.
void dispose() override
Dispose this object 3d.
void setShader(const string &id)
Set shader id.
void setParentEntity(Entity *entity) override
Set parent entity, needs to be called before adding to engine.
void initialize() override
Initiates this object 3d.
void setRenderPass(RenderPass renderPass) override
Set render pass.
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
void setEnableEarlyZRejection(bool enableEarlyZRejection)
Enable/disable early z rejection.
void setDistanceShader(const string &id)
Set distance shader id.
void setEngine(Engine *engine) override
Set up engine.
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
LOD object 3D + imposter to be used with engine class.
void dispose() override
Dispose this object 3d.
void initialize() override
Initiates this object 3d.
void update() override
Update transformations.
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
void setEnableEarlyZRejection(bool enableEarlyZRejection)
Enable/disable early z rejection.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
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 3D to be used with engine class.
Definition: Object3D.h:60
void dispose() override
Dispose this object 3d.
Definition: Object3D.cpp:106
void setShader(const string &id)
Set shader.
Definition: Object3D.cpp:116
void setParentEntity(Entity *entity) override
Set parent entity, needs to be called before adding to engine.
Definition: Object3D.h:161
void initialize() override
Initiates this object 3d.
Definition: Object3D.cpp:111
void setRenderPass(RenderPass renderPass) override
Set render pass.
Definition: Object3D.h:339
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
Definition: Object3D.cpp:52
void setEnableEarlyZRejection(bool enableEarlyZRejection)
Enable/disable early z rejection.
Definition: Object3D.h:469
void setDistanceShader(const string &id)
Set distance shader.
Definition: Object3D.cpp:136
void setEngine(Engine *engine) override
Set up engine.
Definition: Object3D.cpp:41
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
Definition: Object3D.h:394
Transformations which contain scale, rotations and translation.
virtual void fromTransformations(const Transformations &transformations)
Set up this transformations from given transformations.
virtual void update()
Computes transformation matrix.
void set(const array< float, 4 > &color)
Set up color.
Definition: Color4Base.h:68
Representation of a 3d model.
Definition: Model.h:32
Partition interface.
Definition: Partition.h:19
virtual void updateEntity(Entity *entity)=0
Updates a entity.
virtual void addEntity(Entity *entity)=0
Adds a entity.
virtual void removeEntity(Entity *entity)=0
Removes a entity.