Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XNA - Simulated snow

This is more of a question as to request some advice on which pattern/approach I should use. I have done some investigations into this problem - with poor results.

Essentially I have an idea for a game, in which the key gameplay mechanic is based around falling snow - or, in the case of this idea game - falling particles.

The snow/particles need to fall down the screen - but accumulate in piles. The issue is, I need to snow to 'trickle down' the sides of the piles, when they are certain angle, and continue to accumulate. It is possible that holes open underneath piles of snow, and the snow has to fall out - think like sand falling through an hourglass.

I have tried this is Box2d - it is clear that Box2d isn't the right choice for 10,000's of tiny particles - that last for long periods of time. Box 2D chugged to death pretty quickly.

I tried drawing 1px bitmaps onto the screen, but processing 10,000's of collisions every update proved to be poorly performing too.

Any ideas would be appreciated.

Cheers

like image 502
Dave Bish Avatar asked Feb 25 '13 15:02

Dave Bish


3 Answers

Well, just like you discovered, no existing library will help you unless it's geared very specifically toward your scenario. With XNA unfortunately there aren't many things to choose from, and it looks like none of the existing particle system libraries support particle physics.

So you'll need to do a lot of work yourself. First and foremost you need to think of all the optimizations you can possibly do. Like a comment said, you shouldn't run checks between all particles every frame. You should use a point-based collision check instead of the fancier stuff usually used by physics engines. You should make sure the particles are always the same size, in this case (relative to a reference coordinate system that is, that doesn't mean you couldn't have zoom). And of course you need to skip as many collision checks as possible - the particles you know are at rest should never be checked, like the ones that have adjacent particles on all sides - which leads me to think of grids. Perhaps you could represent the entire 'world' as a grid, and simplify the logic from this point of view - pretty much the same as Minecraft does, wouldn't you agree?

Anyway, I realize I'm rambling a bit but it's such an open subject... :)

like image 185
Alex Paven Avatar answered Nov 06 '22 04:11

Alex Paven


Take a lot at this Cool Effects (for XNA & MonoGame) http://www.int6.org/development/cool-effects-for-xna-monogame/

There's no snow effect, but there are some interest effect you can use o modify.

like image 21
Vackup Avatar answered Nov 06 '22 03:11

Vackup


Is it possibly to monitor which particles are actually being processed by the physics engine? If so, is there a way whereby you can stop processing their physics, or severely limit what is processed, if their velocity is less than 0.01 or something of the like?

If you only process the particles that need processing, then you can have as many as you like, assuming that they are not all moving at once!

If this is still a problem, it sounds like a fluid dynamics solution may be more fitting, as fluid dynamics is basically a whole lot of small, moving particles.

Here is some interesting information on 2D fluid dynamics:

http://www.ibiblio.org/e-notes/webgl/gpu/fluid.htm

Your physics engine may already contain what you need.

like image 1
rhughes Avatar answered Nov 06 '22 04:11

rhughes