Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of people/boenzlip/interesstingStuff


Ignore:
Timestamp:
May 26, 2005, 10:20:33 AM (19 years ago)
Author:
patrick
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • people/boenzlip/interesstingStuff

    v1 v1  
     1= Suff =
     2
     3[[TOC]]
     4
     5
     6== Explosions, Particle Rendering - from NeHe ==
     7source = http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30 [[br]]
     8Every time a collision takes place an explosion is triggered at the collision point. A nice way to model explosions is to alpha blend two polygons which are perpendicular to each other and have as the center the point of interest (here intersection point). The polygons are scaled and disappear over time. The disappearing is done by changing the alpha values of the vertices from 1 to 0, over time. Because a lot of alpha blended polygons can cause problems and overlap each other (as it is stated in the Red Book in the chapter about transparency and blending) because of the Z buffer, we borrow a technique used in particle rendering. To be correct we had to sort the polygons from back to front according to their eye point distance, but disabling the Depth buffer writes (not reads) also does the trick (this is also documented in the red book). Notice that we limit our number of explosions to maximum 20 per frame, if additional explosions occur and the buffer is full, the explosion is discarded. The source which updates and renders the explosions is:
     9{{{
     10
     11/ Render / Blend Explosions
     12glEnable(GL_BLEND);                                                     // Enable Blending
     13glDepthMask(GL_FALSE);                                                  // Disable Depth Buffer Writes
     14glBindTexture(GL_TEXTURE_2D, texture[1]);                               // Upload Texture
     15for(i=0; i<20; i++)                                                     // Update And Render Explosions
     16{
     17        if(ExplosionArray[i]._Alpha>=0)
     18        {
     19                glPushMatrix();
     20                ExplosionArray[i]._Alpha-=0.01f;                        // Update Alpha
     21                ExplosionArray[i]._Scale+=0.03f;                        // Update Scale
     22                // Assign Vertices Colour Yellow With Alpha
     23                // Colour Tracks Ambient And Diffuse
     24                glColor4f(1,1,0,ExplosionArray[i]._Alpha);              // Scale
     25                glScalef(ExplosionArray[i]._Scale,ExplosionArray[i]._Scale,ExplosionArray[i]._Scale);
     26                // Translate Into Position Taking Into Account The Offset Caused By The Scale
     27                glTranslatef((float)ExplosionArray[i]._Position.X()/ExplosionArray[i]._Scale,
     28                        (float)ExplosionArray[i]._Position.Y()/ExplosionArray[i]._Scale,
     29                        (float)ExplosionArray[i]._Position.Z()/ExplosionArray[i]._Scale);
     30                glCallList(dlist);                                      // Call Display List
     31                glPopMatrix();
     32        }
     33}
     34
     35}}}