TDME2 1.9.121
LODObject3DImposter.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <tdme/tdme.h>
13#include <tdme/engine/Camera.h>
14#include <tdme/engine/Entity.h>
20#include <tdme/math/fwd-tdme.h>
22
23using std::string;
24using std::to_string;
25using std::vector;
26
42
43/**
44 * LOD object 3D + imposter to be used with engine class
45 * @author Andreas Drewke
46 * @version $Id$
47 */
49 public Transformations,
50 public Entity
51{
52private:
53 Engine* engine { nullptr };
54 Entity* parentEntity { nullptr };
55 bool frustumCulling { true };
56
57 Model* modelLOD1 { nullptr };
60
61 string id;
62 Object3D* objectLOD1 { nullptr };
64
65 Object3D* objectLOD { nullptr };
66
68 bool enabled;
77 string shaderId { "default" };
78 string distanceShaderId { "" };
79 float distanceShaderDistance { 50.0f };
80 bool enableEarlyZRejection { false };
81
84
85 /**
86 * Set parent entity, needs to be called before adding to engine
87 * @param entity entity
88 */
89 inline void setParentEntity(Entity* entity) override {
90 this->parentEntity = entity;
91 }
92
93 /**
94 * @return parent entity
95 */
96 inline Entity* getParentEntity() override {
97 return parentEntity;
98 }
99
100 // overridden methods
101 inline void applyParentTransformations(const Transformations& parentTransformations) override {
102 Transformations::applyParentTransformations(parentTransformations);
103 // delegate to LOD objects
106 }
107
108public:
109 /**
110 * Public constructor
111 * @param id id
112 * @param modelLOD1 model LOD 1
113 * @param imposterModelsLOD2 imposter models LOD 2
114 * @param lod2MinDistance LOD2 min distance
115 * @param lodNoneMinDistance LOD None min distance
116 */
118 const string& id,
120 const vector<Model*>& imposterModelsLOD2,
121 float lod2MinDistance,
122 float lodNoneMinDistance = 150.0f
123 );
124
125 /**
126 * Public destructor
127 */
129
130 // overridden method
131 inline EntityType getEntityType() override {
133 }
134
135 /**
136 * @return LOD object 1
137 */
139 return objectLOD1;
140 }
141
142 /**
143 * @return LOD object 2
144 */
146 return objectLOD2;
147 }
148
149 /**
150 * @return LOD object
151 */
153 return objectLOD;
154 }
155
156 /**
157 * Get current lod object
158 * @param camera camera
159 * @return LOD object to render
160 */
162 // determine LOD object and level type
163 auto objectCamFromLengthSquared = getBoundingBoxTransformed()->computeClosestPointInBoundingBox(camera->getLookFrom()).sub(camera->getLookFrom()).computeLengthSquared();
164 if (objectCamFromLengthSquared >= Math::square(lodNoneMinDistance)) {
165 objectLOD = nullptr;
166 levelLOD = 3;
167 } else
168 if (objectCamFromLengthSquared >= Math::square(lod2MinDistance)) {
169 levelLOD = 2;
171 } else {
173 levelLOD = 1;
174 }
175
176 // done
177 return objectLOD;
178 }
179
180 /**
181 * @return effect color add for LOD2 level
182 */
183 inline const Color4& getEffectColorAddLOD2() const {
184 return effectColorAddLOD2;
185 }
186
187 /**
188 * Set effect color add for LOD2 level
189 * @param effectColorAddLOD2 effect color add for LOD2 level
190 */
192 this->effectColorAddLOD2 = effectColorAddLOD2;
193 }
194
195 /**
196 * @return effect color mul for LOD2 level
197 */
198 inline const Color4& getEffectColorMulLOD2() const {
199 return effectColorMulLOD2;
200 }
201
202 /**
203 * Set effect color mul for LOD2 level
204 * @param effectColorMulLOD2 effect color mul for LOD2 level
205 */
207 this->effectColorMulLOD2 = effectColorMulLOD2;
208 }
209
210 // overridden methods
211 void setEngine(Engine* engine) override;
212 void setRenderer(Renderer* renderer) override;
213 void initialize() override;
214 void dispose() override;
215
216 inline bool isEnabled() override {
217 return enabled;
218 }
219
220 void setEnabled(bool enabled) override;
221 bool isFrustumCulling() override;
222 void setFrustumCulling(bool frustumCulling) override;
223 void fromTransformations(const Transformations& transformations) override;
224 void update() override;
225
226 inline BoundingBox* getBoundingBox() override {
227 return objectLOD1->getBoundingBox();
228 }
229
232 }
233
234 inline const Color4& getEffectColorMul() const override {
235 return effectColorMul;
236 }
237
238 inline void setEffectColorMul(const Color4& effectColorMul) override {
239 this->effectColorMul = effectColorMul;
240 }
241
242 inline const Color4& getEffectColorAdd() const override {
243 return effectColorAdd;
244 }
245
246 inline void setEffectColorAdd(const Color4& effectColorAdd) override {
247 this->effectColorAdd = effectColorAdd;
248 }
249
250 inline const string& getId() override {
251 return id;
252 }
253
254 inline bool isPickable() override {
255 return pickable;
256 }
257
258 inline bool isContributesShadows() override {
259 return contributesShadows;
260 }
261
262 inline void setContributesShadows(bool contributesShadows) override {
263 this->contributesShadows = contributesShadows;
266 }
267
268 inline bool isReceivesShadows() override {
269 return receivesShadows;
270 }
271
272 inline void setReceivesShadows(bool receivesShadows) override {
273 this->receivesShadows = receivesShadows;
276 }
277
278 inline void setPickable(bool pickable) override {
279 this->pickable = pickable;
280 }
281
282 inline const Matrix4x4 getNodeTransformationsMatrix(const string& id) {
284 }
285
286 inline const Vector3& getTranslation() const override {
288 }
289
290 inline void setTranslation(const Vector3& translation) override {
292 }
293
294 inline const Vector3& getScale() const override {
296 }
297
298 inline void setScale(const Vector3& scale) override {
300 }
301
302 inline const Vector3& getPivot() const override {
304 }
305
306 inline void setPivot(const Vector3& pivot) override {
308 }
309
310 inline const int getRotationCount() const override {
312 }
313
314 inline Rotation& getRotation(const int idx) override {
316 }
317
318 inline void addRotation(const Vector3& axis, const float angle) override {
319 Transformations::addRotation(axis, angle);
320 }
321
322 inline void removeRotation(const int idx) override {
324 }
325
326 inline const Vector3& getRotationAxis(const int idx) const override {
328 }
329
330 inline void setRotationAxis(const int idx, const Vector3& axis) override {
332 }
333
334 inline const float getRotationAngle(const int idx) const override {
336 }
337
338 inline void setRotationAngle(const int idx, const float angle) override {
340 }
341
342 inline const Quaternion& getRotationsQuaternion() const override {
344 }
345
346 inline const Matrix4x4& getTransformationsMatrix() const override {
348 }
349
350 inline const Transformations& getTransformations() const override {
351 return *this;
352 }
353
354 inline RenderPass getRenderPass() const override {
355 return renderPass;
356 }
357
358 inline void setRenderPass(RenderPass renderPass) override {
359 this->renderPass = renderPass;
362 }
363
364 /**
365 * @return shader id
366 */
367 inline const string& getShader() {
368 return shaderId;
369 }
370
371 /**
372 * Set shader id
373 * @param id shader
374 */
375 inline void setShader(const string& id) {
376 this->shaderId = id;
377 shaderParameters.setShader(shaderId);
380 }
381
382 /**
383 * @return distance shader id
384 */
385 inline const string& getDistanceShader() {
386 return distanceShaderId;
387 }
388
389 /**
390 * Set distance shader id
391 * @param id shader
392 */
393 inline void setDistanceShader(const string& id) {
394 this->distanceShaderId = id;
395 distanceShaderParameters.setShader(distanceShaderId);
398 }
399
400 /**
401 * @return distance shader distance
402 */
405 }
406
407 /**
408 * Set distance shader distance
409 * @param distanceShaderDistance shader
410 */
412 this->distanceShaderDistance = distanceShaderDistance;
415 }
416
417 /**
418 * @return If early z rejection is enabled
419 */
422 }
423
424 /**
425 * Enable/disable early z rejection
426 * @param enableEarlyZRejection enable early z rejection
427 */
429
430 /**
431 * Returns shader parameter for given parameter name, if the value does not exist, the default will be returned
432 * @param shaderId shader id
433 * @param parameterName parameter name
434 * @return shader parameter
435 */
436 inline const ShaderParameter getShaderParameter(const string& parameterName) {
437 return shaderParameters.getShaderParameter(parameterName);
438 }
439
440 /**
441 * Set shader parameter for given parameter name
442 * @param shaderId shader id
443 * @param parameterName parameter name
444 * @param paraemterValue parameter value
445 */
446 inline void setShaderParameter(const string& parameterName, const ShaderParameter& parameterValue) {
447 shaderParameters.setShaderParameter(parameterName, parameterValue);
448 objectLOD1->setShaderParameter(parameterName, parameterValue);
449 objectLOD2->setShaderParameter(parameterName, parameterValue);
450 }
451
452 /**
453 * Returns distance shader parameter for given parameter name, if the value does not exist, the default will be returned
454 * @param shaderId shader id
455 * @param parameterName parameter name
456 * @return shader parameter
457 */
458 inline const ShaderParameter getDistanceShaderParameter(const string& parameterName) {
459 return distanceShaderParameters.getShaderParameter(parameterName);
460 }
461
462 /**
463 * Set distance shader parameter for given parameter name
464 * @param shaderId shader id
465 * @param parameterName parameter name
466 * @param paraemterValue parameter value
467 */
468 inline void setDistanceShaderParameter(const string& parameterName, const ShaderParameter& parameterValue) {
469 distanceShaderParameters.setShaderParameter(parameterName, parameterValue);
470 objectLOD1->setDistanceShaderParameter(parameterName, parameterValue);
471 objectLOD2->setDistanceShaderParameter(parameterName, parameterValue);
472 }
473
474};
const Vector3 & getLookFrom() const
Definition: Camera.h:213
Engine main class.
Definition: Engine.h:122
TDME2 engine entity shader parameters.
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
void setShader(const string &shaderId)
Set shader.
const ShaderParameter getShaderParameter(const string &parameterName) const
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
TDME engine entity.
Definition: Entity.h:31
@ ENTITYTYPE_LODOBJECT3DIMPOSTER
Definition: Entity.h:66
Imposter object 3d to be used with engine class.
void setShader(const string &id)
Set shader id.
void setRenderPass(RenderPass renderPass) override
Set render pass.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
void setDistanceShader(const string &id)
Set distance shader id.
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
Object3D * determineBillboardObject(Camera *camera)
Get current billboard object.
void setDistanceShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set distance shader parameter for given parameter name.
LOD object 3D + imposter to be used with engine class.
const Matrix4x4 & getTransformationsMatrix() const override
const Color4 & getEffectColorAdd() const override
The effect color will be added to fragment color.
RenderPass getRenderPass() const override
void dispose() override
Dispose this object 3d.
void setShader(const string &id)
Set shader id.
void setTranslation(const Vector3 &translation) override
Set translation.
void setParentEntity(Entity *entity) override
Set parent entity, needs to be called before adding to engine.
void removeRotation(const int idx) override
Remove rotation.
void setPivot(const Vector3 &pivot) override
Set pivot.
const int getRotationCount() const override
const Quaternion & getRotationsQuaternion() const override
void initialize() override
Initiates this object 3d.
EntityShaderParameters shaderParameters
BoundingBox * getBoundingBox() override
void setRenderPass(RenderPass renderPass) override
Set render pass.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void addRotation(const Vector3 &axis, const float angle) override
Add rotation.
void update() override
Update transformations.
void setPickable(bool pickable) override
Set this object pickable.
void setEffectColorMul(const Color4 &effectColorMul) override
Set effect color that will be multiplied with fragment color.
const ShaderParameter getShaderParameter(const string &parameterName)
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
const Color4 & getEffectColorMulLOD2() const
Object3D * determineLODObject(Camera *camera)
Get current lod object.
const Vector3 & getTranslation() const override
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
const ShaderParameter getDistanceShaderParameter(const string &parameterName)
Returns distance shader parameter for given parameter name, if the value does not exist,...
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
const Color4 & getEffectColorMul() const override
The effect color will be multiplied with fragment color.
const Vector3 & getScale() const override
const Vector3 & getPivot() const override
void setEffectColorAddLOD2(const Color4 &effectColorAddLOD2)
Set effect color add for LOD2 level.
void setEnableEarlyZRejection(bool enableEarlyZRejection)
Enable/disable early z rejection.
BoundingBox * getBoundingBoxTransformed() override
void setDistanceShader(const string &id)
Set distance shader id.
void setScale(const Vector3 &scale) override
Set scale.
LODObject3DImposter(const string &id, Model *modelLOD1, const vector< Model * > &imposterModelsLOD2, float lod2MinDistance, float lodNoneMinDistance=150.0f)
Public constructor.
const Matrix4x4 getNodeTransformationsMatrix(const string &id)
EntityShaderParameters distanceShaderParameters
void applyParentTransformations(const Transformations &parentTransformations) override
Apply parent transformations.
const float getRotationAngle(const int idx) const override
const Transformations & getTransformations() const override
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
const Vector3 & getRotationAxis(const int idx) const override
const Color4 & getEffectColorAddLOD2() const
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
void setRotationAxis(const int idx, const Vector3 &axis) override
Set rotation axis.
Rotation & getRotation(const int idx) override
Get rotation at given index.
void setEffectColorMulLOD2(const Color4 &effectColorMulLOD2)
Set effect color mul for LOD2 level.
void setEffectColorAdd(const Color4 &effectColorAdd) override
Set effect color that will be added to fragment color.
void setDistanceShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set distance shader parameter for given parameter name.
void setRenderer(Renderer *renderer) override
Set up renderer.
void setRotationAngle(const int idx, const float angle) override
Object 3D to be used with engine class.
Definition: Object3D.h:60
void setShader(const string &id)
Set shader.
Definition: Object3D.cpp:116
BoundingBox * getBoundingBox() override
Definition: Object3D.h:215
void setRenderPass(RenderPass renderPass) override
Set render pass.
Definition: Object3D.h:339
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
Definition: Object3D.h:255
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
Definition: Object3D.h:504
void fromTransformations(const Transformations &transformations) override
Set up this transformations from given transformations.
Definition: Object3D.cpp:52
BoundingBox * getBoundingBoxTransformed() override
Definition: Object3D.h:219
void setDistanceShader(const string &id)
Set distance shader.
Definition: Object3D.cpp:136
void setDistanceShaderDistance(float distanceShaderDistance)
Set distance shader distance.
Definition: Object3D.h:394
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
Definition: Object3D.h:247
void setDistanceShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set distance shader parameter for given parameter name.
Definition: Object3D.h:524
Rotation representation.
Definition: Rotation.h:18
Shader parameter model class.
Transformations which contain scale, rotations and translation.
const Matrix4x4 & getTransformationsMatrix() const
Rotation & getRotation(const int idx)
Get rotation at given index.
void setRotationAngle(const int idx, const float angle)
void setRotationAxis(const int idx, const Vector3 &axis)
Set rotation axis.
void setTranslation(const Vector3 &translation)
Set translation.
void removeRotation(const int idx)
Remove rotation.
const Quaternion & getRotationsQuaternion() const
virtual void applyParentTransformations(const Transformations &parentTransformations)
Apply parent transformations.
const Vector3 & getScale() const
void setScale(const Vector3 &scale)
Set scale.
const Vector3 & getRotationAxis(const int idx) const
const int getRotationCount() const
const Vector3 & getPivot() const
const Vector3 & getTranslation() const
void setPivot(const Vector3 &pivot)
Set pivot.
void addRotation(const Vector3 &axis, const float angle)
Add rotation.
const float getRotationAngle(const int idx) const
Color 4 definition.
Definition: Color4.h:20
Representation of a 3d model.
Definition: Model.h:32
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:25
Vector3 computeClosestPointInBoundingBox(const Vector3 &point)
Compute closest point in bounding box of given point.
Definition: BoundingBox.h:77
const Matrix4x4 getNodeTransformationsMatrix(const string &id)
Returns transformation matrix for given node.
Definition: Object3DBase.h:255
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Quaternion class.
Definition: Quaternion.h:22
3D vector 3 class
Definition: Vector3.h:22
float computeLengthSquared() const
Definition: Vector3.h:209
Vector3 & sub(const Vector3 &v)
Subtracts a vector.
Definition: Vector3.h:325
Console class.
Definition: Console.h:26