TDME2  1.9.200
CircleParticleEmitterPlaneVelocity.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 CircleParticleEmitterPlaneVelocity::CircleParticleEmitterPlaneVelocity(int32_t count, int64_t lifeTime, int64_t lifeTimeRnd, const Vector3& axis0, const Vector3& axis1, const Vector3& center, float radius, float mass, float massRnd, float velocity, float velocityRnd, const Color4& colorStart, const Color4& colorEnd)
20 {
21  this->count = count;
22  this->lifeTime = lifeTime;
23  this->lifeTimeRnd = lifeTimeRnd;
24  this->axis0.set(axis0).normalize();
25  this->axis1.set(axis1).normalize();
26  this->center.set(center);
27  this->radius = radius;
28  this->mass = mass;
29  this->massRnd = massRnd;
30  this->velocity = velocity;
31  this->velocityRnd = velocityRnd;
32  this->colorStart.set(colorStart);
33  this->colorEnd.set(colorEnd);
34  this->worldCenter.set(center);
35  this->worldRadius = radius;
36  this->worldAxis0.set(axis0).normalize();
37  this->worldAxis1.set(axis1).normalize();
38 }
39 
41 {
42  Vector3 cosOnAxis0;
43  Vector3 sinOnAxis1;
44  // set up particle
45  particle->active = true;
46  particle->spriteIndex = 0.0f;
47  // emit particle on circle spanned on axis 0 and axis 1
48  auto rnd = Math::random();
49  cosOnAxis0.set(worldAxis0).scale(Math::cos(Math::PI * 2 * rnd));
50  sinOnAxis1.set(worldAxis1).scale(Math::sin(Math::PI * 2 * rnd));
51  particle->position.set(cosOnAxis0);
52  particle->position.add(sinOnAxis1);
53  particle->position.scale(worldRadius);
54  // compute velocity
55  particle->velocity.set(particle->position).normalize().scale(velocity + (Math::random() * velocityRnd));
56  // mass
57  particle->mass = mass + static_cast<float>((Math::random() * (massRnd)));
58  // life time
59  particle->lifeTimeMax = lifeTime + static_cast<int64_t>((Math::random() * lifeTimeRnd));
60  particle->lifeTimeCurrent = 0LL;
61  // color
62  particle->color.set(colorStart);
63  particle->colorAdd.set(
64  (colorEnd.getRed() - colorStart.getRed()) / particle->lifeTimeMax,
65  (colorEnd.getGreen() - colorStart.getGreen()) / particle->lifeTimeMax,
66  (colorEnd.getBlue() - colorStart.getBlue()) / particle->lifeTimeMax,
67  (colorEnd.getAlpha() - colorStart.getAlpha()) / particle->lifeTimeMax);
68 }
69 
71 {
72  const auto& transformMatrix = transform.getTransformMatrix();
73  // apply rotation, scale, translation
74  worldCenter = transformMatrix.multiply(center);
75  // apply transform rotation + scale to axis
76  worldAxis0 = transformMatrix.multiplyNoTranslation(axis0);
77  worldAxis1 = transformMatrix.multiplyNoTranslation(axis1);
78  // world radius
79  Vector3 worldScale;
80  transformMatrix.getScale(worldScale);
81  worldRadius = radius * Math::max(worldScale.getX(), Math::max(worldScale.getY(), worldScale.getZ()));
82 }
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.
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
float getY() const
Definition: Vector3.h:117
float getX() const
Definition: Vector3.h:100
float getZ() const
Definition: Vector3.h:134
Vector3 & add(float scalar)
Adds a scalar.
Definition: Vector3.h:153
Vector3 & scale(float scalar)
Scales by scalar.
Definition: Vector3.h:201
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70
Vector3 & normalize()
Normalizes this vector3.
Definition: Vector3.h:239