Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/particleEngine: spread works, and many other functions implemented

File size: 3.5 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#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  // saving the time
123  float count = (dt+this->saveTime) * this->emissionRate;
124  this->saveTime = modff(count, &count);
125  this->saveTime /= this->emissionRate;
126
127
128  for (int i = 0; i <= count; i++)
129    // emmits from EMITTER_DOT,
130    {
131      Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2);
132      randDir.normalize();
133      randDir = Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir).apply(this->direction);
134      randDir.normalize();
135      system->addParticle(this->getAbsCoor(), randDir* velocity);
136    }
137}
Note: See TracBrowser for help on using the repository browser.