2

I have to make a program on particle systems in C# and I'm using Visual studio 2010. I must not use any libraries like OpenGl, ... I can use just Graphisc library from C#. I tried to read some tutorials and lectures but I still don't know how to implement it.

Can anybody help me understand how I should decompose my problem? Or direct me maybe on some useful tutorials? It´s new for me and I'm kinda stuck.

My task:

Program a simple generator luminous particles in the shape of a geyser from a point generator, view the particles as different colored dots moving across a single track on a black background in parallel projection.

Mike
  • 47,263
  • 29
  • 113
  • 177
user1097772
  • 3,499
  • 15
  • 59
  • 95

2 Answers2

1

Look up BackgroundWorker and RenderTargetBitmap it is probably best to do this in WPF

Psuedo code

backgroundWorker()
{
    while(isRunning)
    {
        update()
        draw()
    }
 }

 update()
 {
     for each all particles
     {
         update gravity and/or relativity to other particles
     }
 }

 draw()
 {
     clear bitmap

     for each all particles
     {
         draw your particle
     }

     set it to your container
 }

This is based upon a game loop

  • 1
    +1. Except there is no reason to use any kind of background worker for this task (or even for most games - update everything 30-60 times a second on main thread would be enough) – Alexei Levenkov May 21 '12 at 16:47
1

Though not a complete answer, here is how I would break down the problem if it were my task:

  1. Find a way to render a single particle (perhaps as a dot or a ball). I recommend starting with WPF.
  2. Find a way to "move" that particle programmatically (i.e. by rendering it in different places over time).
  3. Create a Particle class that can store its current state (position, velocity, acceleration) and can be moved (i.e. SetPosition, SetVelocity...)
  4. Create a World class the represents a 3-dimensional space and keeps track of all the particles in it. The World will know the laws of physics and will be responsible for moving particles around given their current state.
  5. Create a bunch of Particles that have the same initial starting position but random initial acceleration vectors. Add those Particles to the World. The World will automatically update their positions from then on.
  6. Apply what you learned in steps 1 and 2 to have your World graphically represent all of its Particles.

Edit: Step 7 would be to "run step 6 in a loop". The loop code provided by noHDD is a very good basic framework: continuously update the state of the world and then draw the results.

ean5533
  • 8,884
  • 3
  • 40
  • 64
  • 3
    I have done something like that with WPF (just for the fun of it): http://codegolf.stackexchange.com/a/2594/15 – Creating an ellipse for every particle is a bit wasteful, though ;) – Joey May 21 '12 at 16:29