TDME2
1.9.121
src
tdme
engine
subsystems
particlesystem
CircleParticleEmitter.cpp
Go to the documentation of this file.
1
#include <
tdme/engine/subsystems/particlesystem/CircleParticleEmitter.h
>
2
3
#include <
tdme/tdme.h
>
4
#include <
tdme/engine/model/Color4.h
>
5
#include <
tdme/engine/model/Color4Base.h
>
6
#include <
tdme/engine/subsystems/particlesystem/Particle.h
>
7
#include <
tdme/engine/Transformations.h
>
8
#include <
tdme/math/Math.h
>
9
#include <
tdme/math/Matrix4x4.h
>
10
#include <
tdme/math/Vector3.h
>
11
12
using
tdme::engine::model::Color4
;
13
using
tdme::engine::model::Color4Base
;
14
using
tdme::engine::subsystems::particlesystem::CircleParticleEmitter
;
15
using
tdme::engine::subsystems::particlesystem::Particle
;
16
using
tdme::engine::Transformations
;
17
using
tdme::math::Math
;
18
using
tdme::math::Matrix4x4
;
19
using
tdme::math::Vector3
;
20
21
CircleParticleEmitter::CircleParticleEmitter(int32_t count, int64_t lifeTime, int64_t lifeTimeRnd,
const
Vector3
& axis0,
const
Vector3
& axis1,
const
Vector3
& center,
float
radius,
float
mass,
float
massRnd,
const
Vector3
& velocity,
const
Vector3
& velocityRnd,
const
Color4
& colorStart,
const
Color4
& colorEnd)
22
{
23
this->count =
count
;
24
this->lifeTime =
lifeTime
;
25
this->lifeTimeRnd =
lifeTimeRnd
;
26
this->axis0.
set
(
axis0
).
normalize
();
27
this->axis1.
set
(
axis1
).
normalize
();
28
this->center.
set
(
center
);
29
this->radius =
radius
;
30
this->
axis0Transformed
.
set
(axis0).
normalize
();
31
this->
axis1Transformed
.
set
(axis1).
normalize
();
32
this->
centerTransformed
.
set
(center);
33
this->
radiusTransformed
=
radius
;
34
this->mass =
mass
;
35
this->massRnd =
massRnd
;
36
this->velocity.
set
(
velocity
);
37
this->velocityRnd.
set
(
velocityRnd
);
38
this->colorStart.
set
(
colorStart
);
39
this->colorEnd.
set
(
colorEnd
);
40
}
41
42
void
CircleParticleEmitter::emit
(
Particle
* particle)
43
{
44
Vector3
cosOnAxis0;
45
Vector3
sinOnAxis1;
46
// set up particle
47
particle->
active
=
true
;
48
particle->
spriteIndex
= 0.0f;
49
// emit particle in circle spanned on axis 0 and axis 1
50
auto
rnd =
static_cast<
float
>
(Math::random());
51
cosOnAxis0.
set
(
axis0Transformed
).
scale
(Math::cos(Math::PI * 2 * rnd));
52
sinOnAxis1.
set
(
axis1Transformed
).
scale
(Math::sin(Math::PI * 2 * rnd));
53
particle->
position
.
set
(cosOnAxis0);
54
particle->
position
.
add
(sinOnAxis1);
55
particle->
position
.
scale
(
radiusTransformed
);
56
// compute velocity
57
particle->
velocity
.
set
(
58
velocity
[0] + (Math::random() *
velocityRnd
[0] * (Math::random() > 0.5 ? +1.0f : -1.0f)),
59
velocity
[1] + (Math::random() *
velocityRnd
[1] * (Math::random() > 0.5 ? +1.0f : -1.0f)),
60
velocity
[2] + (Math::random() *
velocityRnd
[2] * (Math::random() > 0.5 ? +1.0f : -1.0f))
61
);
62
// mass
63
particle->
mass
=
mass
+
static_cast<
float
>
((Math::random() * (
massRnd
)));
64
// life time
65
particle->
lifeTimeMax
=
lifeTime
+
static_cast<
int64_t
>
((Math::random() *
lifeTimeRnd
));
66
particle->
lifeTimeCurrent
= 0LL;
67
// color
68
particle->
color
.
set
(
colorStart
);
69
particle->
colorAdd
.
set
(
70
(
colorEnd
.
getRed
() -
colorStart
.
getRed
()) / particle->
lifeTimeMax
,
71
(
colorEnd
.
getGreen
() -
colorStart
.
getGreen
()) / particle->
lifeTimeMax
,
72
(
colorEnd
.
getBlue
() -
colorStart
.
getBlue
()) / particle->
lifeTimeMax
,
73
(
colorEnd
.
getAlpha
() -
colorStart
.
getAlpha
()) / particle->
lifeTimeMax
74
);
75
}
76
77
void
CircleParticleEmitter::fromTransformations
(
const
Transformations
& transformations)
78
{
79
auto
& transformationsMatrix = transformations.
getTransformationsMatrix
();
80
// apply rotation, scale, translation
81
centerTransformed
= transformationsMatrix.multiply(
center
);
82
// apply transformations rotation + scale to axis
83
axis0Transformed
= transformationsMatrix.multiplyNoTranslation(
axis0
).
normalize
();
84
axis1Transformed
= transformationsMatrix.multiplyNoTranslation(
axis1
).
normalize
();
85
// scale and radius transformed
86
Vector3
scale;
87
transformationsMatrix.getScale(scale);
88
radiusTransformed
=
radius
* Math::max(scale.
getX
(), Math::max(scale.
getY
(), scale.
getZ
()));
89
}
CircleParticleEmitter.h
Color4Base.h
Color4.h
Math.h
Matrix4x4.h
Particle.h
Transformations.h
Vector3.h
tdme::engine::Transformations
Transformations which contain scale, rotations and translation.
Definition:
Transformations.h:27
tdme::engine::Transformations::getTransformationsMatrix
const Matrix4x4 & getTransformationsMatrix() const
Definition:
Transformations.h:169
tdme::engine::model::Color4Base
Color 4 base definition class.
Definition:
Color4Base.h:19
tdme::engine::model::Color4Base::set
void set(const array< float, 4 > &color)
Set up color.
Definition:
Color4Base.h:68
tdme::engine::model::Color4Base::getRed
float getRed() const
Definition:
Color4Base.h:111
tdme::engine::model::Color4Base::getGreen
float getGreen() const
Definition:
Color4Base.h:125
tdme::engine::model::Color4Base::getAlpha
float getAlpha() const
Definition:
Color4Base.h:153
tdme::engine::model::Color4Base::getBlue
float getBlue() const
Definition:
Color4Base.h:139
tdme::engine::model::Color4
Color 4 definition.
Definition:
Color4.h:20
tdme::engine::subsystems::particlesystem::CircleParticleEmitter
Circle particle emitter.
Definition:
CircleParticleEmitter.h:25
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::colorEnd
Color4 colorEnd
Definition:
CircleParticleEmitter.h:43
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::axis0Transformed
Vector3 axis0Transformed
Definition:
CircleParticleEmitter.h:34
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::count
int32_t count
Definition:
CircleParticleEmitter.h:27
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::radius
float radius
Definition:
CircleParticleEmitter.h:33
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::velocityRnd
Vector3 velocityRnd
Definition:
CircleParticleEmitter.h:41
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::velocity
Vector3 velocity
Definition:
CircleParticleEmitter.h:40
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::colorStart
Color4 colorStart
Definition:
CircleParticleEmitter.h:42
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::centerTransformed
Vector3 centerTransformed
Definition:
CircleParticleEmitter.h:36
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::lifeTimeRnd
int64_t lifeTimeRnd
Definition:
CircleParticleEmitter.h:29
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::fromTransformations
void fromTransformations(const Transformations &transformations) override
Update transformation with given transformations.
Definition:
CircleParticleEmitter.cpp:77
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::mass
float mass
Definition:
CircleParticleEmitter.h:38
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::axis1
Vector3 axis1
Definition:
CircleParticleEmitter.h:31
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::axis1Transformed
Vector3 axis1Transformed
Definition:
CircleParticleEmitter.h:35
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::lifeTime
int64_t lifeTime
Definition:
CircleParticleEmitter.h:28
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::emit
void emit(Particle *particle) override
Emits particles.
Definition:
CircleParticleEmitter.cpp:42
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::center
Vector3 center
Definition:
CircleParticleEmitter.h:32
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::radiusTransformed
float radiusTransformed
Definition:
CircleParticleEmitter.h:37
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::axis0
Vector3 axis0
Definition:
CircleParticleEmitter.h:30
tdme::engine::subsystems::particlesystem::CircleParticleEmitter::massRnd
float massRnd
Definition:
CircleParticleEmitter.h:39
tdme::math::Math
Standard math functions.
Definition:
Math.h:21
tdme::math::Matrix4x4
4x4 3D Matrix class
Definition:
Matrix4x4.h:24
tdme::math::Vector3
3D vector 3 class
Definition:
Vector3.h:22
tdme::math::Vector3::getY
float getY() const
Definition:
Vector3.h:119
tdme::math::Vector3::getX
float getX() const
Definition:
Vector3.h:103
tdme::math::Vector3::getZ
float getZ() const
Definition:
Vector3.h:136
tdme::math::Vector3::normalize
Vector3 & normalize()
Normalize the vector.
Definition:
Vector3.h:288
tdme::math::Vector3::set
Vector3 & set(float x, float y, float z)
Set up vector.
Definition:
Vector3.h:73
tdme::math::Vector3::add
Vector3 & add(const Vector3 &v)
Adds a vector.
Definition:
Vector3.h:301
tdme::math::Vector3::scale
Vector3 & scale(float scale)
Scale this vector.
Definition:
Vector3.h:349
tdme::engine::subsystems::particlesystem::Particle
Particle entity.
Definition:
Particle.h:20
tdme::engine::subsystems::particlesystem::Particle::active
bool active
Definition:
Particle.h:21
tdme::engine::subsystems::particlesystem::Particle::colorAdd
Color4 colorAdd
Definition:
Particle.h:29
tdme::engine::subsystems::particlesystem::Particle::velocity
Vector3 velocity
Definition:
Particle.h:23
tdme::engine::subsystems::particlesystem::Particle::mass
float mass
Definition:
Particle.h:25
tdme::engine::subsystems::particlesystem::Particle::lifeTimeCurrent
int64_t lifeTimeCurrent
Definition:
Particle.h:27
tdme::engine::subsystems::particlesystem::Particle::spriteIndex
float spriteIndex
Definition:
Particle.h:22
tdme::engine::subsystems::particlesystem::Particle::lifeTimeMax
int64_t lifeTimeMax
Definition:
Particle.h:26
tdme::engine::subsystems::particlesystem::Particle::position
Vector3 position
Definition:
Particle.h:24
tdme::engine::subsystems::particlesystem::Particle::color
Color4 color
Definition:
Particle.h:28
tdme.h
Generated by
1.9.3