# How to - '2d fluid sim' ?

Hi,

I’m looking for any advices that could help me to reproduction this with OF - http://www.smallfly.com/of/test-2.mov - it’s almost 2d fluid sim.

I tried using box2d but I don’t get something as reactive as what the video shows, and I don’t think I will.

The idea is to have the same motion/reaction and to be able to move any of the ‘nodes’, not just one extremity as is the video.

Thanks,

-h

Well…correction. I’m maybe getting somewhere using box2d.

-h

Box2D is probably massive overkill, but I wouldn’t be surprised if you needed something special for solving spring networks.

(If I understand it correctly, it’s just a network of n-1 springs attaching n objects?)

Yes this just a chain of n-1 springs attaching n objects. Any of the objects can be a ‘handle’.
Using box2d give me the opportunity to have access to other physics properties if I need (i.e. gravity), but I 'm still interested to approach this in a different way.

One thing I want to achieve, is to have several of those chains and to detect the ‘collisions’ and overlap between them. This in order to detect/define the shapes created by the overlap of 2 chains.

Ok, nice… if you need any more physics besides the spring (e.g., gravity) then Box2D is probably perfect.

Looking forward to seeing what you make…

Hi,

If you wanted to roll your own springs, here is some example code, assuming it is part of a particle class:

``````

void Particle::spring(Particle * p, float const k, float const springDist, float const drag) {
float dis = pos.distance(p->pos); //distance between two particles
dis = springDist-dis; //distance from resting position of spring

// find the direction to the other particle
ofxVec3f dir = ((ofxVec3f)(p->pos - pos)).normalized();

float force = (-k/(mass*p->mass))*(dis/drag); //spring force equation

//add velocity to both particles
vel += dir*(force/mass);
p->vel += dir*(-force/p->mass);
}

``````

Have fun,
Sounds like a cool project!