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: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
17 | |
---|
18 | #include "particle_system.h" |
---|
19 | |
---|
20 | #include "particle_emitter.h" |
---|
21 | #include "particle_engine.h" |
---|
22 | #include "compiler.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | |
---|
27 | /** |
---|
28 | \brief standard constructor |
---|
29 | \param count the Count of particles in the System |
---|
30 | \param type The Type of the ParticleSystem |
---|
31 | |
---|
32 | \todo this constructor is not jet implemented - do it |
---|
33 | */ |
---|
34 | ParticleSystem::ParticleSystem (unsigned int count, PARTICLE_TYPE type) |
---|
35 | { |
---|
36 | this->setClassName ("ParticleSystem"); |
---|
37 | |
---|
38 | this->particleType = type; |
---|
39 | this->particles = NULL; |
---|
40 | this->conserve = 1.0; |
---|
41 | this->setLifeSpan(5.0); |
---|
42 | |
---|
43 | ParticleEngine::getInstance()->addSystem(this); |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | \brief standard deconstructor |
---|
49 | |
---|
50 | */ |
---|
51 | ParticleSystem::~ParticleSystem() |
---|
52 | { |
---|
53 | // delete what has to be deleted here |
---|
54 | } |
---|
55 | |
---|
56 | // setting properties |
---|
57 | void ParticleSystem::setMaterial(Material* material) |
---|
58 | { |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan) |
---|
63 | { |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | void ParticleSystem::setRadius(float startRadius, float endRadius, float randomRadius) |
---|
68 | { |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | void ParticleSystem::setConserve(float conserve) |
---|
73 | { |
---|
74 | this->conserve = conserve; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | void ParticleSystem::tick(float dt) |
---|
80 | { |
---|
81 | Particle* tmpPart = particles; |
---|
82 | while (likely(tmpPart != NULL)) |
---|
83 | { |
---|
84 | tmpPart->position = tmpPart->position + tmpPart->velocity; |
---|
85 | |
---|
86 | // many more to come |
---|
87 | |
---|
88 | tmpPart = tmpPart->next; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | void ParticleSystem::draw(void) |
---|
93 | { |
---|
94 | Particle* tmpPart = particles; |
---|
95 | if (likely(tmpPart != NULL)) |
---|
96 | { |
---|
97 | glBegin(GL_POINTS); |
---|
98 | while (likely(tmpPart != NULL)) |
---|
99 | { |
---|
100 | // draw in DOT mode |
---|
101 | glVertex3f(tmpPart->position.x, tmpPart->position.y, tmpPart->position.z); |
---|
102 | |
---|
103 | |
---|
104 | tmpPart = tmpPart->next; |
---|
105 | } |
---|
106 | glEnd(); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | void ParticleSystem::addParticle(Vector position, Vector velocity, unsigned int data) |
---|
112 | { |
---|
113 | // if it is the first Particle |
---|
114 | if (unlikely(particles == NULL)) |
---|
115 | { |
---|
116 | this->particles = new Particle; |
---|
117 | this->particles->next = NULL; |
---|
118 | } |
---|
119 | // filling the List from the beginning |
---|
120 | else |
---|
121 | { |
---|
122 | Particle* tmpPart = new Particle; |
---|
123 | tmpPart->next = this->particles; |
---|
124 | this->particles = tmpPart; |
---|
125 | } |
---|
126 | |
---|
127 | particles->timeToLive = this->lifeSpan + (float)(random()/RAND_MAX)* this->randomLifeSpan; |
---|
128 | particles->position = position; |
---|
129 | particles->velocity = velocity; |
---|
130 | // particle->rotation = ; //! \todo rotation is once again something to be done. |
---|
131 | particles->mass = this->initialMass + (random()/RAND_MAX)* this->randomInitialMass; |
---|
132 | particles->radius = this->startRadius + (random()/RAND_MAX)*this->randomRadius; |
---|
133 | } |
---|
134 | |
---|