1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: ... |
---|
13 | co-programmer: Patrick Boenzli |
---|
14 | */ |
---|
15 | |
---|
16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
17 | |
---|
18 | #include "particle_emitter.h" |
---|
19 | |
---|
20 | #include "particle_system.h" |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | \brief standard constructor |
---|
27 | */ |
---|
28 | ParticleEmitter::ParticleEmitter(const Vector& direction, float angle, float emissionRate, |
---|
29 | float velocity) |
---|
30 | { |
---|
31 | this->setClassName ("ParticleEmitter"); |
---|
32 | this->direction = direction; |
---|
33 | this->setSpread(angle); |
---|
34 | this->emissionRate = emissionRate; |
---|
35 | this->velocity = velocity; |
---|
36 | |
---|
37 | this->saveTime = 0.0; |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | \brief standard destructor |
---|
44 | |
---|
45 | */ |
---|
46 | ParticleEmitter::~ParticleEmitter () |
---|
47 | {} |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | \brief this start the emitter |
---|
52 | */ |
---|
53 | void ParticleEmitter::start() {} |
---|
54 | |
---|
55 | |
---|
56 | /** |
---|
57 | \brief this stops the emitter |
---|
58 | */ |
---|
59 | void ParticleEmitter::stop() {} |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | /* these are Animation interfaces: so you can change spec values as you want */ |
---|
65 | |
---|
66 | /** |
---|
67 | \brief set the emission rate |
---|
68 | \param sets the number of particles emitted per second |
---|
69 | \param random A random emissionRate, the +- randomness of this option |
---|
70 | |
---|
71 | if you want to change the value of this variable during emission time (to make it more dynamic) |
---|
72 | you may want to use the animation class |
---|
73 | */ |
---|
74 | void ParticleEmitter::setEmissionRate(float emissionRate) |
---|
75 | {} |
---|
76 | |
---|
77 | /** |
---|
78 | \brief set the angle of the emitter |
---|
79 | \param angle around the direction in which there are particles to be emitted |
---|
80 | \param randomAngle A random spread-angle, the +- randomness of this option |
---|
81 | |
---|
82 | if you want to change the value of this variable during emission time (to make it more dynamic) |
---|
83 | you may want to use the animation class |
---|
84 | */ |
---|
85 | void ParticleEmitter::setSpread(float angle, float randomAngle) |
---|
86 | {} |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | /** |
---|
92 | \brief sets the velocity of all particles emitted |
---|
93 | \param velocity The starting velocity of the emitted particles |
---|
94 | \param random A random starting velocity, the +- randomness of this option |
---|
95 | |
---|
96 | if you want to change the value of this variable during emission time (to make it more dynamic) |
---|
97 | you may want to use the animation class |
---|
98 | */ |
---|
99 | void ParticleEmitter::setVelocity(float velocity, float random) |
---|
100 | {} |
---|
101 | |
---|
102 | /** |
---|
103 | \brief this set the time to life of a particle, after which it will die |
---|
104 | \param the time to live in seconds |
---|
105 | |
---|
106 | if you want to change the value of this variable during emission time (to make it more dynamic) |
---|
107 | you may want to use the animation class |
---|
108 | */ |
---|
109 | |
---|
110 | void ParticleEmitter::tick(float dt, ParticleSystem* system) |
---|
111 | { |
---|
112 | // saving the time |
---|
113 | float countF = (dt+this->saveTime) / emissionRate; |
---|
114 | int count = (int)round(countF); |
---|
115 | this->saveTime = countF - (float)count; |
---|
116 | |
---|
117 | for (int i = 0; i <= count; i++) |
---|
118 | // emmits from EMITTER_DOT, |
---|
119 | system->addParticle(this->getAbsCoor(), direction * velocity ); |
---|
120 | } |
---|