Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/particleEngine/src/lib/graphics/particles/particle_emitter.cc @ 3934

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

orxonox/branches/particleEngine: particles get deleted after theit life is over

File size: 3.1 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: ...
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
22using namespace std;
23
24
25/**
26   \brief standard constructor
27*/
28ParticleEmitter::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->setEmissionRate(emissionRate);
35   this->velocity = velocity;
36
37   this->saveTime = 0.0;
38}
39
40
41
42/**
43   \brief standard destructor
44
45*/
46ParticleEmitter::~ParticleEmitter () 
47{}
48
49
50/**
51   \brief this start the emitter
52*/
53void ParticleEmitter::start() {}
54
55
56/**
57   \brief this stops the emitter
58*/
59void 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
70   if you want to change the value of this variable during emission time (to make it more dynamic)
71   you may want to use the animation class
72*/
73void ParticleEmitter::setEmissionRate(float emissionRate)
74{
75  this->emissionRate = emissionRate;
76}
77
78/**
79   \brief set the angle of the emitter
80   \param angle around the direction in which there are particles to be emitted
81   \param randomAngle A random spread-angle, the +- randomness of this option
82
83   if you want to change the value of this variable during emission time (to make it more dynamic)
84   you may want to use the animation class
85*/
86void ParticleEmitter::setSpread(float angle, float randomAngle)
87{}
88
89
90
91
92/**
93   \brief sets the velocity of all particles emitted
94   \param velocity The starting velocity of the emitted particles
95   \param random A random starting velocity, the +- randomness of this option
96
97   if you want to change the value of this variable during emission time (to make it more dynamic)
98   you may want to use the animation class
99*/
100void ParticleEmitter::setVelocity(float velocity, float random)
101{}
102
103/**
104   \brief this set the time to life of a particle, after which it will die
105   \param the time to live in seconds
106
107   if you want to change the value of this variable during emission time (to make it more dynamic)
108   you may want to use the animation class
109*/
110
111void ParticleEmitter::tick(float dt, ParticleSystem* system)
112{
113  // saving the time
114  float count = (dt+this->saveTime) * this->emissionRate;
115  this->saveTime = modff(count, &count);
116  this->saveTime /= this->emissionRate;
117
118  for (int i = 0; i <= count; i++)
119    // emmits from EMITTER_DOT,
120    {
121      Vector randDir = Quaternion(Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2), angle).apply(this->direction);
122      randDir.normalize();
123      system->addParticle(this->getAbsCoor(), randDir* velocity);
124    }
125}
Note: See TracBrowser for help on using the repository browser.