Changeset 6823 in orxonox.OLD for trunk/src/lib/particles
- Timestamp:
- Jan 29, 2006, 2:20:46 AM (19 years ago)
- Location:
- trunk/src/lib/particles
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/Makefile.am
r6822 r6823 7 7 particle_emitter.cc \ 8 8 dot_emitter.cc \ 9 box_emitter.cc \ 9 10 \ 10 11 particle_system.cc \ … … 20 21 particle_emitter.h \ 21 22 dot_emitter.h \ 23 box_emitter.h \ 22 24 \ 23 25 particle_system.h \ -
trunk/src/lib/particles/box_emitter.cc
r6822 r6823 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS 17 17 18 #include " dot_emitter.h"18 #include "box_emitter.h" 19 19 20 20 #include "particle_system.h" … … 28 28 29 29 30 CREATE_FACTORY( DotEmitter, CL_DOT_EMITTER);30 CREATE_FACTORY(BoxEmitter, CL_BOX_EMITTER); 31 31 32 32 /** 33 33 * standard constructor 34 34 */ 35 DotEmitter::DotEmitter(const Vector& direction, float angle, float emissionRate, 36 float velocity) 37 : ParticleEmitter(direction, angle, emissionRate, velocity) 35 BoxEmitter::BoxEmitter(const Vector& size) 38 36 { 39 37 this->init(); 38 this->setSize(size); 40 39 } 41 40 42 41 /** 43 * constructs and loads a DotEmitter from a XML-element42 * constructs and loads a BoxEmitter from a XML-element 44 43 * @param root the XML-element to load from 45 44 */ 46 DotEmitter::DotEmitter(const TiXmlElement* root)47 : ParticleEmitter()45 BoxEmitter::BoxEmitter(const TiXmlElement* root) 46 : ParticleEmitter() 48 47 { 49 48 this->init(); 50 49 51 52 50 if (root != NULL) 51 this->loadParams(root); 53 52 } 54 53 … … 58 57 removes the EmitterSystem from the ParticleEngine 59 58 */ 60 DotEmitter::~DotEmitter ()59 BoxEmitter::~BoxEmitter () 61 60 { 62 61 this->setSystem(NULL); … … 66 65 @brief initializes default values of a ParitcleEmitter 67 66 */ 68 void DotEmitter::init()67 void BoxEmitter::init() 69 68 { 70 this->setClassID(CL_DOT_EMITTER, "DotEmitter"); 69 this->setClassID(CL_BOX_EMITTER, "BoxEmitter"); 70 this->setSize(1.0f,1.0f,1.0f); 71 71 } 72 72 73 void DotEmitter::emitParticles(unsigned int count) const 73 void BoxEmitter::loadParams(const TiXmlElement* root) 74 { 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 74 83 { 75 84 Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; … … 82 91 Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; 83 92 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 84 98 // ROTATIONAL CALCULATION (this must not be done for all types of particles.) 85 99 randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); … … 88 102 Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir); 89 103 90 this->getSystem()->addParticle(this->getAbsCoor() , velocityV, orient, moment);104 this->getSystem()->addParticle(this->getAbsCoor() + extension, velocityV, orient, moment); 91 105 92 106 } -
trunk/src/lib/particles/box_emitter.h
r6822 r6823 1 1 /*! 2 * @file dot_emitter.h3 * Definition of a DotEmitter2 * @file box_emitter.h 3 * Definition of a BoxEmitter 4 4 */ 5 5 6 #ifndef _ DOT_EMITTER_H7 #define _ DOT_EMITTER_H6 #ifndef _BOX_EMITTER_H 7 #define _BOX_EMITTER_H 8 8 9 9 #include "particle_emitter.h" 10 10 11 // Default values12 #define DOT_EMITTER_DEFAULT_SIZE 1.013 14 11 //! A class to handle an Emitter. 15 class DotEmitter : public ParticleEmitter12 class BoxEmitter : public ParticleEmitter 16 13 { 17 14 friend class ParticleSystem; 18 15 public: 19 DotEmitter(const Vector& direction, float angle = .5, 20 float emissionRate = 1.0, float velocity = 1.0); 21 DotEmitter(const TiXmlElement* root); 22 virtual ~DotEmitter(); 16 BoxEmitter(const Vector& size); 17 BoxEmitter(const TiXmlElement* root); 18 virtual ~BoxEmitter(); 23 19 20 virtual void loadParams(const TiXmlElement* root); 24 21 25 /* controlling the emitter: interface */26 void tick(float dt);22 void setSize(float x, float y, float z); 23 void setSize(const Vector& size) { this->setSize(size.x, size.y, size.z); }; 27 24 28 25 virtual void emitParticles(unsigned int count) const; … … 32 29 33 30 private: 34 Vector emitterSize; //!< The size of the emitter (not for EMITTER_DOT). 35 31 Vector size; 36 32 }; 37 33 38 #endif /* _ DOT_EMITTER_H */34 #endif /* _BOX_EMITTER_H */ -
trunk/src/lib/particles/dot_emitter.h
r6822 r6823 8 8 9 9 #include "particle_emitter.h" 10 11 // Default values12 #define DOT_EMITTER_DEFAULT_SIZE 1.013 10 14 11 //! A class to handle an Emitter. … … 23 20 24 21 25 /* controlling the emitter: interface */26 void tick(float dt);27 28 22 virtual void emitParticles(unsigned int count) const; 29 23 30 24 private: 31 25 void init(); 32 33 private:34 Vector emitterSize; //!< The size of the emitter (not for EMITTER_DOT).35 36 26 }; 37 27 -
trunk/src/lib/particles/particle_system.cc
r6757 r6823 140 140 { 141 141 BaseObject* emitter = Factory::fabricate(element); 142 if (emitter->isA(CL_PARTICLE_EMITTER)) 143 this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter)); 142 if (emitter != NULL) 143 { 144 if (emitter->isA(CL_PARTICLE_EMITTER)) 145 this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter)); 146 else 147 { 148 PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n", 149 emitter->getClassName(), this->getClassName(), this->getName()); 150 delete emitter; 151 } 152 } 144 153 else 145 154 { 146 PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n", 147 emitter->getClassName(), this->getClassName(), this->getName()); 148 delete emitter; 155 PRINTF(2)("Could not Generate Emitter for system %s::%s (wrong type in XML-format)\n", this->getClassName(), getName()); 149 156 } 150 157 }
Note: See TracChangeset
for help on using the changeset viewer.