= Suff = [[TOC]] == Explosions, Particle Rendering - from NeHe == source = http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=30 [[br]] Every 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: {{{ / Render / Blend Explosions glEnable(GL_BLEND); // Enable Blending glDepthMask(GL_FALSE); // Disable Depth Buffer Writes glBindTexture(GL_TEXTURE_2D, texture[1]); // Upload Texture for(i=0; i<20; i++) // Update And Render Explosions { if(ExplosionArray[i]._Alpha>=0) { glPushMatrix(); ExplosionArray[i]._Alpha-=0.01f; // Update Alpha ExplosionArray[i]._Scale+=0.03f; // Update Scale // Assign Vertices Colour Yellow With Alpha // Colour Tracks Ambient And Diffuse glColor4f(1,1,0,ExplosionArray[i]._Alpha); // Scale glScalef(ExplosionArray[i]._Scale,ExplosionArray[i]._Scale,ExplosionArray[i]._Scale); // Translate Into Position Taking Into Account The Offset Caused By The Scale glTranslatef((float)ExplosionArray[i]._Position.X()/ExplosionArray[i]._Scale, (float)ExplosionArray[i]._Position.Y()/ExplosionArray[i]._Scale, (float)ExplosionArray[i]._Position.Z()/ExplosionArray[i]._Scale); glCallList(dlist); // Call Display List glPopMatrix(); } } }}} = Collision Detection Systems/ Algorithms = Links: http://www.cs.unc.edu/~dm/collision.html = Libraries = * [http://www.ams.sunysb.edu/~jklosow/quickcd/QCD_kdops.html Discrete Orientation Polytopes (k-DOPs)] * [http://www.targ-it.com/Computers/Programming/Graphics/Algorithms_and_Data_Structures/Collision_Detection/Software much more] * [http://www.gamespp.com/algorithms/collisiondetection/ some simple stuff] * [http://www.gamespp.com/graphicsprogramming/BSPTreeFaq.html BSP tree FAQ] * [http://www.ams.sunysb.edu/~jklosow/quickcd/QCD_resources.html more ressources, short overview]