Changeset 6822 in orxonox.OLD for trunk/src/lib/particles/particle_emitter.cc
- Timestamp:
- Jan 29, 2006, 1:57:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/particle_emitter.cc
r6627 r6822 21 21 22 22 #include "load_param.h" 23 #include "factory.h"24 23 #include "debug.h" 25 24 #include "stdlibincl.h" … … 27 26 using namespace std; 28 27 29 30 CREATE_FACTORY(ParticleEmitter, CL_PARTICLE_EMITTER);31 32 28 /** 33 29 * standard constructor … … 36 32 float velocity) 37 33 { 38 this->init(); 39 34 this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter"); 35 36 this->system = NULL; 37 38 this->setInheritSpeed(PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED); 39 this->setEmissionMomentum(0); 40 40 this->direction = direction; 41 41 this->setSpread(angle); 42 42 this->setEmissionRate(emissionRate); 43 43 this->setEmissionVelocity(velocity); 44 } 45 46 /** 47 * constructs and loads a ParticleEmitter from a XML-element 48 * @param root the XML-element to load from 49 */ 50 ParticleEmitter::ParticleEmitter(const TiXmlElement* root) 51 { 52 this->init(); 53 54 if (root != NULL) 55 this->loadParams(root); 44 45 this->saveTime = 0.0; 56 46 } 57 47 … … 64 54 { 65 55 this->setSystem(NULL); 66 }67 68 /**69 @brief initializes default values of a ParitcleEmitter70 */71 void ParticleEmitter::init()72 {73 this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter");74 75 this->type = PARTICLE_EMITTER_DEFAULT_TYPE;76 this->emitterSize = PARTICLE_EMITTER_DEFAULT_SIZE;77 this->setInheritSpeed(PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED);78 this->setEmissionRate(PARTICLE_EMITTER_DEFAULT_EMISSION_RATE);79 this->setSize(PARTICLE_EMITTER_DEFAULT_SIZE);80 this->setEmissionMomentum(0);81 this->setEmissionVelocity(1.0);82 this->setSpread(M_PI);83 84 this->system = NULL;85 86 this->saveTime = 0.0;87 56 } 88 57 … … 94 63 { 95 64 PNode::loadParams(root); 96 97 LoadParam(root, "type", this, ParticleEmitter, setType)98 .describe("What type of emitter is this [dot, plane, cube, sphere].");99 100 LoadParam(root, "size", this, ParticleEmitter, setSize)101 .describe("How big the emitter is (no effect on dot-emitters)");102 65 103 66 LoadParam(root, "rate", this, ParticleEmitter, setEmissionRate) … … 139 102 void ParticleEmitter::stop() {} 140 103 141 142 143 144 145 /**146 * @param type the new Type of this emitter147 */148 void ParticleEmitter::setType(EMITTER_TYPE type)149 {150 this->type = type;151 }152 153 /**154 * sets the type of emitter155 * @param type the type as a const char*156 dot: EMITTER_DOT, plane: EMITTER_PLANE, cube: EMITTER_CUBE, sphere, EMITTER_SPHERE;157 */158 void ParticleEmitter::setType(const char* type)159 {160 if (!strcmp(type, "plane"))161 this->setType(EMITTER_PLANE);162 else if (!strcmp(type, "cube"))163 this->setType(EMITTER_CUBE);164 else if (!strcmp(type, "sphere"))165 this->setType(EMITTER_SPHERE);166 else167 this->setType(EMITTER_DOT);168 }169 170 const char* ParticleEmitter::getTypeC() const171 {172 if (this->type == EMITTER_PLANE)173 return "EMITTER_PLANE";174 else if (this->type == EMITTER_CUBE)175 return "EMITTER_CUBE";176 else if (this->type == EMITTER_SPHERE)177 return "EMITTER_SPHERE";178 else179 return "EMITTER_DOT";180 }181 182 /**183 * sets a new size to the emitter184 */185 void ParticleEmitter::setSize(float emitterSize)186 {187 if (emitterSize > 0.0)188 this->emitterSize = emitterSize;189 else190 emitterSize = 0.0;191 }192 104 193 105 /** … … 280 192 PRINTF(5)("emitting %f particles, saving %f seconds for the next timestep\n", count, this->saveTime); 281 193 282 if (likely(count > 0 ))194 if (likely(count > 0.0f)) 283 195 { 284 Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; 196 this->emitParticles((unsigned int)count); 197 198 /* Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; 285 199 for (int i = 0; i < (int)count; i++) 286 200 { … … 294 208 Vector extension; // the Vector for different fields. 295 209 296 if (this->type & EMITTER_PLANE)297 {298 extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5));299 extension = this->getAbsDir().apply(extension);300 }301 else if (this->type & EMITTER_CUBE)302 {303 extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize;304 }210 // if (this->type & EMITTER_PLANE) 211 // { 212 // extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5)); 213 // extension = this->getAbsDir().apply(extension); 214 // } 215 // else if (this->type & EMITTER_CUBE) 216 // { 217 // extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize; 218 // } 305 219 306 220 … … 312 226 313 227 this->system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV, orient, moment); 314 } 228 } */ 315 229 } 316 230 } … … 322 236 void ParticleEmitter::debug() const 323 237 { 324 PRINT(0)(" Emitter %s\n", this->getName());238 PRINT(0)(" ParticleEmitter %s::%s\n", this->getClassName(), this->getName()); 325 239 PRINT(0)(" EmissionRate: %f, Speed: %f, SpreadAngle: %f\n", this->getEmissionRate(), this->getEmissionVelocity(), this->getSpread()); 326 PRINT(0)(" Size %f, Type: %s\n", this->getSize(), this->getTypeC()); 327 } 240 }
Note: See TracChangeset
for help on using the changeset viewer.