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