PDA

View Full Version : Particle system?

CyBBe
04-29-2000, 08:24 AM
How do I do a particle system, I'm using GLUT and I've found one example but it ain't GLUT and I can't get it to work.

Anyone?

Thanx...

dmy
04-29-2000, 12:13 PM
you can't get it compiled, or what?
if it crashes, try to get another example on the net. probably you downloaded a not-so-much-tested application.
nehe has a particle demo.

or else you can write a particle system from scratch, and this would be another story...

what do you need?

Dolo/\/\ightY

Satapher
05-01-2000, 07:31 AM
Here's how I would go about writing a particle system (don't expect much I'm a beginner too and just wrote my first PS two weeks ago) I figure a particle system can have any number of constant variables (properties) as long as one is randomly generated.

First you need a structure that holds all of the individual particle's properties. A bit like this for a VERY primative system :

#define MAX_PARTICLES 1000
int loop; // For loops!

struct _particle
{
GLfloat x, y, z; // Position
GLfloat xv, yv, zv; // Velocity (Speed)
GLfloat life; // How long it stays
} particle[MAX_PARTICLES];

Then within a function that is only called once (such as an GL init function) roll thru your particles and assign them some variables with a for loop :

for(loop=0; loop<MAX_PARTICLES; loop++)
{
define y value
give random yv value
give x random value
give life random value
}

then in your main loop put something like this

for(loop=0; loop< MAX_PARTICLES; loop++)
{
subtract life from alpha value

draw particle

}

i had to do this in a hurry at the end =(

but you can contact me if you'd like and ill try my best to help out

satapher@quake3mods.net

or ICQ : 5181454

-Satapher

Rob The Bloke
05-13-2000, 03:17 AM
what's been described is an example of a static particle system. ie, there can only be a fixed number of particles. you can store particles within a linked list or other dynamic data stucture. This allows there to be as many particles as needed during run time without wasting any memory. Mail me if you wish to get some source code I prepared explaining how to go about setting up a system of this nature.

[This message has been edited by Rob The Bloke (edited 05-16-2000).]

skw|d
05-13-2000, 11:44 AM
There is a big cost in using dynamic link lists for a large system of particles. Malloc() takes some time. I think the best way is to recycle a static array.

Rob The Bloke
05-14-2000, 01:00 PM
Depends on your needs though, a trade off has to be made depending on whether its better to keep a static array in the memory, or keep the system dynamic.

If the particle system is being used for a small amount of time in the general runtime, or if the number of particles varies greatly, then I'd suggest the use of dynamic systems.

If however you'regoing to use a system that is constantly active, and if its size remains within fairly close limits, then a static data structure.

At the end of the day, there are two methods and its up to you to use whats best for your needs.

Overmind
05-15-2000, 10:08 AM
I tried write particle systems, too, and they worked well.

But how do you make particle systems look really good? The fountain effect like in NeHe's demo looks rather good with my program too, but how do you make explosions, fire, ...???

Rob The Bloke
05-16-2000, 02:32 PM
It comes down to how well you observe what you are trying to do.

Particle systems are affected purely by how you affect the acceleration and spread of the particles, and how much affects them.

On a basic level there are a few common things that you set your system up to be affected by, namely

* gravity (accelerate each particle downwards)
* tubulence (random movements within your particles)

you can keep adding in these for as long as you want, and as many as you want.for example

wind, attractions or repulsions between particles, magnetism, convection etc, etc....

Revisiting your old physics textbooks is a fairly good bet.

If you start getting into them seriously, try writing your own header file for particle systems that contain all the main equations for manipulating your particles(eg gravity etc). That way you can start writing something like...

apply_convection(currentParticle);
apply_gravity(currentParticle);
draw_particle;

This makes it a lot easier to create realistic ones, and much easier to edit whats going on.

In terms of creating high level particle systems, (admittedly most of the really good ones I've written have been rendered out in something like Maya or Renderman) you'll need to start adding textures, transparencies and lighting to your particles.

One of the best things you can do is to use a number of particle systems combined to give one effect. If you were creating fire for example, I would use on system for the flames, another for smoke particles, one for sparks and so on. How many you use depends on how many you can identify in what you are trying to create. You can also make particles to be emmiters for other particle systems.

eg, a school of fish swimming is represented by one particle system, and each fish is an emmiter for another system that gives off bubbles.

To go a stage further still, you can use animated particles to create things such as flocking birds, battle scenes (star wars phantom menace, the final battle scene).

The downside to this is that the more you add, the slower your frame rates will be. They are cool to play around with though.

[This message has been edited by Rob The Bloke (edited 05-16-2000).]

Shayde
05-16-2000, 10:10 PM
This page has a lot of good information on particle systems, including fire, cloth, string, etc.:

http://freespace.virgin.net/hugo.elias/models/m_main.htm

Ciao...
SHAYDE