void update(Shader& advect, Shader& computeDivergence, Shader& makeGravity, Shader& jacobi, Shader& subtractGradient) { float velocityDissipation = 0.99f; float densityDissipation = 1.0f; Advect(advect, velocity.Ping, velocity.Ping, obstacle, velocity.Pong, velocityDissipation); SwapSurfaces(&velocity); Advect(advect, velocity.Ping, density.Ping, obstacle, density.Pong, densityDissipation); SwapSurfaces(&density); ComputeDivergence(computeDivergence, velocity.Ping, obstacle, divergence); AddForce(makeGravity, velocity.Ping, velocity.Pong); SwapSurfaces(&velocity); //ClearSurface(pressure.Ping, 0); int numJacobiIterations = 20; for (int i = 0; i < numJacobiIterations; i++) { Jacobi(jacobi, pressure.Ping, divergence, obstacle, pressure.Pong); SwapSurfaces(&pressure); } SubtractGradient(subtractGradient, velocity.Ping, pressure.Ping, obstacle, velocity.Pong); SwapSurfaces(&velocity); }
void Calculate(int data) { glViewport(0, 0, g_iWidth, g_iHeight); Advect(Velocity.Ping, Velocity.Ping, Boundaries, Velocity.Pong, VelocityDissipation); SwapSurfaces(&Velocity); /*Advect(Velocity2.Ping, Velocity2.Ping, Boundaries, Velocity2.Pong, VelocityDissipation); SwapSurfaces(&Velocity2);*/ Advect(Velocity.Ping, Temperature.Ping, Boundaries, Temperature.Pong, TemperatureDissipation); SwapSurfaces(&Temperature); /*Advect(Velocity2.Ping, Temperature2.Ping, Boundaries, Temperature2.Pong, TemperatureDissipation); SwapSurfaces(&Temperature2);*/ Advect(Velocity.Ping, Density.Ping, Boundaries, Density.Pong, DensityDissipation); SwapSurfaces(&Density); /*Advect(Velocity2.Ping, Density2.Ping, Boundaries, Density2.Pong, DensityDissipation); SwapSurfaces(&Density2);*/ glutMouseFunc(Mouse); ApplyBuoyancy(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong, ax, ay); SwapSurfaces(&Velocity); /*ApplyBuoyancy2(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong); SwapSurfaces(&Velocity);*/ ApplyImpulse(Temperature.Ping, ImpulsePosition, ImpulseTemperature); ApplyImpulse(Density.Ping, ImpulsePosition, ImpulseDensity); /*ApplyImpulse(Temperature2.Ping, ImpulsePosition2, ImpulseTemperature); ApplyImpulse(Density2.Ping, ImpulsePosition2, ImpulseDensity);*/ ComputeDivergence(Velocity.Ping, Boundaries, Divergence); ClearSurface(Pressure.Ping, 0); /*ComputeDivergence(Velocity2.Ping, Boundaries, Divergence2); ClearSurface(Pressure2.Ping, 0);*/ for (int i = 0; i < NumJacobiIterations; ++i) { Jacobi(Pressure.Ping, Divergence, Boundaries, Pressure.Pong); SwapSurfaces(&Pressure); } /*for (int i = 0; i < NumJacobiIterations; ++i) { Jacobi(Pressure2.Ping, Divergence2, Boundaries, Pressure2.Pong); SwapSurfaces(&Pressure2); }*/ SubtractGradient(Velocity.Ping, Pressure.Ping, Boundaries, Velocity.Pong); SwapSurfaces(&Velocity); /*SubtractGradient(Velocity2.Ping, Pressure2.Ping, Boundaries, Velocity2.Pong); SwapSurfaces(&Velocity2);*/ glutPostRedisplay(); glutTimerFunc(30, Calculate, 1); }