The Fountain Simulation

Here I'll explain

• Some basic physical things (simulation of a water drop)
• How to get antialiased points
• How to use blending

Some basic physics...

The movement of a drop contains two factors: The direction, how the drop gets out of the fountain and the gravity. The position of a drop is pretty easy to compute if you know, how much time has passed since the drop has leaved the fountain. You have to multiplicate the vector of the constant moving (how the drop leaves the fountain) with the time and then subtract the squared time multiplicated with an acceleration factor. This acceleration factor contains the weight of a drop and the power of gravity. This is all. You now have to know the direction, how the drop comes out of the fountain, but this is just a bit calculating with sine and cosine. You can look at my code.

How can I render antialiased points?

When I wrote the example, I realized, that the foutain and its surrounding was drawn bigger or smaller, when I resized the window, but the drops' size remained the same. This didn't look too good, so I thought I could place a glPointSize() in my resize-function. But this command is only sensible, when you use antialiasing. This is only possible, when blending is enabled. Then the pixels next to the point's center do not get the point's color, but are blended with the color in the color buffer.

How can I use blending?

Blending means that a pixel on the screen isn't replaced by another one, but they are "mixed". Therefore you can use the alpha value of colors, it indicates how much of the color of the consisting pixel is used for the new color - for antialiasing of points, OpenGL computes this alpha value. After calling glEnable(GL_BLEND); you have to tell OpenGL how to use the alpha values. It isn't specified, that a higher alpha-value means more transparency or something like that. You can use them as you want. To tell OpenGL _what_ you want, you must use glBlendFunc(). It takes two parameters, one for the source factor and the second for the destination factor. I used GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA as parameters. This is quite an often used combination and affects, that the higher the alpha value, the less transparency of the incoming fragment, i.e. the source.

It is quite easy, look here.

Back

**************************************************************************

Any comments? Conact me!

philipp.crocoll@web.de

www.codecolony.de