[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 | |
---|
[6823] | 18 | #include "box_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 | |
---|
[6823] | 30 | CREATE_FACTORY(BoxEmitter, CL_BOX_EMITTER); |
---|
[4725] | 31 | |
---|
[3926] | 32 | /** |
---|
[4836] | 33 | * standard constructor |
---|
[3926] | 34 | */ |
---|
[6823] | 35 | BoxEmitter::BoxEmitter(const Vector& size) |
---|
[3926] | 36 | { |
---|
[4726] | 37 | this->init(); |
---|
[6823] | 38 | this->setSize(size); |
---|
[4437] | 39 | } |
---|
| 40 | |
---|
[4478] | 41 | /** |
---|
[6823] | 42 | * constructs and loads a BoxEmitter from a XML-element |
---|
[4836] | 43 | * @param root the XML-element to load from |
---|
[4478] | 44 | */ |
---|
[6823] | 45 | BoxEmitter::BoxEmitter(const TiXmlElement* root) |
---|
| 46 | : ParticleEmitter() |
---|
[4437] | 47 | { |
---|
[4726] | 48 | this->init(); |
---|
[4338] | 49 | |
---|
[6823] | 50 | if (root != NULL) |
---|
| 51 | this->loadParams(root); |
---|
[3926] | 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
[4836] | 55 | * standard destructor |
---|
[3926] | 56 | |
---|
[4496] | 57 | removes the EmitterSystem from the ParticleEngine |
---|
[3926] | 58 | */ |
---|
[6823] | 59 | BoxEmitter::~BoxEmitter () |
---|
[3935] | 60 | { |
---|
[6623] | 61 | this->setSystem(NULL); |
---|
[3935] | 62 | } |
---|
[3929] | 63 | |
---|
[4478] | 64 | /** |
---|
[6623] | 65 | @brief initializes default values of a ParitcleEmitter |
---|
[4726] | 66 | */ |
---|
[6823] | 67 | void BoxEmitter::init() |
---|
[4726] | 68 | { |
---|
[6823] | 69 | this->setClassID(CL_BOX_EMITTER, "BoxEmitter"); |
---|
| 70 | this->setSize(1.0f,1.0f,1.0f); |
---|
[4726] | 71 | } |
---|
| 72 | |
---|
[6823] | 73 | void BoxEmitter::loadParams(const TiXmlElement* root) |
---|
[4437] | 74 | { |
---|
[6823] | 75 | ParticleEmitter::loadParams(root); |
---|
| 76 | |
---|
| 77 | LoadParam(root, "size", this, BoxEmitter, setSize) |
---|
| 78 | .describe("The Size of the BoxEmitter: x, y, z") |
---|
| 79 | .defaultValues(3, 1.0f,1.0f,1.0f); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void BoxEmitter::emitParticles(unsigned int count) const |
---|
| 83 | { |
---|
[6822] | 84 | Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; |
---|
[3929] | 85 | |
---|
[6822] | 86 | for (unsigned int i = 0; i < count; i++) |
---|
[3950] | 87 | { |
---|
[6822] | 88 | Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); |
---|
| 89 | randDir.normalize(); |
---|
| 90 | randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction); |
---|
| 91 | Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; |
---|
[4597] | 92 | |
---|
[6823] | 93 | Vector extension = Vector(((float)rand()/RAND_MAX -.5)*this->size.x, |
---|
| 94 | ((float)rand()/RAND_MAX -.5) *this->size.y, |
---|
| 95 | ((float)rand()/RAND_MAX -.5) * this->size.z); |
---|
| 96 | |
---|
| 97 | |
---|
[6822] | 98 | // ROTATIONAL CALCULATION (this must not be done for all types of particles.) |
---|
| 99 | randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); |
---|
| 100 | randDir.normalize(); |
---|
| 101 | Quaternion orient = Quaternion(M_PI, randDir); |
---|
| 102 | Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir); |
---|
[4176] | 103 | |
---|
[6823] | 104 | this->getSystem()->addParticle(this->getAbsCoor() + extension, velocityV, orient, moment); |
---|
[4176] | 105 | |
---|
[3950] | 106 | } |
---|
[3932] | 107 | } |
---|