TDME2  1.9.200
PointParticleEmitter.cpp
Go to the documentation of this file.
2 
3 #include <tdme/tdme.h>
4 #include <tdme/engine/Color4.h>
7 #include <tdme/math/Math.h>
8 #include <tdme/math/Matrix4x4.h>
9 #include <tdme/math/Vector3.h>
10 
15 using tdme::math::Math;
18 
19 PointParticleEmitter::PointParticleEmitter(int32_t count, int64_t lifeTime, int64_t lifeTimeRnd, float mass, float massRnd, const Vector3& position, const Vector3& velocity, const Vector3& velocityRnd, const Color4& colorStart, const Color4& colorEnd)
20 {
21  this->count = count;
22  this->lifeTime = lifeTime;
23  this->lifeTimeRnd = lifeTimeRnd;
24  this->mass = mass;
25  this->massRnd = massRnd;
26  this->position.set(position);
27  this->worldPosition.set(position);
28  this->velocity.set(velocity);
29  this->velocityRnd.set(velocityRnd);
30  this->colorStart.set(colorStart);
31  this->colorEnd.set(colorEnd);
32 }
33 
35 {
36  // set up particle
37  particle->active = true;
38  particle->spriteIndex = 0.0f;
39  particle->position.set(0.0f, 0.0f, 0.0f);
40  particle->velocity.set(
41  velocity[0] + (Math::random() * velocityRnd[0] * (Math::random() > 0.5 ? +1.0f : -1.0f)),
42  velocity[1] + (Math::random() * velocityRnd[1] * (Math::random() > 0.5 ? +1.0f : -1.0f)),
43  velocity[2] + (Math::random() * velocityRnd[2] * (Math::random() > 0.5 ? +1.0f : -1.0f))
44  );
45  particle->mass = mass + static_cast<float>((Math::random() * (massRnd)));
46  particle->lifeTimeMax = lifeTime + static_cast<int64_t>((Math::random() * lifeTimeRnd));
47  particle->lifeTimeCurrent = 0LL;
48  particle->color.set(colorStart);
49  particle->colorAdd.set(
50  (colorEnd.getRed() - colorStart.getRed()) / particle->lifeTimeMax,
51  (colorEnd.getGreen() - colorStart.getGreen()) / particle->lifeTimeMax,
52  (colorEnd.getBlue() - colorStart.getBlue()) / particle->lifeTimeMax,
53  (colorEnd.getAlpha() - colorStart.getAlpha()) / particle->lifeTimeMax
54  );
55 }
56 
58 {
59  //
60  const auto& transformMatrix = transform.getTransformMatrix();
61  // world position
62  worldPosition = transformMatrix.multiply(position);
63 }
Color 4 definition class.
Definition: Color4.h:18
float getRed() const
Definition: Color4.h:92
float getGreen() const
Definition: Color4.h:107
float getAlpha() const
Definition: Color4.h:137
float getBlue() const
Definition: Color4.h:122
void set(float r, float g, float b, float a)
Sets this color by its components.
Definition: Color4.h:66
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
const Matrix4x4 & getTransformMatrix() const
Definition: Transform.h:169
void setTransform(const Transform &transform) override
Update transform with given transform.
void emit(Particle *particle) override
Emits particles.
Standard math functions.
Definition: Math.h:19
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70