|
|
 |
 |
|
Join the Discussion
|
"Post your questions, concerns, views and comments to this article..."
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
Article submitted by: Curtis W. Socha
What is a particle system?
Prerequisites
.Delphi 4 or newer.
.Understanding how to work with the canvas
.Understanding of TList
.DirectX 4.0 or later if you wish to view the DirectDraw example.
To run the examples
.Download ParticleUnit.pas from this document.
.When you download the examples later on, be sure to include this unit in your search path.
|
This tutorial is going to discuss a library of routines I have put together that will help you create your own particle systems. The term system is defined to mean, "A group of interacting, interrelated, or interdependent elements forming a complex whole". Since we are obviously dealing with particles, and we have a library of methods (elements) that work together to manipulate these particles, we thus have a particle system.
OK, that makes sense, but what is a particle?
When I refer to the term particle, I am referring to an XY coordinates in space that has unique properties. Each particle is treated as an individual entity with its own characteristics. These days, we are all familiar with OOP so you should think of a particle as an object. It will have speed, mass, direction, and an XY coordinate position in two-dimensional space. This small group of characteristics can produce some wild special effects. Keep in mind that you do not have to necessarily put a single pixel on the screen to represent a particle, as I will in these examples. You can use that XY coordinate to display any image at that location. Let us refer to Example 1.0 now to see an illustration of a simple particle traveling through 2D space. Another name for this, according to mathematics, is a vector.
Hmmm. So what could a particle system be used for?
Well, for starters, they make for great trajectory games. You can use the particle to represent a cannonball being shot out of a cannon, rotating star fields, explosions, molecular effects, sparks, the list goes on. That said, I would like to mention that most of all, they are fun as all heck to play with. I have yet to run out of ideas using this library.
You mentioned gravitation. How does this impact the particle system?
As I mentioned, particles can have mass. Since mass in the real universe naturally gravitates to each other, I thought it would be really cool to make my particles do this as well. To make things even more interesting, I created gravity wells. They are essentially black holes that you can place anywhere in your 2D universe. Particles will attract not only each other, but they will be attracted to the gravity well (or repelled!). If you wish, you can alter the gravity well so that it repulses particles instead of attracting them.
Well then, lets get started. Teach me!
Great. Let us get on with it. The first few things I must explain is how I have the library organized. The library has a TParticleClass that contains lists of all active particles and gravity wells. This class also contains the methods you will use to manipulate your particle universe. The next thing to mention is the TParticle record. This record contains information about a specific particle. Things like mass, force, angle, whether it has gravitation or not, and its coordinates. Last but not least, we have the TGravityWell record. This record contains information about the gravity well, things such as location, size, and whether it should act as land gravity (I.E. the land under your feet is considered land gravity whereas the sun is considered point gravity). In a nutshell, you basically have a TParticleClass that contains a TList of TParticle and TGravityWell.
I will now provide the source code for the particle system library and several examples on how to use it. Click to download ParticleUnit.pas.
So the library is a single unit. How do I use this thing?
Good question. To help you along the windy path, we are going to review an extremely simple application to demonstrate just how easy it is to create particle systems using this library. All you need to do to add the library is add it to your uses clause.
Next page > Sample projects > Page 1, 2
|