/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS #include "plane_emitter.h" #include "particle_system.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "debug.h" #include "class_id_DEPRECATED.h" ObjectListDefinitionID(PlaneEmitter, CL_PLANE_EMITTER); CREATE_FACTORY(PlaneEmitter); /** * standard constructor */ PlaneEmitter::PlaneEmitter(const Vector2D& size, float emissionRate, float velocity, float angle) : ParticleEmitter(emissionRate, velocity, angle) { this->init(); this->setSize(size); } /** * constructs and loads a PlaneEmitter from a XML-element * @param root the XML-element to load from */ PlaneEmitter::PlaneEmitter(const TiXmlElement* root) : ParticleEmitter() { this->init(); if (root != NULL) this->loadParams(root); } /** * standard destructor removes the EmitterSystem from the ParticleEngine */ PlaneEmitter::~PlaneEmitter () { this->setSystem(NULL); } /** @brief initializes default values of a ParitcleEmitter */ void PlaneEmitter::init() { this->registerObject(this, PlaneEmitter::_objectList); this->setSize(1.0f, 1.0f); } void PlaneEmitter::loadParams(const TiXmlElement* root) { ParticleEmitter::loadParams(root); LoadParam(root, "size", this, PlaneEmitter, setSize) .describe("The Size of the PlaneEmitter: x, y") .defaultValues(1.0f,1.0f); } void PlaneEmitter::setSize(float x, float y) { this->size = Vector2D(x, y); } void PlaneEmitter::emitParticles(unsigned int count) const { Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; Vector xDir = this->getAbsDirX() * this->size.x; Vector yDir = this->getAbsDirZ() * this->size.y; Vector zDir = this->getAbsDirY(); for (unsigned int i = 0; i < count; i++) { Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); randDir.normalize(); randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(zDir); Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; Vector plane = this->getAbsCoor() + xDir * ((float)rand()/RAND_MAX -.5) + yDir * ((float)rand()/RAND_MAX -.5); // ROTATIONAL CALCULATION (this must not be done for all types of particles.) randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); randDir.normalize(); Quaternion orient = Quaternion(M_PI, randDir); Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir); this->getSystem()->addParticle(plane, velocityV, orient, moment); } }