1 | /* |
---|
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: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: Patrick Boenzli |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
17 | |
---|
18 | #include "dot_emitter.h" |
---|
19 | |
---|
20 | #include "particle_system.h" |
---|
21 | |
---|
22 | #include "util/loading/load_param.h" |
---|
23 | #include "util/loading/factory.h" |
---|
24 | #include "debug.h" |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | CREATE_FACTORY(DotEmitter, CL_DOT_EMITTER); |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | DotEmitter::DotEmitter(float emissionRate, float velocity, float angle) |
---|
35 | : ParticleEmitter( emissionRate, velocity, angle) |
---|
36 | { |
---|
37 | this->init(); |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * constructs and loads a DotEmitter from a XML-element |
---|
42 | * @param root the XML-element to load from |
---|
43 | */ |
---|
44 | DotEmitter::DotEmitter(const TiXmlElement* root) |
---|
45 | : ParticleEmitter() |
---|
46 | { |
---|
47 | this->init(); |
---|
48 | |
---|
49 | if (root != NULL) |
---|
50 | this->loadParams(root); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * standard destructor |
---|
55 | |
---|
56 | removes the EmitterSystem from the ParticleEngine |
---|
57 | */ |
---|
58 | DotEmitter::~DotEmitter () |
---|
59 | { |
---|
60 | this->setSystem(NULL); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | @brief initializes default values of a ParitcleEmitter |
---|
65 | */ |
---|
66 | void DotEmitter::init() |
---|
67 | { |
---|
68 | this->setClassID(CL_DOT_EMITTER, "DotEmitter"); |
---|
69 | } |
---|
70 | |
---|
71 | void DotEmitter::emitParticles(unsigned int count) const |
---|
72 | { |
---|
73 | Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; |
---|
74 | |
---|
75 | for (unsigned int i = 0; i < count; i++) |
---|
76 | { |
---|
77 | Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); |
---|
78 | randDir.normalize(); |
---|
79 | randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->getAbsDirX()); |
---|
80 | Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; |
---|
81 | |
---|
82 | // ROTATIONAL CALCULATION (this must not be done for all types of particles.) |
---|
83 | randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); |
---|
84 | randDir.normalize(); |
---|
85 | Quaternion orient = Quaternion(M_PI, randDir); |
---|
86 | Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir); |
---|
87 | |
---|
88 | this->getSystem()->addParticle(this->getAbsCoor() + this->getVelocity()*.1*rand()/RAND_MAX, |
---|
89 | velocityV, orient, moment); |
---|
90 | |
---|
91 | } |
---|
92 | } |
---|