- Timestamp:
- Jan 29, 2006, 1:57:03 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 11 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r6818 r6822 256 256 CL_FONT = 0x00000802, 257 257 258 CL_PARTICLE_EMITTER = 0x00 201852,259 CL_PARTICLE_SYSTEM = 0x00 202000,258 CL_PARTICLE_EMITTER = 0x00801000, 259 CL_PARTICLE_SYSTEM = 0x00802000, 260 260 CL_SPRITE_PARTICLES = 0x00000853, 261 261 CL_SPARK_PARTICLES = 0x00000854, … … 263 263 CL_DOT_PARTICLES = 0x00000856, 264 264 CL_MODEL_PARTICLES = 0x00000857, 265 // CL_TEMPLATE_PARTICLES = 0x00000857, 265 CL_DOT_EMITTER = 0x00000861, 266 CL_BOX_EMITTER = 0x00000862, 267 CL_SPHERE_EMITTER = 0x00000863, 268 CL_MODEL_EMITTER = 0x00000864, 266 269 267 270 CL_MATERIAL = 0x00000804, … … 278 281 CL_ENVIRONMENT = 0x00000821, 279 282 CL_SHADER = 0x00000822, 280 CL_FOG_EFFECT = 0x 70000001,281 CL_LENSE_FLARE = 0x 70000002,283 CL_FOG_EFFECT = 0x00000841, 284 CL_LENSE_FLARE = 0x00000842, 282 285 283 286 /// GL-GUI … … 287 290 CL_GLGUI_CHECKBUTTON = 0x00000904, 288 291 CL_GLGUI_RADIOBUTTON = 0x00000905, 289 CL_GLGUI_CONTAINER = 0x00002 906,292 CL_GLGUI_CONTAINER = 0x00002000, 290 293 CL_GLGUI_BOX = 0x00000907, 291 294 CL_GLGUI_FRAME = 0x00000908, -
trunk/src/lib/particles/Makefile.am
r6652 r6822 6 6 libORXparticles_a_SOURCES = \ 7 7 particle_emitter.cc \ 8 dot_emitter.cc \ 8 9 \ 9 10 particle_system.cc \ … … 18 19 noinst_HEADERS = \ 19 20 particle_emitter.h \ 21 dot_emitter.h \ 20 22 \ 21 23 particle_system.h \ -
trunk/src/lib/particles/dot_emitter.cc
r6820 r6822 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS 17 17 18 #include " particle_emitter.h"18 #include "dot_emitter.h" 19 19 20 20 #include "particle_system.h" … … 28 28 29 29 30 CREATE_FACTORY( ParticleEmitter, CL_PARTICLE_EMITTER);30 CREATE_FACTORY(DotEmitter, CL_DOT_EMITTER); 31 31 32 32 /** 33 33 * standard constructor 34 34 */ 35 ParticleEmitter::ParticleEmitter(const Vector& direction, float angle, float emissionRate, 36 float velocity) 35 DotEmitter::DotEmitter(const Vector& direction, float angle, float emissionRate, 36 float velocity) 37 : ParticleEmitter(direction, angle, emissionRate, velocity) 37 38 { 38 39 this->init(); 39 40 this->direction = direction;41 this->setSpread(angle);42 this->setEmissionRate(emissionRate);43 this->setEmissionVelocity(velocity);44 40 } 45 41 46 42 /** 47 * constructs and loads a ParticleEmitter from a XML-element43 * constructs and loads a DotEmitter from a XML-element 48 44 * @param root the XML-element to load from 49 45 */ 50 ParticleEmitter::ParticleEmitter(const TiXmlElement* root) 46 DotEmitter::DotEmitter(const TiXmlElement* root) 47 : ParticleEmitter() 51 48 { 52 49 this->init(); … … 61 58 removes the EmitterSystem from the ParticleEngine 62 59 */ 63 ParticleEmitter::~ParticleEmitter ()60 DotEmitter::~DotEmitter () 64 61 { 65 62 this->setSystem(NULL); … … 69 66 @brief initializes default values of a ParitcleEmitter 70 67 */ 71 void ParticleEmitter::init()68 void DotEmitter::init() 72 69 { 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; 70 this->setClassID(CL_DOT_EMITTER, "DotEmitter"); 87 71 } 88 72 89 /** 90 * loads a ParticleEmitter from a XML-element 91 * @param root the XML-element to load from 92 */ 93 void ParticleEmitter::loadParams(const TiXmlElement* root) 73 void DotEmitter::emitParticles(unsigned int count) const 94 74 { 95 PNode::loadParams(root);75 Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; 96 76 97 LoadParam(root, "type", this, ParticleEmitter, setType) 98 .describe("What type of emitter is this [dot, plane, cube, sphere]."); 77 for (unsigned int i = 0; i < count; i++) 78 { 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; 99 83 100 LoadParam(root, "size", this, ParticleEmitter, setSize) 101 .describe("How big the emitter is (no effect on dot-emitters)"); 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); 102 89 103 LoadParam(root, "rate", this, ParticleEmitter, setEmissionRate) 104 .describe("How many particles should be emittet from this emitter"); 90 this->getSystem()->addParticle(this->getAbsCoor(), velocityV, orient, moment); 105 91 106 LoadParam(root, "inherit-speed", this, ParticleEmitter, setInheritSpeed)107 .describe("the extent, the speed of the emitter has on the particles");108 109 LoadParam(root, "emission-velocity", this, ParticleEmitter, setEmissionVelocity)110 .describe("How fast the particles are emittet (their initial speed)");111 112 LoadParam(root, "emission-momentum", this, ParticleEmitter, setEmissionMomentum)113 .describe("How fast the particles rotation is at emissiontime (their initial momentum)");114 115 LoadParam(root, "spread", this, ParticleEmitter, setSpread)116 .describe("The angle the particles are emitted from (angle, deviation)");117 118 119 LoadParam(root, "emission-direction", this, ParticleEmitter, setDirection);120 }121 122 void ParticleEmitter::setSystem(ParticleSystem* system)123 {124 if (system != NULL)125 system->addEmitter(this);126 else if (this->system != NULL)127 this->system->removeEmitter(this);128 }129 130 /**131 * this start the emitter132 */133 void ParticleEmitter::start() {}134 135 136 /**137 * this stops the emitter138 */139 void ParticleEmitter::stop() {}140 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 193 /**194 * set the emission rate195 * @param emissionRate: sets the number of particles emitted per second196 197 if you want to change the value of this variable during emission time (to make it more dynamic)198 you may want to use the animation class199 */200 void ParticleEmitter::setEmissionRate(float emissionRate)201 {202 if (emissionRate > 0.0)203 this->emissionRate = emissionRate;204 else205 this->emissionRate = 0.0;206 }207 208 /**209 * how much of the speed from the ParticleEmitter should flow onto the ParticleSystem210 * @param value a Value between zero and one211 212 if you want to change the value of this variable during emission time (to make it more dynamic)213 you may want to use the animation class214 */215 void ParticleEmitter::setInheritSpeed(float value)216 {217 if (unlikely(value > 1.0))218 this->inheritSpeed = 1;219 else if (unlikely(value < 0.0))220 this->inheritSpeed = 0;221 else222 this->inheritSpeed = value;223 }224 225 /**226 * set the angle of the emitter227 * @param angle around the direction in which there are particles to be emitted228 * @param randomAngle A random spread-angle, the +- randomness of this option229 230 if you want to change the value of this variable during emission time (to make it more dynamic)231 you may want to use the animation class232 */233 void ParticleEmitter::setSpread(float angle, float randomAngle)234 {235 this->angle = angle;236 this->randomAngle = randomAngle;237 }238 239 /**240 * sets the initial velocity of all particles emitted241 * @param velocity The starting velocity of the emitted particles242 * @param randomVelocity A random starting velocity, the +- randomness of this option243 244 if you want to change the value of this variable during emission time (to make it more dynamic)245 you may want to use the animation class246 */247 void ParticleEmitter::setEmissionVelocity(float velocity, float randomVelocity)248 {249 this->velocity = velocity;250 this->randomVelocity = randomVelocity;251 }252 253 /**254 * sets the initial Momentum of all particles emitted255 * @param momentum the new Momentum (just a float for being not too complicated).256 * @param randomMomentum variation from the given value.257 */258 void ParticleEmitter::setEmissionMomentum(float momentum, float randomMomentum)259 {260 this->momentum = momentum;261 this->momentumRandom = randomMomentum;262 }263 264 /**265 * this set the time to life of a particle, after which it will die266 * @param dt: the time to live in seconds267 * @param system: the system into which to emitt268 269 if you want to change the value of this variable during emission time (to make it more dynamic)270 you may want to use the animation class271 */272 void ParticleEmitter::tick(float dt)273 {274 assert (this->system != NULL);275 if (likely(dt > 0.0 && this->emissionRate > 0.0))276 {277 // saving the time (particles only partly emitted in this timestep)278 float count = (dt+this->saveTime) * this->emissionRate;279 this->saveTime = modff(count, &count) / this->emissionRate;280 PRINTF(5)("emitting %f particles, saving %f seconds for the next timestep\n", count, this->saveTime);281 282 if (likely(count > 0))283 {284 Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;285 for (int i = 0; i < (int)count; i++)286 {287 Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);288 randDir.normalize();289 randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);290 Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;291 292 // this should spread the Particles evenly. if the Emitter is moved around quickly293 Vector equalSpread = this->getVelocity() * rand()/RAND_MAX * dt;294 Vector extension; // the Vector for different fields.295 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 }305 306 307 // ROTATIONAL CALCULATION (this must not be done for all types of particles.)308 randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);309 randDir.normalize();310 Quaternion orient = Quaternion(M_PI, randDir);311 Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);312 313 this->system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV, orient, moment);314 }315 }316 92 } 317 93 } 318 319 /**320 * outputs some nice debug information321 */322 void ParticleEmitter::debug() const323 {324 PRINT(0)(" Emitter %s\n", this->getName());325 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 } -
trunk/src/lib/particles/dot_emitter.h
r6820 r6822 1 1 /*! 2 * @file particle_emitter.h3 * Definition of a ParticleEmitter4 */2 * @file dot_emitter.h 3 * Definition of a DotEmitter 4 */ 5 5 6 #ifndef _ PARTICLE_EMITTER_H7 #define _ PARTICLE_EMITTER_H6 #ifndef _DOT_EMITTER_H 7 #define _DOT_EMITTER_H 8 8 9 #include "p_node.h" 10 11 // FORWARD DECLARATION 12 class ParticleSystem; 13 class TiXmlElement; 9 #include "particle_emitter.h" 14 10 15 11 // Default values 16 #define PARTICLE_EMITTER_DEFAULT_SIZE 1.0 17 #define PARTICLE_EMITTER_DEFAULT_EMISSION_RATE 50 18 #define PARTICLE_EMITTER_DEFAULT_TYPE EMITTER_DOT 19 #define PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED 0.0 20 #define PARTICLE_EMITTER_DEFAULT_SPREAD M_PI 21 22 //! The form of the Emitter to emit from 23 typedef enum EMITTER_TYPE 24 { 25 EMITTER_DOT = 1, 26 EMITTER_PLANE = 2, 27 EMITTER_SPHERE = 4, 28 EMITTER_CUBE = 8 29 }; 12 #define DOT_EMITTER_DEFAULT_SIZE 1.0 30 13 31 14 //! A class to handle an Emitter. 32 class ParticleEmitter : public PNode15 class DotEmitter : public ParticleEmitter 33 16 { 34 17 friend class ParticleSystem; 35 18 public: 36 ParticleEmitter(const Vector& direction, float angle = .5,37 38 ParticleEmitter(const TiXmlElement* root);39 virtual ~ ParticleEmitter();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(); 40 23 41 void init();42 virtual void loadParams(const TiXmlElement* root);43 24 44 25 /* controlling the emitter: interface */ 45 void start();46 void stop();47 26 void tick(float dt); 48 27 49 void setSystem(ParticleSystem* system); 50 ParticleSystem* getSystem() const { return this->system; }; 51 52 /* controlling the behavour: these can be used as Animation interfaces */ 53 void setType(EMITTER_TYPE type); 54 void setType(const char* type); 55 void setSize(float emitterSize); 56 void setEmissionRate(float emissionRate); 57 void setInheritSpeed(float value); 58 void setSpread(float angle, float randomAngle = 0.0); 59 void setEmissionVelocity(float velocity, float randomVelocity = 0.0); 60 void setEmissionMomentum(float momentum, float randomMomentum = 0.0); 61 62 void setDirection(float x, float y, float z) { this->direction = Vector(x,y,z); } 63 ; //!< todo this should be done via PNODE 64 65 /** @returns the type of the emitter */ 66 inline EMITTER_TYPE getType() const { return this->type; }; 67 /** @returns the Type as a const char * */ 68 const char* getTypeC() const; 69 /** @returns the Size of the emitter */ 70 inline float getSize() const { return this->emitterSize; }; 71 /** @returns the emissionRate */ 72 inline float getEmissionRate() const { return this->emissionRate; }; 73 /** @returns the inherit-speed-factor */ 74 inline float getInheritSpeed() const { return this->inheritSpeed; }; 75 /** @returns the SpreadAngle of the emitter */ 76 inline float getSpread() const { return this->angle; }; 77 /** @returns the EmissionVelocity of the emitter */ 78 inline float getEmissionVelocity() const { return this->velocity; }; 79 /** @returns the EmissionMomentum of this emitter */ 80 inline float getEmissionMomentum() const { return this->momentum; }; 81 82 void debug() const; 83 28 virtual void emitParticles(unsigned int count) const; 84 29 85 30 private: 86 ParticleSystem* system; //!< The ParticleSystem this Emitter Emits into.31 void init(); 87 32 88 EMITTER_TYPE type; //!< The type of emitter this is. 89 float emitterSize; //!< The size of the emitter (not for EMITTER_DOT). 90 float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed. 91 Vector direction; //!< emition direction. 92 float angle; //!< max angle from the direction of the emitter 93 float randomAngle; //!< random emission angle (angle +- angleRandom is the emitted angle. 94 float emissionRate; //!< amount of particles per seconds emitted by emitter. 95 float velocity; //!< the initial speed of a Particles. 96 float randomVelocity; //!< the random variation from the initial Speed. 97 float momentum; //!< The Initial spped of the Rotation. 98 float momentumRandom; //!< The random variation of the Momentum. 33 private: 34 Vector emitterSize; //!< The size of the emitter (not for EMITTER_DOT). 99 35 100 float saveTime; //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big).101 36 }; 102 37 103 #endif /* _ PARTICLE_EMITTER_H */38 #endif /* _DOT_EMITTER_H */ -
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 } -
trunk/src/lib/particles/particle_emitter.h
r6620 r6822 16 16 #define PARTICLE_EMITTER_DEFAULT_SIZE 1.0 17 17 #define PARTICLE_EMITTER_DEFAULT_EMISSION_RATE 50 18 #define PARTICLE_EMITTER_DEFAULT_TYPE EMITTER_DOT19 18 #define PARTICLE_EMITTER_DEFAULT_INHERIT_SPEED 0.0 20 19 #define PARTICLE_EMITTER_DEFAULT_SPREAD M_PI 21 22 //! The form of the Emitter to emit from23 typedef enum EMITTER_TYPE24 {25 EMITTER_DOT = 1,26 EMITTER_PLANE = 2,27 EMITTER_SPHERE = 4,28 EMITTER_CUBE = 829 };30 20 31 21 //! A class to handle an Emitter. … … 34 24 friend class ParticleSystem; 35 25 public: 36 ParticleEmitter(const Vector& direction , float angle = .5,26 ParticleEmitter(const Vector& direction = Vector(1.0,0.0,0.0) , float angle = .5, 37 27 float emissionRate = 1.0, float velocity = 1.0); 38 ParticleEmitter(const TiXmlElement* root);39 28 virtual ~ParticleEmitter(); 40 29 41 void init(); 42 virtual void loadParams(const TiXmlElement* root); 30 virtual void loadParams(const TiXmlElement* root = NULL); 43 31 44 32 /* controlling the emitter: interface */ … … 51 39 52 40 /* controlling the behavour: these can be used as Animation interfaces */ 53 void setType(EMITTER_TYPE type);54 void setType(const char* type);55 void setSize(float emitterSize);56 41 void setEmissionRate(float emissionRate); 57 42 void setInheritSpeed(float value); … … 60 45 void setEmissionMomentum(float momentum, float randomMomentum = 0.0); 61 46 62 void setDirection(float x, float y, float z) { this->direction = Vector(x,y,z); } 63 ; //!< todo this should be done via PNODE 47 void setDirection(float x, float y, float z) { this->direction = Vector(x,y,z); }; //!< todo this should be done via PNODE 64 48 65 /** @returns the type of the emitter */66 inline EMITTER_TYPE getType() const { return this->type; };67 /** @returns the Type as a const char * */68 const char* getTypeC() const;69 /** @returns the Size of the emitter */70 inline float getSize() const { return this->emitterSize; };71 49 /** @returns the emissionRate */ 72 50 inline float getEmissionRate() const { return this->emissionRate; }; … … 80 58 inline float getEmissionMomentum() const { return this->momentum; }; 81 59 60 virtual void emitParticles(unsigned int count) const = 0; 61 82 62 void debug() const; 83 63 64 protected: 84 65 85 private:86 ParticleSystem* system; //!< The ParticleSystem this Emitter Emits into.87 88 EMITTER_TYPE type; //!< The type of emitter this is.89 float emitterSize; //!< The size of the emitter (not for EMITTER_DOT).90 66 float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed. 91 67 Vector direction; //!< emition direction. 92 68 float angle; //!< max angle from the direction of the emitter 93 69 float randomAngle; //!< random emission angle (angle +- angleRandom is the emitted angle. 94 float emissionRate; //!< amount of particles per seconds emitted by emitter.95 70 float velocity; //!< the initial speed of a Particles. 96 71 float randomVelocity; //!< the random variation from the initial Speed. … … 98 73 float momentumRandom; //!< The random variation of the Momentum. 99 74 75 private: 76 ParticleSystem* system; //!< The ParticleSystem this Emitter Emits into. 100 77 float saveTime; //!< The time that was missing by the last Tick (otherwise there would be no emission when framefate is too big). 78 float emissionRate; //!< amount of particles per seconds emitted by emitter. 101 79 }; 102 80 -
trunk/src/world_entities/projectiles/bomb.cc
r6700 r6822 25 25 #include "object_manager.h" 26 26 27 #include " particle_emitter.h"27 #include "dot_emitter.h" 28 28 #include "particle_system.h" 29 29 … … 50 50 this->lifeSpan = 15; 51 51 52 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);52 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 53 53 this->emitter->setParent(this); 54 54 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/projectiles/guided_missile.cc
r6760 r6822 23 23 #include "class_list.h" 24 24 25 #include " particle_emitter.h"25 #include "dot_emitter.h" 26 26 #include "sprite_particles.h" 27 27 … … 46 46 this->maxVelocity = 75; 47 47 48 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);48 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 49 49 this->emitter->setParent(this); 50 50 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/projectiles/hyperblast.cc
r6821 r6822 23 23 #include "class_list.h" 24 24 25 #include " particle_emitter.h"25 #include "dot_emitter.h" 26 26 #include "sprite_particles.h" 27 27 #include "spark_particles.h" … … 47 47 this->size = 4.0; 48 48 49 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); 50 this->emitter->setType( EMITTER_CUBE ); 51 this->emitter->setSize(10); 49 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 52 50 this->emitter->setParent(this); 53 51 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/projectiles/laser.cc
r6753 r6822 26 26 #include "model.h" 27 27 28 #include " particle_emitter.h"28 #include "dot_emitter.h" 29 29 #include "sprite_particles.h" 30 #include <cassert>31 30 32 31 #include <cassert> 33 34 32 35 33 using namespace std; … … 50 48 this->lifeSpan = 5.0; 51 49 52 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);50 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 53 51 this->emitter->setParent(this); 54 52 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/projectiles/rocket.cc
r6700 r6822 23 23 #include "class_list.h" 24 24 25 #include " particle_emitter.h"25 #include "dot_emitter.h" 26 26 #include "sprite_particles.h" 27 27 … … 45 45 this->lifeSpan = 5; 46 46 47 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);47 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 48 48 this->emitter->setParent(this); 49 49 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/projectiles/test_bullet.cc
r6700 r6822 23 23 #include "class_list.h" 24 24 25 #include " particle_emitter.h"25 #include "dot_emitter.h" 26 26 #include "sprite_particles.h" 27 27 … … 45 45 this->lifeSpan = 2; 46 46 47 this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);47 this->emitter = new DotEmitter(Vector(0,1,0), M_2_PI, 100, 5); 48 48 this->emitter->setParent(this); 49 49 this->emitter->setSpread(M_PI, M_PI); -
trunk/src/world_entities/space_ships/space_ship.cc
r6815 r6822 28 28 #include "weapons/cannon.h" 29 29 30 #include " particle_emitter.h"30 #include "dot_emitter.h" 31 31 #include "sprite_particles.h" 32 32 … … 205 205 dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); 206 206 207 this->burstEmitter = new ParticleEmitter(Vector(1,0,0), .01, 200, 0.0);207 this->burstEmitter = new DotEmitter(Vector(1,0,0), .01, 200, 0.0); 208 208 this->burstEmitter->setParent(this); 209 209 this->burstEmitter->setRelCoor(-1, .5, 0); … … 531 531 532 532 byte b; 533 533 534 534 while ( SYNCHELP_READ_REMAINING()>0 ) 535 535 { 536 536 SYNCHELP_READ_BYTE( b, NWT_SS_B ); 537 537 538 538 if ( b == DATA_state ) 539 539 { … … 544 544 continue; 545 545 } 546 546 547 547 if ( b == DATA_flags ) 548 548 { … … 559 559 bRollL = (flags & MASK_bRollL) != 0; 560 560 bRollR = (flags & MASK_bRollR) != 0; 561 561 562 562 continue; 563 563 } 564 564 565 565 if ( b == DATA_mouse ) 566 566 { … … 569 569 SYNCHELP_READ_FLOAT( mouseDir.v.y, NWT_SS_MOUSEDIRY ); 570 570 SYNCHELP_READ_FLOAT( mouseDir.v.z, NWT_SS_MOUSEDIRZ ); 571 571 572 572 continue; 573 573 } 574 574 575 575 if ( b == DATA_sync ) 576 576 { 577 577 if ( this->getOwner() != this->getHostID() ) 578 578 SYNCHELP_READ_FKT( PNode::writeSync, NWT_SS_PN_SYNC ); 579 579 580 580 continue; 581 581 } 582 582 583 583 if ( b == DATA_velocity ) 584 584 { … … 588 588 } 589 589 } 590 590 591 591 return SYNCHELP_READ_N; 592 592 } … … 621 621 622 622 *reciever = 0; 623 623 624 624 if ( this->getOwner() == this->getHostID() && PNode::needsReadSync() ) 625 625 {
Note: See TracChangeset
for help on using the changeset viewer.