Exemplo n.º 1
0
    public void SetVertexColors(int x, int y, bool rect, float power, Color clr, float radius, List <PAPointXY> points)
    {
        int i, j;
        int count = (int)(radius / settings.tileSize);
        int xMin = x, xMax = x, yMin = y, yMax = y;
        //float distance;
        Vector3   currentPos, tilePos;
        PAPointXY p;

        xMin = x - count; xMin = Mathf.Clamp(xMin, 0, settings.xCount);
        yMin = y - count; yMin = Mathf.Clamp(yMin, 0, settings.yCount);
        xMax = x + count; xMax = Mathf.Clamp(xMax, 0, settings.xCount);
        yMax = y + count; yMax = Mathf.Clamp(yMax, 0, settings.yCount);

        currentPos = new Vector3(x * settings.tileSize, 0.0f, y * settings.tileSize);

        for (j = yMin; j <= yMax; ++j)
        {
            for (i = xMin; i <= xMax; ++i)
            {
                tilePos = new Vector3(i * settings.tileSize, 0.0f, j * settings.tileSize);

                if (!rect && Vector3.Distance(tilePos, currentPos) > radius)
                {
                    continue;
                }
                p = new PAPointXY(i, j); if (!points.Contains(p))
                {
                    points.Add(p);
                }
                SetVertexColor(i, j, power, clr);
            }
        }
    }
Exemplo n.º 2
0
    public void SmoothPointTerrain(int x, int y, bool rect, float power, float radius, List<PAPointXY> points)
    {
        int i, j, pi, mi;
        int count = (int)(radius / settings.diagonalLength);
        int xMin = x, xMax = x, yMin = y, yMax = y;
        float h;
        Vector3 currentPos, tilePos;
        PAPointXY p;
        PATile tile;
        List<Mesh> ms = new List<Mesh>();
        List<Vector3[]> vs = new List<Vector3[]>();
        Mesh mesh;
        bool c;
        PAPoint point;
        Vector3[] vertices;

        xMin = x - count; xMin = Mathf.Clamp(xMin, 0, settings.xCount);
        yMin = y - count; yMin = Mathf.Clamp(yMin, 0, settings.yCount);
        xMax = x + count; xMax = Mathf.Clamp(xMax, 0, settings.xCount);
        yMax = y + count; yMax = Mathf.Clamp(yMax, 0, settings.yCount);

        currentPos = new Vector3(x * settings.tileSize, 0.0f, y * settings.tileSize);

        for (j = yMin; j <= yMax; ++j)
        for (i = xMin; i <= xMax; ++i)
        {
            tilePos = new Vector3(i * settings.tileSize, 0.0f, j * settings.tileSize);

            if (!rect && Vector3.Distance(tilePos, currentPos) > radius) continue;
            p = new PAPointXY(i, j); if (!points.Contains(p)) points.Add(p);
            h = GetSmoothPointHeight(i, j, power);

            point = settings.points[(settings.xCount + 1) * j + i];
            for (pi = 0; pi < 4; ++pi)
                if (point.t[pi] >= 0)
                {
                    c = false;
                    tile = GetTile(point.t[pi]);
                    mesh = GetChunkMesh(tile.chunkId);
                    vertices = null;

                    for (mi = 0; mi < ms.Count; ++mi) if (ms[mi] == mesh) { c = true; vertices = vs[mi]; }
                    if (vertices == null) vertices = mesh.vertices;

                    vertices[tile.cId * 4 + point.p[pi]].y = Mathf.Clamp(h, settings.minHeight, settings.maxHeight);

                    if (!c) { ms.Add(mesh); vs.Add(vertices); }
                }
        }

        for (i = 0; i < ms.Count; ++i) ms[i].vertices = vs[i];
    }
Exemplo n.º 3
0
    public void DeformPointTerrain(int x, int y, bool rect, float power, float radius, List<PAPointXY> points)
    {
        int count = (int)(radius / settings.diagonalLength);
        int xMin = x, xMax = x, yMin = y, yMax = y;
        int i, j;
        float distance, falloff;
        Vector3 currentPos, tilePos;
        PAPointXY p;

        xMin = x - count; xMin = Mathf.Clamp(xMin, 0, settings.xCount);
        yMin = y - count; yMin = Mathf.Clamp(yMin, 0, settings.yCount);
        xMax = x + count; xMax = Mathf.Clamp(xMax, 0, settings.xCount);
        yMax = y + count; yMax = Mathf.Clamp(yMax, 0, settings.yCount);

        currentPos = new Vector3(x * settings.tileSize, 0.0f, y * settings.tileSize);
        for (j = yMin; j <= yMax; ++j)
        for (i = xMin; i <= xMax; ++i)
        {
            p = new PAPointXY(i, j); if (!points.Contains(p)) points.Add(p);
            if (rect)
            {
                falloff = power;
            } else
            {
                tilePos = new Vector3(i * settings.tileSize, 0.0f, j * settings.tileSize);
                distance = Vector3.Distance(currentPos, tilePos);
                falloff = GaussFalloff(distance, radius) * power;
            }
            SetPointHeight(i, j, falloff, true);
        }
    }
Exemplo n.º 4
0
    public void SetVertexColors(int x, int y, bool rect, float power, Color clr, float radius, List<PAPointXY> points)
    {
        int i, j;
        int count = (int)(radius / settings.tileSize);
        int xMin = x, xMax = x, yMin = y, yMax = y;
        //float distance;
        Vector3 currentPos, tilePos;
        PAPointXY p;

        xMin = x - count; xMin = Mathf.Clamp(xMin, 0, settings.xCount);
        yMin = y - count; yMin = Mathf.Clamp(yMin, 0, settings.yCount);
        xMax = x + count; xMax = Mathf.Clamp(xMax, 0, settings.xCount);
        yMax = y + count; yMax = Mathf.Clamp(yMax, 0, settings.yCount);

        currentPos = new Vector3(x * settings.tileSize, 0.0f, y * settings.tileSize);

        for (j = yMin; j <= yMax; ++j)
        for (i = xMin; i <= xMax; ++i)
        {
            tilePos = new Vector3(i * settings.tileSize, 0.0f, j * settings.tileSize);

            if (!rect && Vector3.Distance(tilePos, currentPos) > radius) continue;
            p = new PAPointXY(i, j); if (!points.Contains(p)) points.Add(p);
            SetVertexColor(i, j, power, clr);
        }
    }