예제 #1
0
    public List <int> PossibleNeighbors(FluidManager.Particle p)
    {
        List <int> possibleNeighbors = new List <int>();

        int x   = (int)(p.pos.x / range);
        int y   = (int)(p.pos.y / range);
        int key = GetKey(x, y);

        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x, y + 1);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x, y - 1);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x + 1, y);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x + 1, y + 1);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x + 1, y - 1);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x - 1, y);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x - 1, y + 1);
        possibleNeighbors.AddRange(hashTable[key]);
        key = GetKey(x - 1, y - 1);
        possibleNeighbors.AddRange(hashTable[key]);

        return(possibleNeighbors);
    }
예제 #2
0
    public void MoveParticle(ref FluidManager.Particle p)
    {
        int x   = (int)((p.pos.x / range));
        int y   = (int)((p.pos.y / range));
        int key = GetKey(x, y);

        //If p still on same cell, do nothing
        if (key == p.hashKey)
        {
            return;
        }

        //Else move p to the fine cell
        hashTable[key].Add(p.index);
        if (p.hashKey != -1)
        {
            hashTable[p.hashKey].Remove(p.index);
        }
        p.hashKey = key;
    }