-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fire.cpp
59 lines (57 loc) · 2.61 KB
/
Fire.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//--------------------------------------------------------------------------------------------------------------------
/// @file Fire.h
/// @brief Constructor and update function, the update function overrides the virtual update function of the emitter
//--------------------------------------------------------------------------------------------------------------------
#include "Fire.h"
Fire::Fire(int _numberOfParticles, glm::vec3 _positionFire) : Emitter(_numberOfParticles, _positionFire)
{
m_numberOfParticles = _numberOfParticles;
m_positionEmitter = _positionFire;
}
//--------------------------------------------------------------------------------------------------------------------
void Fire::update(float _deltaTime)
{
for(int i=0; i<m_numberOfParticles; ++i)
{
if(m_listOfParticles[i].isDead() == 0)
{
// update the particles if not dead
m_listOfParticles[i].update(_deltaTime);
}
else
{
// reset the values if dead
m_listOfParticles[i].setPosition((glm::vec3(sin((float)rand()/RAND_MAX*10.0-4.5f), 0, sin((float)rand()/RAND_MAX*10.0f-4.0f))*(glm::vec3((float)rand()/RAND_MAX*25.0-13.0f, 0, (float)rand()/RAND_MAX*25.0f-13.0f)))+m_positionEmitter);
m_listOfParticles[i].setVelocity(glm::vec3(0,(float)rand()/(float)RAND_MAX*2.0+0.5,0));
m_listOfParticles[i].setColour(glm::vec3(1,0.5,0));
m_listOfParticles[i].setDeltaColour(glm::vec3(0,0.02,0));
m_listOfParticles[i].setSize((float)rand()/RAND_MAX*5.0+2.5);
m_listOfParticles[i].setDeltaSize(0.1);
m_listOfParticles[i].setLifeSpan((float)rand()/RAND_MAX*2.0-0.5);
m_listOfParticles[i].setDeltaLifeSpan(0.02);
m_listOfParticles[i].setLifeLimit(1);
m_listOfParticles[i].setTransparency(1);
m_listOfParticles[i].setDeltaTransparency(0.02);
}
}
}
//--------------------------------------------------------------------------------------------------------------------
void Fire::blowOnFire()
{
for(int i=0; i<m_numberOfParticles; ++i)
{
// if the particles are higher than a certain hight change the acceleration
if(m_listOfParticles[i].getYPosition()>=-80)
{
m_listOfParticles[i].setAcceleration(glm::vec3(0,0,-((float)rand()/(float)RAND_MAX*1.6+0.9)));
}
}
}
//--------------------------------------------------------------------------------------------------------------------
void Fire::resetAcceleration()
{
for(int i=0; i<m_numberOfParticles; ++i)
{
m_listOfParticles[i].setAcceleration(glm::vec3(0,0,0));
}
}