# Fluid Grid (aka Geometry Wars background)

This topic is 3330 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 24
• 15
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634098
• Total Posts
3015521
×