Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/particles/particle_emitter.cc @ 3966

Last change on this file since 3966 was 3966, checked in by bensch, 19 years ago

orxonox/trunk: merged branches/particleEngine into the trunk, because of the new vector class
merged with command:
svn merge -r 3922:HEAD particleEngine/ ../trunk/

not merged src/story_entities/world.cc. will do this at a later time (do not forget)

File size: 3.8 KB
Line 
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: Benjamin Grauer
13   co-programmer: Patrick Boenzli
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PARTICLE
17
18#include "particle_emitter.h"
19
20#include "particle_system.h"
21#include "particle_engine.h"
22
23using namespace std;
24
25
26/**
27   \brief standard constructor
28*/
29ParticleEmitter::ParticleEmitter(const Vector& direction, float angle, float emissionRate, 
30                  float velocity)
31{
32   this->setClassName ("ParticleEmitter");
33   this->direction = direction;
34   this->setSpread(angle);
35   this->setEmissionRate(emissionRate);
36   this->setVelocity(velocity);
37
38   this->saveTime = 0.0;
39
40   ParticleEngine::getInstance()->addEmitter(this);
41}
42
43
44
45/**
46   \brief standard destructor
47
48*/
49ParticleEmitter::~ParticleEmitter () 
50{
51  ParticleEngine::getInstance()->removeEmitter(this);
52 
53}
54
55
56/**
57   \brief this start the emitter
58*/
59void ParticleEmitter::start() {}
60
61
62/**
63   \brief this stops the emitter
64*/
65void ParticleEmitter::stop() {}
66
67
68
69
70/* these are Animation interfaces: so you can change spec values as you want */
71
72/**
73   \brief set the emission rate
74   \param sets the number of particles emitted per second
75
76   if you want to change the value of this variable during emission time (to make it more dynamic)
77   you may want to use the animation class
78*/
79void ParticleEmitter::setEmissionRate(float emissionRate)
80{
81  this->emissionRate = emissionRate;
82}
83
84/**
85   \brief set the angle of the emitter
86   \param angle around the direction in which there are particles to be emitted
87   \param randomAngle A random spread-angle, the +- randomness of this option
88
89   if you want to change the value of this variable during emission time (to make it more dynamic)
90   you may want to use the animation class
91*/
92void ParticleEmitter::setSpread(float angle, float randomAngle)
93{
94  this->angle = angle;
95  this->randomAngle = randomAngle;
96}
97
98/**
99   \brief sets the velocity of all particles emitted
100   \param velocity The starting velocity of the emitted particles
101   \param random A random starting velocity, the +- randomness of this option
102
103   if you want to change the value of this variable during emission time (to make it more dynamic)
104   you may want to use the animation class
105*/
106void ParticleEmitter::setVelocity(float velocity, float randomVelocity)
107{
108  this->velocity = velocity;
109  this->randomVelocity = randomVelocity;
110}
111
112/**
113   \brief this set the time to life of a particle, after which it will die
114   \param the time to live in seconds
115
116   if you want to change the value of this variable during emission time (to make it more dynamic)
117   you may want to use the animation class
118*/
119
120void ParticleEmitter::tick(float dt, ParticleSystem* system)
121{
122  if (likely(dt > 0.0 && this->emissionRate > 0.0))
123  {
124    // saving the time
125    float count = (dt+this->saveTime) * this->emissionRate;
126    this->saveTime = modff(count, &count);
127    this->saveTime /= this->emissionRate;
128    PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime); 
129   
130    for (int i = 0; i < count; i++)
131      // emmits from EMITTER_DOT,
132      {
133        Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2);
134        randDir.normalize();
135        randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir)).apply(this->direction);
136        randDir = randDir.getNormalized()*velocity + (this->getVelocity() * system->inheritSpeed);
137
138        system->addParticle(this->getAbsCoor(), randDir);
139      }
140  }
141}
142
143/**
144   \brief outputs some nice debug information
145*/
146void ParticleEmitter::debug(void)
147{
148
149}
Note: See TracBrowser for help on using the repository browser.