# Fluid Grid (aka Geometry Wars background)

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I want to implement something like the fluid, elastic grid you can see in Geometry Wars (
). I really need a math primer on that though. I've heard this is implemented using spring constraints, however I didn't find any good articles on that on the internet. Thanks

##### Share on other sites
I know this rule but I don't know how to represent a grid of points that can move a bit like a fluid would. What are the inputs? How is the position of a certain point calculated? It certainly takes into account the position of its neighbors as well as some kind of constraints that will move it back to its initial position in a fluid way.

##### Share on other sites
Hi,
You have to model every point as a newtonian mass (F=ma) and each spring as a linear(f=kx) spring.
Each point just has position, velocity and mass.
Each spring has a free length and a spring constant and two endpoints, each of which can either be a point mass, or a fixed point (inheritance).
Every time step:
For each spring:
get the distance between the two endpoints, subtract the free length, multiply by the
spring constant, and apply the resulting force to both endpoint objects be sure to take
angle into account, and reverse the direction for one of them. Also you will want to do the
same with some velocity damping or your grid will oscilate and probably blow up.
For each point mass:
just integrate using your favourite method (euler or verlet works well for this, RK4
requires multiple passes each time step).

You'll have to construct a grid with at least 2 fixed points in it (preferably at the edges) to start with, and then apply outside disturbances to it to make it interesting.

And there you go, this thing will have all sorts of fun behaviour, like waves and such.

Hope this helps.

##### Share on other sites
Check out:
http://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations
And:
http://en.wikipedia.org/wiki/Computational_fluid_dynamics

Magical time-travelling quote
Quote:
 Original post by SneftelIt's unlikely that that background is using a mass-spring system. The grid lines alias as they distort. More likely, the weapon blasts send out invisible sprites which are used to deform the static texture.
Could be both! I remember in an interview they mention that the background actually takes up the majority of their processing time ;)

##### Share on other sites
It's unlikely that that background is using a mass-spring system. The grid lines alias as they distort. More likely, the weapon blasts send out invisible sprites which are used to deform the static texture.

##### Share on other sites
Quote:
 Original post by SneftelIt's unlikely that that background is using a mass-spring system. The grid lines alias as they distort. More likely, the weapon blasts send out invisible sprites which are used to deform the static texture.

Really? I recall an interview where the GW developer commented that the background was a mass+spring system tweaked to be "just on the edge of stability" or something like that..

##### Share on other sites
I made a little demo trying that effct myself.
the gridcode:

grid.cpp
http://sudi.pastebin.com/f53cb3d0d

grid.h
http://sudi.pastebin.com/f4265ff7b

the game:

i used the sprin system.

##### Share on other sites
Quote:
 Original post by SudiI made a little demo trying that effct myself.

Neat, but it seems to go unstable in some situations :-)

##### Share on other sites
Quote:
 Original post by SneftelIt's unlikely that that background is using a mass-spring system. The grid lines alias as they distort. More likely, the weapon blasts send out invisible sprites which are used to deform the static texture.

That's what I thought too, until I saw how the black-hole "enemies" affected the grid. Then it definitely looked more like a spring system than some kind of shader effect. At 1:34 in the video you can clearly see how the black hole on the left edge is distorting the grid in an extremely spring-like manner.

It looks like an extremely dense spring system (like, one node for every intersection on the highest resolution grid) with low spring constants and a lot of dampening.

Also it looks like they might have disabled the spring force when x < 0.

##### Share on other sites
I found the interview I remembered:

"
Q: One of the most striking new graphical features in the game is the "gravity grid" play area. How did you make this look so cool; does every object in the game really have its own gravity?

A: The grid itself is made up of 60,000 points, each one exerting a small amount of force on its neighbour. The simulation itself sits on the edge of stability which is what causes it to swing about so much when one of the game objects gives it a small push!

Only a few types of object affect the grid. As the grid system is rather expensive to calculate, it actually runs on the second core along with the audio system, (the first core being dedicated to gameplay and particles, the third is used to render the audio).
"

from http://www.bizarrecreations.com/games/geometry_wars_retro_evolved/interview.php

60k sounds like a lot (and it's way more than I would have guessed), but that's only 256x256, which is pretty low-rez.

##### Share on other sites
Quote:
Original post by h4tt3n
Quote:
 Original post by SudiI made a little demo trying that effct myself.

Neat, but it seems to go unstable in some situations :-)

well that only happens when your cpu is not fast enough bc then forces pile up and kinda screw everything.

##### Share on other sites
Quote:
 Original post by apefishHi,You have to model every point as a newtonian mass (F=ma) and each spring as a linear(f=kx) spring. Each point just has position, velocity and mass. Each spring has a free length and a spring constant and two endpoints, each of which can either be a point mass, or a fixed point (inheritance).Every time step: For each spring: get the distance between the two endpoints, subtract the free length, multiply by the spring constant, and apply the resulting force to both endpoint objects be sure to take angle into account, and reverse the direction for one of them. Also you will want to do the same with some velocity damping or your grid will oscilate and probably blow up. For each point mass: just integrate using your favourite method (euler or verlet works well for this, RK4 requires multiple passes each time step).You'll have to construct a grid with at least 2 fixed points in it (preferably at the edges) to start with, and then apply outside disturbances to it to make it interesting.And there you go, this thing will have all sorts of fun behaviour, like waves and such.Hope this helps.
Yes this helps a lot. Thanks.

##### Share on other sites
Quote:
Original post by Sudi
Quote:
Original post by h4tt3n
Quote:
 Original post by SudiI made a little demo trying that effct myself.

Neat, but it seems to go unstable in some situations :-)

well that only happens when your cpu is not fast enough bc then forces pile up and kinda screw everything.

My laptop runs spring simulations an order of magnitude larger than that without breaking sweat - and without screwing up :-) Are you sure there's not a bug hiding in there somewhere? Just asking out of curiosity and in the hopes of making a nice piece of code even nicer.

##### Share on other sites
well its not the spring system that is so expensive but drawing it is....its not really optimised. and maybe also the postprocess shaders do their part maybe try the bat file that says no shader.

##### Share on other sites
After reading through this interesting discussion I have the following question:

Are the outer most nodes/points attached to a non moving frame or does gravity have no effect on each node in the grid?

Thank you.

##### Share on other sites
The way I usually anchor the edges or ends of a "net" or "band" of springs is I just make a special type of node that ignores any force applied to it.

Alternatively you could just treat them like normal nodes, and then have some external code that zeroes out the edge node velocities before you do velocity/position integration.

##### Share on other sites
Thanks Nypyren.

So if I understand you correctly, gravity plays no part with any of the nodes and the outmost nodes should have no rigid bodies attached to them (treated as static actors).

##### Share on other sites
Quote:
 Original post by Spa8nkyThanks Nypyren.So if I understand you correctly, gravity plays no part with any of the nodes and the outmost nodes should have no rigid bodies attached to them (treated as static actors).

Gravity, as far as the Geometry Wars black holes go - that does affect nodes (but only the nodes that are movable). There's no 'world' gravity in Geometry wars. If you wanted to make a side-scroller with rope bridges, and you used springs to hold the rope together, THEN you could apply gravity to all nodes, which would result in the rope automatically settling into a parabolic curve that everyone's familiar with.

The only thing the anchor nodes are used for is an endpoint for the spring(s) attached to the movable nodes. If you allowed the anchor nodes to be affected by other forces, the entire grid could fly away like a tarp in a windstorm :)

• 43
• 11
• 17
• 11
• 13