Gels

Gel

Nice short title there. Moving swiftly on. Adding a dimension to a string gives you a cloth and adding another gives you a gel or jelly, (or jello for those of you who live in America). You can make a really impressive bouncing jelly cube which wobbles and stuff.

You make a cube in exactly the same way as cloths and strings, only with another dimension added, so I won't bother to go into too much detail here.
Of course you needn't have cubes. You can make any jelly shapes, and use them to calculate stresses on various shapes of objects. I doubt that's how they do it in real life though.

Again, you can make a very flexible gel by connecting each point to its 26 nearest neighbours or a stiffer one by connecting to its 124 neighbours. As you can see from the number of comparisons you have to do, it can be a very slow process to calculate a gel in real time. It should be possible to calculate a small cube, say 8 by 8 by 8, in assembler using fixed point maths. I am currently writing this and should have an example up sometime.

I shan't bother to give any pseudo code here. You should be an expert on particle spring systems by now. When (if?) I have finished writing my realtime bouncing jelly, I will post my code up here. It will be in PC assembler using fixed-point maths.

Constant Volume Property

Hmmm.... I been having these thoughts. Working on the gel recently I realised why it was that they always seem to behave like blocks of foam. It's cos that's exactly what they are. If you take a sponge and a jelly, and squeeze one in each hand, you will see that there is a significant difference between the two. The sponge will just squash, but the jelly will squirt out everywhere. This is because Gel, like water, has a constant volume property. If you push down on a sponge, it will just get smaller, but a gel will always maintain the same volume by squishing outwards where it is not being compressed.

So I been thinking how I might apply this to the gel to give it a realistic behaviour. I considered calculating the volume of all the little boxes it was made up from, but decided that was too slow and fiddly. I eventually discovered a simple approach, though it might not be amazingly accurate.

In a gel with constant volume, the average distance between a particle and its neighbours needs to remain constant. So, for every particle, calculate that average, and, if it is too small, push the neighbours away a little. If it is too large, then pull them in a little.

I haven't actually tried this myself, but I am fairly confident that it will work.

2 Dimensional Gel

Hmmm? isn't a 2D gel just a cloth. er yes, but what I mean is a 2D gel in a 2D world. I assume most people have played those tank games where you have a landscape littered with tanks, and you take it in turns to fire shots at eachother. Worms is a really great version of this, but with little worms instead of tanks.
If your shot misses a tank, it blows a hole in the land.Some games made the effort to have the land colapse if you shot out the ground underneath it.However the land would simply fall down in perfect columns.

I always thought it would be great if the land could sag and bend. This is where the gel comes in. You could have the land made up from a huge gel. It shouldn't be too slow to calculate since it's just in 2 dimensions. You could have a point every 16 pixels or so, and linearly texturemap polygons in between them. It would look totally awesome. A tank could drive out on a ledge only to find that it bends beneath it, tipping it into the water. Destroying the middle of a bridge would let the two halves colapse onto the ground. An explosion could shock the land, making the whole thing wobble, throwing tanks around.

I expect to see the next tank game that comes out have this feature.

Click on the image on the right to download an animation of a gel falling onto some rods (in .FLI format).

Some C++ source code for an arbitary shaped gelly. It's for Watcom C++, so it may have some trouble compiling with other compilers. Good luck.