Ejemplo n.º 1
0
    Vector3 GetVertexBlendElevation(GridElevations el, GridDirection direction, GridDirection edge)
    {
        float delta = GetStraightGrad(el, edge) * GridMetrics.blendFactor / 2;

        if (edge == direction.Next()) //fix clockwise direction
        {
            delta *= -1;
        }
        return(Vector3.up * GridMetrics.elevationStep * ((float)el[direction] + delta));
    }
Ejemplo n.º 2
0
    void CreateCell(int x, int z, int i)
    {
        Vector3 position;

        position.x = x;
        position.y = 0f;
        position.z = z;

        SquareCell cell = cells[i] = Instantiate <SquareCell>(cellPrefab);

        cell.transform.localPosition = position;
        if (x > 0)
        {
            cell.SetNeighbor(GridDirection.W, cells[i - 1]);
        }
        if (z > 0)
        {
            cell.SetNeighbor(GridDirection.S, cells[i - cellCountX]);
        }
        if (z > 0 && x > 0)
        {
            cell.SetNeighbor(GridDirection.SW, cells[i - cellCountX - 1]);
        }
        if (z > 0 && x < cellCountX - 1)
        {
            cell.SetNeighbor(GridDirection.SE, cells[i - cellCountX + 1]);
        }
        cell.coordinates = GridCoordinates.FromOffsetCoordinates(x, z);
        if (heightmap == null)
        {
            cell.GridElevations = GridElevations.GetVertexHeights(position, seed);
        }
        else
        {
            cell.GridElevations = GridElevations.GetVertexHeightsFromHeightmap(position, heightmap);
        }

        // start off with grass everywhere
        cell.Tile = gridMaterials[0].GetClone;
        if (cell.CentreElevation < 7) // basic treeline cut-off
        {
            cell.PlantLevel = UnityEngine.Random.Range(0, 100) - 95;
        }
        AddCellToChunk(x, z, cell);
    }
Ejemplo n.º 3
0
 float GetStraightGrad(GridElevations el, GridDirection direction)
 {
     return((float)el[direction.Previous()] - (float)el[direction.Next()]);
 }
Ejemplo n.º 4
0
    Vector3 GetDoubleVertexBlendElevation(GridElevations el, GridDirection direction)
    {
        float delta = (GetStraightGrad(el, direction.Previous()) - GetStraightGrad(el, direction.Next())) * GridMetrics.blendFactor / 2;

        return(Vector3.up * GridMetrics.elevationStep * ((float)el[direction] + delta));
    }