TDME2  1.9.200
DecalInternal.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
7 #include <tdme/engine/fwd-tdme.h>
9 #include <tdme/engine/Color4.h>
14 #include <tdme/engine/Transform.h>
15 #include <tdme/math/Math.h>
16 #include <tdme/math/Matrix4x4.h>
17 #include <tdme/utilities/Time.h>
18 
19 using std::string;
20 
28 using tdme::math::Math;
31 
32 /**
33  * Decal entity internal
34  * @author Andreas Drewke
35  */
37  : public Transform
38 {
39 protected:
40  string id;
41  Engine* engine { nullptr };
42  Renderer* renderer { nullptr };
43  bool enabled;
44  OrientedBoundingBox* obb { nullptr };
45  Texture* texture { nullptr };
48  float fps;
49  float textureSpriteIdx { 0.0f };
50  int64_t lastRenderedTime { -1ll };
51 
56  bool pickable;
59 
64 
66 
67  /**
68  * Set parent transform
69  * @param parentTransform parent transform
70  */
72  this->parentTransform = parentTransform;
73  auto entityTransform = parentTransform * (*this);
74  entityTransformMatrix = entityTransform.getTransformMatrix();
75  //
77  }
78 
79  /**
80  * Update bounding volume and obb matrix with transform and finally world to decal space matrix
81  */
82  inline void updateInternal() {
86  }
87 
88 public:
89  // forbid class copy
91 
92  /**
93  * Public constructor
94  * @param id id
95  * @param obb oriented bounding box
96  * @param texture texture
97  * @param textureHorizonalSprites texture horizonal sprites
98  * @param textureVerticalSprites texture vertical sprites
99  * @param fps frames per seconds
100  */
101  DecalInternal(const string& id, OrientedBoundingBox* obb, Texture* texture = nullptr, int32_t textureHorizontalSprites = 1, int32_t textureVerticalSprites = 1, float fps = 10.0f);
102 
103  /**
104  * Destructor
105  */
106  virtual ~DecalInternal();
107 
108  /**
109  * @return id
110  */
111  inline const string& getId() {
112  return id;
113  }
114 
115  /**
116  * Set renderer
117  * @param renderer renderer
118  */
119  inline void setRenderer(Renderer* renderer) {
120  this->renderer = renderer;
121  }
122 
123  /**
124  * Set engine
125  * @param engine engine
126  */
127  inline void setEngine(Engine* engine) {
128  this->engine = engine;
129  }
130 
131  /**
132  * @return is enabled
133  */
134  inline bool isEnabled() {
135  return enabled;
136  }
137 
138  /**
139  * Set enabled
140  * @param enabled enabled
141  */
142  inline void setEnabled(bool enabled) {
143  this->enabled = enabled;
144  }
145 
146  /**
147  * @return effect color mul
148  */
149  inline const Color4& getEffectColorMul() const {
150  return effectColorMul;
151  }
152 
153  /**
154  * Set effect color mul
155  * @param effectColorMul effect color mul
156  */
158  this->effectColorMul = effectColorMul;
159  }
160 
161  /**
162  * @return effect color mul
163  */
164  inline const Color4& getEffectColorAdd() const {
165  return effectColorMul;
166  }
167 
168  /**
169  * Set effect color add
170  * @param effectColorAdd effect color add
171  */
173  this->effectColorAdd = effectColorAdd;
174  }
175 
176  /**
177  * @return is pickable
178  */
179  inline bool isPickable() const {
180  return pickable;
181  }
182 
183  /**
184  * Set pickable
185  * @param pickable pickable
186  */
187  inline void setPickable(bool pickable) {
188  this->pickable = pickable;
189  }
190 
191  /**
192  * @return if entity contributes to shadows
193  */
194  inline bool isContributesShadows() {
195  return contributesShadows;
196  }
197 
198  /**
199  * Enable/disable contributes shadows
200  * @param contributesShadows contributes shadows
201  */
203  this->contributesShadows = contributesShadows;
204  }
205 
206  /**
207  * @return if entity receives shadows
208  */
209  inline bool isReceivesShadows() {
210  return receivesShadows;
211  }
212 
213  /**
214  * Enable/disable receives shadows
215  * @param receivesShadows receives shadows
216  */
218  this->receivesShadows = receivesShadows;
219  }
220 
221  /**
222  * @return bounding box
223  */
225  return &boundingBox;
226  }
227 
228  /**
229  * @return world bounding box
230  */
232  return &worldBoundingBox;
233  }
234 
235  /**
236  * Update transform
237  */
238  void update() override;
239 
240  /**
241  * From transform
242  * @param transform transform
243  */
244  void setTransform(const Transform& transform) override;
245 
246  /**
247  * Initialize
248  */
249  void initialize();
250 
251  /**
252  * Dispose
253  */
254  void dispose();
255 
256  /**
257  * @return decal texture
258  */
260  return texture;
261  }
262 
263  /**
264  * @return world to decal space matrix
265  */
268  }
269 
270  /**
271  * @return texture horizontal sprites
272  */
273  inline int32_t getTextureHorizontalSprites(){
275  }
276 
277  /**
278  * @return texture vertical sprites
279  */
280  inline int32_t getTextureVerticalSprites(){
281  return textureVerticalSprites;
282  }
283 
284  /**
285  * @return fps
286  */
287  inline float getFPS(){
288  return fps;
289  }
290 
291  /**
292  * @return current texture sprite index
293  */
294  inline int32_t computeTextureSpriteIdx() {
295  auto now = Time::getCurrentMillis();
296  // first rendering?
297  if (lastRenderedTime == -1ll) {
298  lastRenderedTime = now;
299  return textureSpriteIdx;
300  }
301  //
302  auto timeElapsed = now - lastRenderedTime;
303  textureSpriteIdx = Math::mod(textureSpriteIdx + (static_cast<float>(timeElapsed) / 1000.0f) * fps, static_cast<float>(textureHorizontalSprites * textureVerticalSprites));
304  //
305  lastRenderedTime = now;
306  //
307  return static_cast<int32_t>(textureSpriteIdx);
308  }
309 
310 };
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
void fromBoundingVolumeWithTransformMatrix(BoundingBox *original, const Matrix4x4 &transformMatrix)
Create bounding volume from given original(of same type) with applied transform matrix.
Definition: BoundingBox.cpp:79
Oriented bounding box physics primitive.
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
void setEngine(Engine *engine)
Set engine.
void setEnabled(bool enabled)
Set enabled.
void update() override
Update transform.
void setTransform(const Transform &transform) override
From transform.
DecalInternal(const string &id, OrientedBoundingBox *obb, Texture *texture=nullptr, int32_t textureHorizontalSprites=1, int32_t textureVerticalSprites=1, float fps=10.0f)
Public constructor.
void setPickable(bool pickable)
Set pickable.
void setEffectColorMul(const Color4 &effectColorMul)
Set effect color mul.
void setEffectColorAdd(const Color4 &effectColorAdd)
Set effect color add.
void setRenderer(Renderer *renderer)
Set renderer.
void updateInternal()
Update bounding volume and obb matrix with transform and finally world to decal space matrix.
Definition: DecalInternal.h:82
void setReceivesShadows(bool receivesShadows)
Enable/disable receives shadows.
void setParentTransform(const Transform &parentTransform)
Set parent transform.
Definition: DecalInternal.h:71
Standard math functions.
Definition: Math.h:19
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 clone() const
Clones this matrix.
Definition: Matrix4x4.h:619
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Definition: Matrix4x4.h:225
Matrix4x4 & invert()
Inverts this matrix.
Definition: Matrix4x4.h:479
Time utility class.
Definition: Time.h:20
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6