Changeset 4192 in orxonox.OLD for orxonox/branches/physics/src/lib/graphics/particles/particle_system.cc
- Timestamp:
- May 16, 2005, 12:55:19 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/physics/src/lib/graphics/particles/particle_system.cc
r4190 r4192 53 53 this->setRadius(1.0, 1.0, 0.0); 54 54 this->setType(type, 1); 55 this->setColor(1.0,1.0,1.0,1.0, .5,.5,.5,.5, .0,.0,.0,.0); 55 56 ParticleEngine::getInstance()->addSystem(this); 56 57 } … … 198 199 } 199 200 201 202 /** 203 \brief Tells the ParticleSystem how it should iterate the color over time 204 \param .... 205 */ 206 void ParticleSystem::setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, 207 GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, 208 GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea) 209 { 210 this->startColor[0] = br; 211 this->startColor[1] = bg; 212 this->startColor[2] = bb; 213 this->startColor[3] = ba; 214 215 this->midColor[0] = mr; 216 this->midColor[1] = mg; 217 this->midColor[2] = mb; 218 this->midColor[3] = ma; 219 220 this->endColor[0] = er; 221 this->endColor[1] = eg; 222 this->endColor[2] = eb; 223 this->endColor[3] = ea; 224 } 225 200 226 /** 201 227 \brief ticks the system. … … 217 243 tickPart->extForce = Vector(0,0,0); 218 244 245 // applying Color 246 //! \todo better algorithm to do this \todo also implement the midColor 247 tickPart->color[0] = this->startColor[0] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[0]; 248 tickPart->color[1] = this->startColor[1] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[1]; 249 tickPart->color[2] = this->startColor[2] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[2]; 250 tickPart->color[3] = this->startColor[3] *(1-tickPart->lifeCycle) + tickPart->lifeCycle * this->endColor[3]; 251 219 252 // many more to come 220 253 … … 222 255 tickPart->velocity = tickPart->velocity * this->conserve; 223 256 // find out if we have to delete tickPart 224 if ((tickPart-> timeToLive -= dt) <=0)257 if ((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0) 225 258 { 226 259 // remove the particle from the list … … 267 300 \brief draws all the Particles of this System 268 301 \param the time passed in seconds (since the last draw) 302 303 The Cases in this Function all do the same: 304 Drawing all the particles with the appropriate Type. 305 This is just the fastest Way to do this, but will most likely be changed in the future. 269 306 */ 270 307 void ParticleSystem::draw(float dt) 271 308 { 272 309 glPushAttrib(GL_ENABLE_BIT); 273 // material->select(); 310 glDisable(GL_LIGHTING); 311 274 312 Particle* drawPart = particles; 275 313 276 314 switch (this->particleType) 277 315 { 316 default: 278 317 case PARTICLE_SPRITE: 279 GLdouble projMat[16];280 GLfloat drawPartPos[4];281 glGetDoublev(GL_PROJECTION_MATRIX, projMat);282 283 318 glMatrixMode(GL_MODELVIEW); 284 319 glDisable(GL_DEPTH_TEST); 285 glDisable(GL_LIGHTING); 286 material->select(); 320 321 material->select(); 322 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 287 323 288 324 289 325 while (likely(drawPart != NULL)) 290 326 { 327 glColor4fv(drawPart->color); 291 328 //! \todo implement a faster code for the look-at Camera algorithm. 292 329 293 Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera(); 330 Camera* camera = WorldInterface::getInstance()->getCurrentWorld()->getLocalCamera(); //!< \todo MUST be different 294 331 Vector cameraPos = camera->getAbsCoor(); 295 332 Vector cameraTargetPos = camera->getTarget()->getAbsCoor(); … … 326 363 drawPart = drawPart->next; 327 364 } 328 glEnable(GL_LIGHTING);329 glEnable(GL_DEPTH_TEST);330 365 331 366 332 367 break; 333 default:334 368 335 369 case PARTICLE_SPARK: … … 338 372 while (likely(drawPart != NULL)) 339 373 { 374 glColor4fv(drawPart->color); 340 375 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 341 376 glVertex3f(drawPart->position.x - drawPart->velocity.x, … … 351 386 while (likely(drawPart != NULL)) 352 387 { 388 glColor4fv(drawPart->color); 389 353 390 glLineWidth(drawPart->radius); 354 391 … … 405 442 } 406 443 407 particles->timeToLive = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 444 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 445 particles->lifeCycle = 0.0; 408 446 particles->position = position; 409 447 particles->velocity = velocity; … … 413 451 particles->radius = this->startRadius + (rand()/RAND_MAX-.5)*this->randomStartRadius; 414 452 415 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles-> timeToLive;453 particles->radiusIt = (this->endRadius + (rand()/RAND_MAX-.5)*this->randomEndRadius - particles->radius) / particles->lifeTime; 416 454 417 455 ++this->count;
Note: See TracChangeset
for help on using the changeset viewer.