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