Exemplo n.º 1
0
        public FluidSimulation(World world)
        {
            this._world = world;
            _activeParticles = new List<int>(MAX_PARTICLES);
            _liquid = new Particle[MAX_PARTICLES];
            for (int i = 0; i < MAX_PARTICLES; i++)
            {
                _liquid[i] = new Particle(Vector2.Zero, Vector2.Zero, false);
                _liquid[i].index = i;
            }

            _delta = new Vector2[MAX_PARTICLES];
            _scaledPositions = new Vector2[MAX_PARTICLES];
            _scaledVelocities = new Vector2[MAX_PARTICLES];

            _grid = new Dictionary<int, Dictionary<int, List<int>>>();

            _halfScreen = new Vector2(
                GeneralManager.ScreenX,
                GeneralManager.ScreenY) / 2f;
            _simulationAABB.LowerBound.X = 0;//-(_halfScreen.X + 100f);
            _simulationAABB.LowerBound.Y = 0;//-(_halfScreen.Y + 100f);
            _simulationAABB.UpperBound.X = 1000;//_halfScreen.X + 100f;
            _simulationAABB.UpperBound.Y = -1000;//_halfScreen.Y + 100f;
        }
Exemplo n.º 2
0
        private void findNeighbors(Particle particle)
        {
            particle.neighborCount = 0;
            Dictionary<int, List<int>> gridX;
            List<int> gridY;

            for (int nx = -1; nx < 2; nx++)
            {
                for (int ny = -1; ny < 2; ny++)
                {
                    int x = particle.ci + nx;
                    int y = particle.cj + ny;
                    if (_grid.TryGetValue(x, out gridX) && gridX.TryGetValue(y, out gridY))
                    {

                        for (int a = 0; a < gridY.Count; a++)
                        {
                            if (gridY[a] != particle.index)
                            {
                                particle.neighbors[particle.neighborCount] = gridY[a];
                                particle.neighborCount++;

                                if (particle.neighborCount >= MAX_NEIGHBORS)
                                    return;
                            }
                        }
                    }
                }
            }
        }