Hi,
Storing the particles is easy, the questions are:
1) how many particles: 10 to the what?
relevant question...
in my case, particles are generally in the 10^3 range (my 3D engine
currently has a hard-coded limit of 10k particles, but I am not sure how
many is "typical").
I am aware that probably around 1000-5000 particles are used for most
particle effects (such as explosions), where one will have maybe 2500
particles for the "fire and sparks", another 1000 or so for smoke
particles, ...
IIRC, flame particles are approx 3 inches, and smoke particles 5 inches.
IIRC, most fire sources generally emit 250 particles per second, with
particles having an approx 5 second lifespan (with a variance of +-3s),
so around 1250 for a typical fire-source (such as a torch).
there may be a number of such torches in a scene (however, a lot of
times many may start sputtering, indicating that likely the particle
limit is being reached).
2) particle-particle interactions are O(N^2) so ...
in a naive case, yes.
with a BSP or similar it is around O(n log2 n).
however, when n=10k, this may still put a dent in the framerate.
it is also like when writing rigid body physics code:
the vast majority of the time is not often going into actual "physics
stuff", so much as it is trying to cull away everything that is not
moving and can't possibly collide.
it is sad in a way:
3D stuff is a good way to show just how little CPU power and RAM one
really has sometimes.
granted, there is a little more fancy-looking stuff one can do when they
don't need to try keep things at 40-60 fps, or when one can do things
with the otherwise absurdly small scenes typical in a tech demo (for
example, being able to simulate a small box of water doesn't really mean
it will scale to a lake).
you might want to have a look at the Multipole O(n log n) and Fast Multipole
O(n) methods where you reduce the interaction computation by operating
either at: Box-Particle or Box-Box interactions rather than always
Particle-Particle.
I implemented this in C++ as a homework couple of weeks ago for simulating
fluid dynamics. Basically you create a Quad Tree where every node contains
all Particles within its boundaries, then it will have 4 children Nodes that
contain the subset of Particles in those children Nodes and so on. You split
recursively until every leaf Node contains at most M Particles. Then to do
the simulation you traverse the Tree in pre- or post order and find out
whether you can optimize computation using Box-Box, Box-Particle, or
Particle-Particle interactions. You have to read the algorithm in detail.
I use a BSP variant personally.
oct-tree would also make sense, but I have seen little to suggest that
an oct-tree is either particularly faster or simpler than a BSP.
IMHO, a quad-tree seems like a bad idea in 3D for managing particles (it
makes sense to separate them on all 3 axes if possible).
Here you find the details and a sample implementation in C++ (HW solution
1):
http://cse-lab.ethz.ch/teaching/classes/mmc2011.html
Regarding the insert/deletes it is log_4 to insert/delete, you do a contains
check top-bottom starting from the root Node ... that's pretty fast I would
say.
yeah, although IME, inserting/deleting is not so much the main time
eater, at least vs possible interactions between particles and/or
rendering them.
if I were doing a fluid, I would likely consider 16 or 32 inch water
particles. I don't think much smaller would be ideal for the framerate
(assuming non-trivial amounts of water).
probably the particles would try to maintain an equilibrium distance,
becoming attractive or repulsive depending on their variation from said
ideal distance.
also, probably they would need the ability to interact with scene
geometry, ...
but, it could be cool.
I guess the main issue is how many such particles one can reasonably
have in a scene while keeping a good frame-rate (I can't entirely
predict, not having tried doing this).