Changeset 4217 in orxonox.OLD for orxonox/branches/movie_player/src/lib/graphics/particles
- Timestamp:
- May 18, 2005, 11:27:40 AM (20 years ago)
- Location:
- orxonox/branches/movie_player/src/lib/graphics/particles
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/movie_player/src/lib/graphics/particles/particle_emitter.cc
r3966 r4217 124 124 // saving the time 125 125 float count = (dt+this->saveTime) * this->emissionRate; 126 this->saveTime = modff(count, &count); 127 this->saveTime /= this->emissionRate; 126 this->saveTime = modff(count, &count) / this->emissionRate; 128 127 PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime); 129 128 130 for (int i = 0; i < count; i++) 131 // emmits from EMITTER_DOT, 129 if (likely(count > 0)) 132 130 { 133 Vector randDir = Vector(random()-RAND_MAX/2, random()-RAND_MAX/2, random()-RAND_MAX/2); 134 randDir.normalize(); 135 randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)random()/RAND_MAX -.5), randDir)).apply(this->direction); 136 randDir = randDir.getNormalized()*velocity + (this->getVelocity() * system->inheritSpeed); 131 Vector inheritVelocity = this->getVelocity() * system->inheritSpeed; 132 for (int i = 0; i < count; i++) 133 // emmits from EMITTER_DOT, 134 { 135 Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); 136 randDir.normalize(); 137 randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction); 138 Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; 137 139 138 system->addParticle(this->getAbsCoor(), randDir); 140 // this should spread the Particles evenly. if the Emitter is moved around quickly 141 Vector equalSpread = this->getVelocity() * random()/RAND_MAX * dt; 142 143 system->addParticle(this->getAbsCoor() - equalSpread, velocityV); 144 } 139 145 } 140 146 } -
orxonox/branches/movie_player/src/lib/graphics/particles/particle_emitter.h
r3966 r4217 22 22 23 23 public: 24 ParticleEmitter(const Vector& direction, float angle = .5, float emissionRate = 1.0,25 float velocity = 1.0);24 ParticleEmitter(const Vector& direction, float angle = .5, 25 float emissionRate = 1.0, float velocity = 1.0); 26 26 virtual ~ParticleEmitter(void); 27 27 -
orxonox/branches/movie_player/src/lib/graphics/particles/particle_engine.cc
r3966 r4217 228 228 void ParticleEngine::tick(float dt) 229 229 { 230 // add new Particles to each System connected to an Emitter.231 tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator();232 ParticleConnection* tmpConnection = tmpConIt->nextElement();233 while(tmpConnection)234 {235 tmpConnection->emitter->tick(dt, tmpConnection->system);236 tmpConnection = tmpConIt->nextElement();237 }238 delete tmpConIt;239 240 241 230 // ticks all the ParticleSystems 242 231 tIterator<ParticleSystem>* tmpIt = systemList->getIterator(); … … 248 237 } 249 238 delete tmpIt; 239 240 // add new Particles to each System connected to an Emitter. 241 tIterator<ParticleConnection>* tmpConIt = connectionList->getIterator(); 242 ParticleConnection* tmpConnection = tmpConIt->nextElement(); 243 while(tmpConnection) 244 { 245 tmpConnection->emitter->tick(dt, tmpConnection->system); 246 tmpConnection = tmpConIt->nextElement(); 247 } 248 delete tmpConIt; 250 249 } 251 250 252 251 /** 253 252 \brief draws all the systems and their Particles. 254 */ 255 void ParticleEngine::draw(void) 253 \param dt the time passed in seconds (since the last Frame) 254 */ 255 void ParticleEngine::draw(float dt) 256 256 { 257 257 tIterator<ParticleSystem>* tmpIt = systemList->getIterator(); … … 259 259 while(tmpSys) 260 260 { 261 tmpSys->draw( );261 tmpSys->draw(dt); 262 262 tmpSys = tmpIt->nextElement(); 263 263 } -
orxonox/branches/movie_player/src/lib/graphics/particles/particle_engine.h
r3966 r4217 8 8 9 9 #include "base_object.h" 10 #include "particle_system.h" 11 #include "particle_emitter.h" 10 12 11 13 // FORWARD DEFINITION … … 28 30 29 31 void tick(float dt); 30 void draw( void);32 void draw(float dt); 31 33 32 34 void addSystem(ParticleSystem* system); -
orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.cc
r3966 r4217 35 35 { 36 36 this->setClassName ("ParticleSystem"); 37 this->material = NULL; 37 38 this->name = NULL; 38 39 this->maxCount = maxCount; 39 40 this->count = 0; 40 this->particleType = type;41 41 this->particles = NULL; 42 this->setConserve(.8); 43 this->setLifeSpan(.1); 42 this->deadList = NULL; 43 this->setConserve(1); 44 this->setLifeSpan(1); 44 45 this->setInheritSpeed(0); 45 46 this->glID = NULL; 46 47 this->setRadius(1.0, 1.0, 0.0); 47 this->setType( PARTICLE_SPRITE, 1);48 this->setType(type, 1); 48 49 ParticleEngine::getInstance()->addSystem(this); 49 50 } … … 53 54 \brief standard deconstructor 54 55 */ 55 ParticleSystem::~ParticleSystem() 56 ParticleSystem::~ParticleSystem() 56 57 { 57 58 // delete what has to be deleted here 58 59 ParticleEngine::getInstance()->removeSystem(this); 60 61 // deleting all the living Particles 62 while (this->particles) 63 { 64 Particle* tmpDelPart = this->particles; 65 this->particles = this->particles->next; 66 delete tmpDelPart; 67 } 68 69 // deleting all the dead particles 70 while (this->deadList) 71 { 72 Particle* tmpDelPart = this->deadList; 73 this->deadList = this->deadList->next; 74 delete tmpDelPart; 75 } 76 77 if (this->material) 78 delete this->material; 59 79 } 60 80 … … 199 219 { 200 220 prevPart->next = tickPart->next; 201 delete tickPart; 221 tickPart->next = this->deadList; 222 this->deadList = tickPart; 202 223 tickPart = prevPart->next; 203 224 } … … 206 227 prevPart = NULL; 207 228 this->particles = tickPart->next; 208 delete tickPart; 229 tickPart->next = this->deadList; 230 this->deadList = tickPart; 209 231 tickPart = this->particles; 210 232 } … … 221 243 /** 222 244 \brief draws all the Particles of this System 223 */ 224 void ParticleSystem::draw(void) 225 { 245 \param the time passed in seconds (since the last draw) 246 */ 247 void ParticleSystem::draw(float dt) 248 { 249 glPushAttrib(GL_ENABLE_BIT); 226 250 // material->select(); 227 228 229 glMatrixMode(GL_MODELVIEW);230 // glDisable(GL_LIGHTING);231 material->select();232 233 251 Particle* drawPart = particles; 234 if (likely(drawPart != NULL)) 252 253 switch (this->particleType) 235 254 { 236 glBegin(GL_POINTS); 255 case PARTICLE_SPRITE: 256 glMatrixMode(GL_MODELVIEW); 257 // glDisable(GL_LIGHTING); 258 material->select(); 259 glDisable(GL_DEPTH_TEST); 237 260 while (likely(drawPart != NULL)) 238 261 { 239 // draw in DOT mode240 262 glPushMatrix(); 241 263 glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); … … 243 265 glCallList(*this->glID); 244 266 245 // 267 //glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 246 268 drawPart = drawPart->next; 247 269 glPopMatrix(); 248 270 } 271 // glEnd(); 272 273 // glEnable(GL_LIGHTING); 274 275 glEnable(GL_DEPTH_TEST); 276 break; 277 default: 278 279 case PARTICLE_SPARK: 280 glEnable(GL_LINE_SMOOTH); 281 glBegin(GL_LINES); 282 while (likely(drawPart != NULL)) 283 { 284 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 285 glVertex3f(drawPart->position.x - drawPart->velocity.x, 286 drawPart->position.y - drawPart->velocity.y, 287 drawPart->position.z - drawPart->velocity.z); 288 drawPart = drawPart->next; 289 } 249 290 glEnd(); 291 break; 292 293 case PARTICLE_DOT: 294 glBegin(GL_POINTS); 295 while (likely(drawPart != NULL)) 296 { 297 glLineWidth(drawPart->radius); 298 299 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 300 drawPart = drawPart->next; 301 } 302 glEnd(); 303 break; 250 304 } 305 glPopAttrib(); 251 306 } 252 307 … … 264 319 if (unlikely(particles == NULL)) 265 320 { 266 this->particles = new Particle; 321 if (likely(deadList != NULL)) 322 { 323 this->particles = this->deadList; 324 deadList = deadList->next; 325 } 326 else 327 { 328 PRINTF(5)("Generating new Particle\n"); 329 this->particles = new Particle; 330 } 267 331 this->particles->next = NULL; 268 332 } … … 270 334 else 271 335 { 272 Particle* tmpPart = new Particle; 336 Particle* tmpPart; 337 if (likely(deadList != NULL)) 338 { 339 tmpPart = this->deadList; 340 deadList = deadList->next; 341 } 342 else 343 { 344 PRINTF(5)("Generating new Particle\n"); 345 tmpPart = new Particle; 346 } 273 347 tmpPart->next = this->particles; 274 348 this->particles = tmpPart; 275 349 } 276 350 277 particles->timeToLive = this->lifeSpan + (float)(rand om()/RAND_MAX)* this->randomLifeSpan;351 particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 278 352 particles->position = position; 279 353 particles->velocity = velocity; 280 354 281 355 // particle->rotation = ; //! \todo rotation is once again something to be done. 282 particles->mass = this->initialMass + (rand om()/RAND_MAX -.5)* this->randomInitialMass;283 particles->radius = this->startRadius + (rand om()/RAND_MAX-.5)*this->randomStartRadius;284 285 particles->radiusIt = (this->endRadius + (rand om()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive;356 particles->mass = this->initialMass + (rand()/RAND_MAX -.5)* this->randomInitialMass; 357 particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius; 358 359 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->timeToLive; 286 360 287 361 ++this->count; 288 362 } 289 363 else 290 PRINTF( 4)("maximum count of particles reached not adding any more\n");364 PRINTF(5)("maximum count of particles reached not adding any more\n"); 291 365 } 292 366 … … 298 372 PRINT(0)(" ParticleSystem %s\n", this->name); 299 373 PRINT(0)(" ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount); 300 } 374 if (deadList) 375 { 376 PRINT(0)(" - ParticleDeadList is used: "); 377 int i = 1; 378 Particle* tmpPart = this->deadList; 379 while (tmpPart = tmpPart->next) ++i; 380 PRINT(0)("count: %d\n", i); 381 } 382 } -
orxonox/branches/movie_player/src/lib/graphics/particles/particle_system.h
r3966 r4217 10 10 #include "vector.h" 11 11 12 #define PARTICLE_DOT_MASK 0x00001 13 #define PARTICLE_SPRITE_MASK 0x00010 14 #define PARTICLE_MODEL_MASK 0x00100 15 #define PARTICLE_WORDL_ENTITY_MASK 0x01000 16 #define PARTICLE_MULTI_MASK 0x10000 12 #define PARTICLE_DOT_MASK 0x000001 13 #define PARTICLE_SPARK_MASK 0x000010 14 #define PARTICLE_SPRITE_MASK 0x000100 15 #define PARTICLE_MODEL_MASK 0x001000 16 #define PARTICLE_WORDL_ENTITY_MASK 0x010000 17 #define PARTICLE_MULTI_MASK 0x100000 17 18 18 19 //! An enumerator for the different types of particles. 19 20 typedef enum PARTICLE_TYPE {PARTICLE_DOT = PARTICLE_DOT_MASK, 21 PARTICLE_SPARK = PARTICLE_SPARK_MASK, 20 22 PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, 21 23 PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, … … 42 44 float radiusIt; //!< The difference of the Size per second. 43 45 46 PARTICLE_TYPE type; 47 44 48 Particle* next; //!< pointer to the next particle in the List. (NULL if no preceding one) 45 49 }; … … 50 54 51 55 public: 52 ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); 56 ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, 57 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); 53 58 virtual ~ParticleSystem(); 54 59 void setName(const char* name); … … 59 64 void setInheritSpeed(float value); 60 65 void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); 61 void setRadius(float startRadius, float endRadius, float randomStartRadius = 0.0, float randomEndRadius = 0.0); 66 void setRadius(float startRadius, float endRadius, 67 float randomStartRadius = 0.0, float randomEndRadius = 0.0); 62 68 void setConserve(float conserve); 63 69 void setMass(float mass, float randomMass); 64 70 65 71 void tick(float dt); 66 void draw( void);72 void draw(float dt); 67 73 68 74 void debug(void); … … 88 94 Material* material; //!< A Material for all the Particles. 89 95 Particle* particles; //!< A list of particles of this System. 96 Particle* deadList; //!< A list of dead Particles in the System. 90 97 91 98 GLuint* glID; //!< A List of different gl-List-ID's
Note: See TracChangeset
for help on using the changeset viewer.