Ejemplo n.º 1
0
    private Vector3 DownRight(Vector3 center, RiverData.Direction dir)
    {
        Vector3 result = new Vector3();

        switch (dir)
        {
        case RiverData.Direction.Up:
            result.x = center.x + 0.5f;
            result.z = center.z - 0.5f;
            break;

        case RiverData.Direction.Right:
            result.x = center.x - 0.5f;
            result.z = center.z - 0.5f;
            break;

        case RiverData.Direction.Down:
            result.x = center.x - 0.5f;
            result.z = center.z + 0.5f;
            break;

        case RiverData.Direction.Left:
            result.x = center.x + 0.5f;
            result.z = center.z + 0.5f;
            break;
        }

        return(result);
    }
Ejemplo n.º 2
0
    private Vector3 PointSDir(Vector3 ori, RiverData.Direction a, RiverData.Direction b)
    {
        Vector3 result = new Vector3(ori.x, ori.y, ori.z);

        var amodify = RiverData.GetDirectionDir(a);
        var bmodify = RiverData.GetDirectionDir(b);

        result += amodify / 2;
        result += bmodify / 2;

        return(result);
    }
Ejemplo n.º 3
0
    private Vector3 DownRightEx(Vector3 center, RiverData.Direction dir)
    {
        Vector3 result = new Vector3();
        var     vector = RiverData.GetDirectionDir(dir);

        var noiseDir = (NoiseVector(center)).normalized;

        var direx   = (-vector + noiseDir).normalized;
        var dirleft = Vector3.Cross(direx, Vector3.up);

        result = center + (direx + dirleft) * 0.5f;
        return(result);
    }
Ejemplo n.º 4
0
    private Vector3 BorderLeftEx(Vector3 center, RiverData.Direction dir)
    {
        Vector3 result = new Vector3();
        var     vector = RiverData.GetDirectionDir(dir);

        var noiseModify = NoiseModify(center);
        //Vector3 noiseDir = new Vector3(noiseModify.x - center.x, 0, noiseModify.z - center.z);
        var noiseDir = (NoiseVector(center)).normalized;

        var direx   = (vector + noiseDir).normalized;
        var dirleft = Vector3.Cross(direx, Vector3.up);

        result = center + (direx + dirleft) * 0.5f;

        return(result);
    }
Ejemplo n.º 5
0
    private Vector3 NoiseModify(Vector3 kOri, float diff, RiverData.Direction oriDir)
    {
        Vector3 result = new Vector3(kOri.x, kOri.y, kOri.z);

        double twoPi = Math.PI * 2f;

        double T = 4.0;

        double a = kOri.x * twoPi / (T);
        double b = kOri.z * twoPi / (T);

        diff *= kNoisePercent;
        //float diff = (float)(Math.Sin(a) + Math.Sin(b)) * kNoisePercent;

        switch (oriDir)
        {
        case RiverData.Direction.Up:
        {
            result.x += diff;
        }
        break;

        case RiverData.Direction.Down:
        {
            result.x += diff;
        }
        break;

        case RiverData.Direction.Right:
        {
            result.z += diff;
        }
        break;

        case RiverData.Direction.Left:
        {
            result.z += diff;
        }
        break;
        }
        return(result);
    }
Ejemplo n.º 6
0
    private void GetPointsFromFlowDirAtTwo(RiverData.Direction predir, RiverData.Direction curdir, Vector3 pos, ref List <Vector3> left, ref List <Vector3> right)
    {
        if (predir == curdir || predir == RiverData.Direction.NotExist)
        {
            var r1 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Right));
            var r2 = PointSDir(pos, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Right), RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Down));
            var l1 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Left));
            var l2 = PointSDir(pos, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Left), RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Down));

            left.Add(l2);
            left.Add(l1);

            right.Add(r2);
            right.Add(r1);
        }
        else
        {
            var diffdir = RiverData.ThisDirisOrisDirsDir(curdir, predir);

            switch (diffdir)
            {
            case RiverData.Direction.Left:
            {
                var r1 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Right));
                var r2 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Down));
                var r3 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Left));
                var l1 = PointSDir(pos, curdir, RiverData.GetTargetDirsDir(curdir, RiverData.Direction.Down));
            }
            break;

            case RiverData.Direction.Right:
            {
            }
            break;
            }
        }
    }
Ejemplo n.º 7
0
    private void AddEightVertice(Vector3 downl, Vector3 l, Vector3 r, Vector3 downr, Color a, RiverData.Direction diff = RiverData.Direction.NotExist)
    {
        kBoundsPoints.Clear();
        kBoundsPoints.Add(l);
        kBoundsPoints.Add(r);

        var l1 = ModifyVector(LerpPos(downl, l, 0.66f));
        var l2 = ModifyVector(LerpPos(downl, l, 0.33f));

        var r1 = ModifyVector(LerpPos(downr, r, 0.66f));
        var r2 = ModifyVector(LerpPos(downr, r, 0.33f));

        if (diff == RiverData.Direction.Left)
        {
            var dir1 = r1 - l1;
            var dir2 = r2 - l2;

            r1 = ModifyVector(l1 + dir1 * 1.4f);
            r2 = ModifyVector(l2 + dir2 * 1.4f);
        }
        else if (diff == RiverData.Direction.Right)
        {
            var dir1 = l1 - r1;
            var dir2 = l2 - r2;

            l1 = ModifyVector(r1 + dir1 * 1.4f);
            l2 = ModifyVector(r2 + dir2 * 1.4f);
        }

        vertices.Add(downl);
        vertices.Add(l1);
        vertices.Add(l2);
        vertices.Add(l);
        vertices.Add(r);
        vertices.Add(r2);
        vertices.Add(r1);
        vertices.Add(downr);

        triangles.Add(verticesOffset + 0);
        triangles.Add(verticesOffset + 6);
        triangles.Add(verticesOffset + 7);
        triangles.Add(verticesOffset + 0);
        triangles.Add(verticesOffset + 1);
        triangles.Add(verticesOffset + 6);

        triangles.Add(verticesOffset + 1);
        triangles.Add(verticesOffset + 5);
        triangles.Add(verticesOffset + 6);
        triangles.Add(verticesOffset + 1);
        triangles.Add(verticesOffset + 2);
        triangles.Add(verticesOffset + 5);

        triangles.Add(verticesOffset + 2);
        triangles.Add(verticesOffset + 4);
        triangles.Add(verticesOffset + 5);
        triangles.Add(verticesOffset + 2);
        triangles.Add(verticesOffset + 3);
        triangles.Add(verticesOffset + 4);

        colors.Add(a);
        colors.Add(a);
        colors.Add(a);
        colors.Add(a);
        colors.Add(a);
        colors.Add(a);
        colors.Add(a);
        colors.Add(a);


        uvs.Add(new Vector2(1, 1));
        uvs.Add(new Vector2(1, 0.66f));
        uvs.Add(new Vector2(1, 0.33f));
        uvs.Add(new Vector2(1, 0));

        uvs.Add(new Vector2(0, 0));
        uvs.Add(new Vector2(0, 0.33f));
        uvs.Add(new Vector2(0, 0.66f));
        uvs.Add(new Vector2(0, 1));

        tangles.Add(new Vector4(1, 1, 0, 0));
        tangles.Add(new Vector4(1, 0.66f, 0, 0));
        tangles.Add(new Vector4(1, 0.33f, 0, 0));
        tangles.Add(new Vector4(1, 0, 0, 0));

        tangles.Add(new Vector4(0, 0, 0, 0));
        tangles.Add(new Vector4(0, 0.33f, 0, 0));
        tangles.Add(new Vector4(0, 0.66f, 0, 0));
        tangles.Add(new Vector4(0, 1, 0, 0));

        verticesOffset += 8;
    }
Ejemplo n.º 8
0
 private Vector3 ModifyVector(Vector3 kOri, float diff, RiverData.Direction oriDir)
 {
     return(HeightSample(NoiseModify(kOri, diff, oriDir)));
 }