Fluid Grid (aka Geometry Wars background)

Started by
17 comments, last by Nypyren 14 years, 4 months ago
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
Advertisement
F = -kx
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.

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.
Check out:
http://en.wikipedia.org/wiki/Navier%E2%80%93Stokes_equations
And:
http://en.wikipedia.org/wiki/Computational_fluid_dynamics

[edit]Magical time-travelling quote
Quote:Original post by Sneftel
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.
Could be both! I remember in an interview they mention that the background actually takes up the majority of their processing time ;)
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.
Quote:Original post by Sneftel
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.


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..
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:
http://www.file-upload.net/download-2063014/crazygeo.tar.gz.html

i used the sprin system.
Quote:Original post by Sudi
I made a little demo trying that effct myself.


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

Quote:Original post by Sneftel
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.


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.

This topic is closed to new replies.

Advertisement