| [4597] | 1 | /* | 
|---|
| [3926] | 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: | 
|---|
| [3938] | 12 | main-programmer: Benjamin Grauer | 
|---|
| [3926] | 13 | co-programmer: Patrick Boenzli | 
|---|
|  | 14 | */ | 
|---|
|  | 15 |  | 
|---|
| [5357] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS | 
|---|
| [3926] | 17 |  | 
|---|
| [6822] | 18 | #include "dot_emitter.h" | 
|---|
| [3926] | 19 |  | 
|---|
| [3932] | 20 | #include "particle_system.h" | 
|---|
|  | 21 |  | 
|---|
| [7193] | 22 | #include "util/loading/load_param.h" | 
|---|
|  | 23 | #include "util/loading/factory.h" | 
|---|
| [4381] | 24 | #include "debug.h" | 
|---|
|  | 25 |  | 
|---|
| [3926] | 26 | using namespace std; | 
|---|
|  | 27 |  | 
|---|
|  | 28 |  | 
|---|
| [6822] | 29 | CREATE_FACTORY(DotEmitter, CL_DOT_EMITTER); | 
|---|
| [4725] | 30 |  | 
|---|
| [3926] | 31 | /** | 
|---|
| [4836] | 32 | *  standard constructor | 
|---|
| [3926] | 33 | */ | 
|---|
| [6825] | 34 | DotEmitter::DotEmitter(float emissionRate, float velocity, float angle) | 
|---|
| [7302] | 35 | : ParticleEmitter( emissionRate, velocity, angle) | 
|---|
| [3926] | 36 | { | 
|---|
| [4726] | 37 | this->init(); | 
|---|
| [4437] | 38 | } | 
|---|
|  | 39 |  | 
|---|
| [4478] | 40 | /** | 
|---|
| [6822] | 41 | *  constructs and loads a DotEmitter from a XML-element | 
|---|
| [4836] | 42 | * @param root the XML-element to load from | 
|---|
| [4478] | 43 | */ | 
|---|
| [6822] | 44 | DotEmitter::DotEmitter(const TiXmlElement* root) | 
|---|
| [7302] | 45 | : ParticleEmitter() | 
|---|
| [4437] | 46 | { | 
|---|
| [4726] | 47 | this->init(); | 
|---|
| [4338] | 48 |  | 
|---|
| [7302] | 49 | if (root != NULL) | 
|---|
|  | 50 | this->loadParams(root); | 
|---|
| [3926] | 51 | } | 
|---|
|  | 52 |  | 
|---|
|  | 53 | /** | 
|---|
| [4836] | 54 | *  standard destructor | 
|---|
| [3926] | 55 |  | 
|---|
| [4496] | 56 | removes the EmitterSystem from the ParticleEngine | 
|---|
| [3926] | 57 | */ | 
|---|
| [6822] | 58 | DotEmitter::~DotEmitter () | 
|---|
| [3935] | 59 | { | 
|---|
| [6623] | 60 | this->setSystem(NULL); | 
|---|
| [3935] | 61 | } | 
|---|
| [3929] | 62 |  | 
|---|
| [4478] | 63 | /** | 
|---|
| [6623] | 64 | @brief initializes default values of a ParitcleEmitter | 
|---|
| [4726] | 65 | */ | 
|---|
| [6822] | 66 | void DotEmitter::init() | 
|---|
| [4726] | 67 | { | 
|---|
| [6822] | 68 | this->setClassID(CL_DOT_EMITTER, "DotEmitter"); | 
|---|
| [4726] | 69 | } | 
|---|
|  | 70 |  | 
|---|
| [6822] | 71 | void DotEmitter::emitParticles(unsigned int count) const | 
|---|
| [4437] | 72 | { | 
|---|
| [6822] | 73 | Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; | 
|---|
| [3929] | 74 |  | 
|---|
| [6822] | 75 | for (unsigned int i = 0; i < count; i++) | 
|---|
| [3950] | 76 | { | 
|---|
| [6822] | 77 | Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); | 
|---|
|  | 78 | randDir.normalize(); | 
|---|
| [6825] | 79 | randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->getAbsDirX()); | 
|---|
| [6822] | 80 | Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; | 
|---|
| [4597] | 81 |  | 
|---|
| [6822] | 82 | // ROTATIONAL CALCULATION (this must not be done for all types of particles.) | 
|---|
|  | 83 | randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); | 
|---|
|  | 84 | randDir.normalize(); | 
|---|
|  | 85 | Quaternion orient = Quaternion(M_PI, randDir); | 
|---|
|  | 86 | Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir); | 
|---|
| [4176] | 87 |  | 
|---|
| [7302] | 88 | this->getSystem()->addParticle(this->getAbsCoor() + this->getVelocity()*.1*rand()/RAND_MAX, | 
|---|
|  | 89 | velocityV, orient, moment); | 
|---|
| [4176] | 90 |  | 
|---|
| [3950] | 91 | } | 
|---|
| [3932] | 92 | } | 
|---|