Giter Club home page Giter Club logo

phaser-fluid's People

Contributors

wully616 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

phaser-fluid's Issues

density / ink is not mass conserving

the ink density is not mass conserving, when applying a vector on a grid with velocity the whole thing gets advected and essentially overwrites what is in the new field with what was in the old field

implement vortices

float epsilon=2;

void add_vorocity(int N, float * u, float * v, float dt) {

//vort is just the curl of the velocity field
#define vort(i,j) (( -0.5*( v[IX(i+1,j)]-v[IX(i-1,j)] + u[IX(i,j-1)]-u[IX(i,j+1)] )*N ))
	
	int i, j;

	int size = (N+2)*(N+2);

	float *fx		= (float *) malloc ( size*sizeof(float) );
	float *fy		= (float *) malloc ( size*sizeof(float) );

	FOR_EACH_CELL
		if(i==1 || j==1 || i==N || j==N) continue;

		float dvx = 0.5*(vort(i+1,j)-vort(i-1,j));
		float dvy = 0.5*(vort(i,j+1)-vort(i,j-1));

		float mag=sqrt(dvx*dvx+dvy*dvy);

		//apply a force equal to epsilon * cross(N,vor)
		fx[IX(i,j)]=mag > smallf ? epsilon*dt*dvy*vort(i,j)/(mag*N) : 0;
		fy[IX(i,j)]=mag > smallf ? epsilon*dt*dvx*vort(i,j)/(mag*N) : 0;
	END_FOR

	set_bnd ( N, 0, fx ); set_bnd ( N, 0, fy );


	FOR_EACH_CELL
		if(i==1 || j==1 || i==N || j==N) continue;

		if(u[IX(i,j)]) u[IX(i,j)]+=fx[IX(i,j)];
		if(v[IX(i,j)]) v[IX(i,j)]-=fy[IX(i,j)];
	END_FOR

	set_bnd ( N, 1, u ); set_bnd ( N, 2, v );

free(fx);
free(fy);

#undef vort

implement pressure differences between cells creating velocity forces

for (int x = 0; x < m_w-1; x++) {
for (int y = 0; y < m_h-1; y++) {
int cell = Cell(x,y);
float force_x =  mp_p0[cell] - mp_p0[cell+1];
float force_y =  mp_p0[cell] - mp_p0[cell+m_w];
mp_xv1[cell]     +=  a * force_x;
mp_xv1[cell+1]   +=  a * force_x;
mp_yv1[cell]     +=  a * force_y;
mp_yv1[cell+m_w] +=  a * force_y;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.