Changeset 4192 in orxonox.OLD for orxonox/branches/physics
- Timestamp:
- May 16, 2005, 12:55:19 AM (20 years ago)
- Location:
- orxonox/branches/physics/src
- Files:
-
- 3 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; -
orxonox/branches/physics/src/lib/graphics/particles/particle_system.h
r4186 r4192 36 36 typedef struct Particle 37 37 { 38 float timeToLive; //!< The time this particle lives from NOW on. 38 float lifeTime; //!< The time this particle has to live. 39 float lifeCycle; //!< The fraction of time passed. (in percentage of its lifeTime) 40 39 41 Vector position; //!< The current position of this particle. 40 42 Vector velocity; //!< The current velocity of this particle. … … 44 46 float radius; //!< The current size of this particle. 45 47 float radiusIt; //!< The difference of the Size per second. 48 49 GLfloat color [4]; //!< A Color for the particles. 46 50 47 51 PARTICLE_TYPE type; … … 70 74 void setMass(float mass, float randomMass); 71 75 76 void setColor(GLfloat br, GLfloat bg, GLfloat bb, GLfloat ba, 77 GLfloat mr, GLfloat mg, GLfloat mb, GLfloat ma, 78 GLfloat er, GLfloat eg, GLfloat eb, GLfloat ea); 79 72 80 void applyField(float dt, Field* field); 73 81 … … 82 90 float conserve; //!< How much energy gets conserved to the next Tick. 83 91 float lifeSpan; //!< Initial lifetime of a Particle. 84 float randomLifeSpan; 85 float startRadius; 86 float endRadius; 87 float randomStartRadius; 88 float randomEndRadius; 89 float initialMass; 90 float randomInitialMass; 91 float inheritSpeed; 92 float randomLifeSpan; //!< A random value for the Lifespan (around the initial lifetime) 93 float startRadius; //!< The beginning Radius of the Particle 94 float endRadius; //!< The end Radius of the Particle 95 float randomStartRadius; //!< The Random start Radius (begin + rand*randomValue) 96 float randomEndRadius; //!< Random end value 97 float initialMass; //!< The initial Mass of the Particle 98 float randomInitialMass; //!< The random initial Mass of the Particle 99 float inheritSpeed; //!< How much speed the particle inherits from the Emitters speed \todo move this to the emitter 100 101 GLfloat startColor[4]; //!< Color of the Particle at the beginning 102 GLfloat midColor[4]; //!< Color of the Particle at the middle of its lifeSpan 103 GLfloat endColor[4]; //!< Color of the Particle at the end of its lifeSpan 92 104 93 105 // particles -
orxonox/branches/physics/src/story_entities/world.cc
r4190 r4192 492 492 493 493 494 // Creating a Test Particle System 494 495 ParticleSystem* system = new ParticleSystem(100000, PARTICLE_SPRITE); 495 system->setLifeSpan(3); 496 system->setConserve(.9); 497 system->setRadius(2, 0, 2, 0); 498 496 system->setLifeSpan(1); 497 system->setConserve(.8); 498 system->setRadius(4, 0, 1, 0); 499 system->setColor(1,0,0,1, 1,1,0,1, 0,0,0,0); 500 501 // Creating a Test Particle Emitter 499 502 ParticleEmitter* emitter = new ParticleEmitter(Vector(-1, 0, 0), M_PI_4, 400, .5); 500 503 emitter->setParent(this->localPlayer); 501 504 emitter->setRelCoor(Vector(0,-3,0)); 505 506 // Add the Flow from the Emitter into the System 507 particleEngine->addConnection(emitter, system); 508 509 510 // Creating Some Fields 502 511 Field* twirl = new Twirl(); 503 512 twirl->setMagnitude(.1); 504 513 Field* gravity = new PointGravity(); 505 514 gravity->setMagnitude(.5); 506 new PhysicsConnection(system, twirl); 507 // new PhysicsConnection(system, gravity); 508 twirl->setParent(this->localCamera->getTarget()); 509 gravity->setParent(this->localCamera->getTarget()); 510 particleEngine->addConnection(emitter, system); 515 twirl->setParent(this->localCamera->getTarget()); 516 gravity->setParent(this->localCamera->getTarget()); 517 518 // new PhysicsConnection(system, twirl); 519 // new PhysicsConnection(system, gravity); 520 511 521 } 512 522
Note: See TracChangeset
for help on using the changeset viewer.