Ejemplo n.º 1
0
    float HeightDifference(Vector2 cell, FluxMode mode)
    {
        switch (mode)
        {
        case FluxMode.LeftFlux:
            if ((int)cell.x - 1 < 0)
            {
                return(0);
            }
            return(grid[(int)cell.x, (int)cell.y].terrainHeight + grid[(int)cell.x, (int)cell.y].waterHeight - grid[(int)cell.x - 1, (int)cell.y].terrainHeight - grid[(int)cell.x - 1, (int)cell.y].waterHeight);

        case FluxMode.RightFlux:
            if ((int)cell.x + 1 >= size)
            {
                return(0);
            }
            return(grid[(int)cell.x, (int)cell.y].terrainHeight + grid[(int)cell.x, (int)cell.y].waterHeight - grid[(int)cell.x + 1, (int)cell.y].terrainHeight - grid[(int)cell.x + 1, (int)cell.y].waterHeight);

        case FluxMode.UpFlux:
            if ((int)cell.y - 1 < 0)
            {
                return(0);
            }
            return(grid[(int)cell.x, (int)cell.y].terrainHeight + grid[(int)cell.x, (int)cell.y].waterHeight - grid[(int)cell.x, (int)cell.y - 1].terrainHeight - grid[(int)cell.x, (int)cell.y - 1].waterHeight);

        case FluxMode.DownFlux:
            if ((int)cell.y + 1 >= size)
            {
                return(0);
            }
            return(grid[(int)cell.x, (int)cell.y].terrainHeight + grid[(int)cell.x, (int)cell.y].waterHeight - grid[(int)cell.x, (int)cell.y + 1].terrainHeight - grid[(int)cell.x, (int)cell.y + 1].waterHeight);

        default:
            return(0);
        }
    }
Ejemplo n.º 2
0
    float GetFlux(Vector2 cell, FluxMode mode, float Δt)
    {
        switch (mode)
        {
        case FluxMode.LeftFlux:
            return(Mathf.Max(0,
                             grid[(int)cell.x, (int)cell.y].outflowFlux[(int)FluxMode.LeftFlux] + Δt * (pipeLength * pipeLength) * ((Physics.gravity.y * HeightDifference(cell, FluxMode.LeftFlux)) / pipeLength)));

        case FluxMode.RightFlux:
            return(Mathf.Max(0,
                             grid[(int)cell.x, (int)cell.y].outflowFlux[(int)FluxMode.RightFlux] + Δt * (pipeLength * pipeLength) * ((Physics.gravity.y * HeightDifference(cell, FluxMode.RightFlux)) / pipeLength)));

        case FluxMode.UpFlux:
            return(Mathf.Max(0,
                             grid[(int)cell.x, (int)cell.y].outflowFlux[(int)FluxMode.UpFlux] + Δt * (pipeLength * pipeLength) * ((Physics.gravity.y * HeightDifference(cell, FluxMode.UpFlux)) / pipeLength)));

        case FluxMode.DownFlux:
            return(Mathf.Max(0,
                             grid[(int)cell.x, (int)cell.y].outflowFlux[(int)FluxMode.DownFlux] + Δt * (pipeLength * pipeLength) * ((Physics.gravity.y * HeightDifference(cell, FluxMode.DownFlux)) / pipeLength)));

        default:
            return(0);
        }
    }