예제 #1
0
        public float getMinHeight(float x, float y)
        {
            if (_minHeight == null)
            {
                return(-500.0f);
            }

            uint[] indices =
            {
                3, 0, 4,
                0, 1, 4,
                1, 2, 4,
                2, 5, 4,
                5, 8, 4,
                8, 7, 4,
                7, 6, 4,
                6, 3, 4
            };

            float[] boundGridCoords =
            {
                0.0f,               0.0f,
                0.0f,        -266.66666f,
                0.0f,        -533.33331f,
                -266.66666f,        0.0f,
                -266.66666f, -266.66666f,
                -266.66666f, -533.33331f,
                -533.33331f,        0.0f,
                -533.33331f, -266.66666f,
                -533.33331f, -533.33331f
            };

            Cell  cell = new Cell(x, y);
            float gx   = x - (cell.GetGridX() - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;
            float gy   = y - (cell.GetGridY() - MapConst.CenterGridId + 1) * MapConst.SizeofGrids;

            uint quarterIndex = 0;

            if (cell.GetCellY() < MapConst.MaxCells / 2)
            {
                if (cell.GetCellX() < MapConst.MaxCells / 2)
                {
                    quarterIndex = 4 + (gy > gx ? 1u : 0u);
                }
                else
                {
                    quarterIndex = (2 + ((-MapConst.SizeofGrids - gx) > gy ? 1u : 0));
                }
            }
            else if (cell.GetCellX() < MapConst.MaxCells / 2)
            {
                quarterIndex = 6 + ((-MapConst.SizeofGrids - gx) <= gy ? 1u : 0);
            }
            else
            {
                quarterIndex = gx > gy ? 1u : 0;
            }

            quarterIndex *= 3;

            return(new Plane(
                       new Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], _minHeight[indices[quarterIndex + 0]]),
                       new Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], _minHeight[indices[quarterIndex + 1]]),
                       new Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], _minHeight[indices[quarterIndex + 2]])
                       ).GetDistanceToPlane(new Vector3(gx, gy, 0.0f)));
        }
예제 #2
0
 public Grid(Cell cell, uint expiry, bool unload = true) : this(cell.GetId(), cell.GetGridX(), cell.GetGridY(), expiry, unload)
 {
 }