コード例 #1
0
ファイル: River.cs プロジェクト: longde123/VolumetricTerrain
 public River(IslandTileCorner c)
 {
     this.data   = c;
     this.left   = null;
     this.right  = null;
     this.father = null;
 }
コード例 #2
0
        //calculate elevation for each pixel
        public float PixelElevation(Vector p, List <IslandTileCorner> bottomcorners)
        {
            //note: e0=u*e1+v*e2
            IslandTileCorner c1 = bottomcorners[0];
            IslandTileCorner c2 = bottomcorners[1];
            Vector           e0 = new Vector(p.data[0] - center.data[0], p.data[1] - center.data[1]);
            //e0.data[0] = p.data[0] - center.data[0];
            //e0.data[1] = p.data[1] - center.data[1];
            Vector e1 = new Vector(c1.position.data[0] - center.data[0], c1.position.data[1] - center.data[1]);
            //e1.data[0] = c1.position.data[0] - center.data[0];
            //e1.data[1] = c1.position.data[1] - center.data[1];
            Vector e2 = new Vector(c2.position.data[0] - center.data[0], c2.position.data[1] - center.data[1]);
            //e2.data[0] = c2.position.data[0] - center.data[0];
            //e2.data[1] = c2.position.data[1] - center.data[1];
            double temp = e1.data[0] * e2.data[1] - e1.data[1] * e2.data[0];
            double u    = (e0.data[0] * e2.data[1] - e0.data[1] * e2.data[0]) / temp;
            double v    = (e0.data[1] * e1.data[0] - e0.data[0] * e1.data[1]) / temp;
            //System.Console.WriteLine(u + " " + v);
            float pixelelevation;

            pixelelevation = (float)(elevation + (c1.elevation - elevation) * u + (c2.elevation - elevation) * v);
            return(pixelelevation);
        }
コード例 #3
0
ファイル: Island.cs プロジェクト: longde123/VolumetricTerrain
        public void GenerateSubRiver(River sr)
        {
            //to make it easy I don't concider the subriver of a subriver
            IslandTileCorner highest = sr.data;

            foreach (var c in sr.data.adjacent)
            {
                if (c.elevation > highest.elevation)
                {
                    highest = c;
                }
            }
            if (sr.right == null)
            {
                sr.right        = new River(highest);
                sr.right.father = sr;
            }
            counts++;
            if (counts < _subStreamLength)
            {
                GenerateSubRiver(sr.right);
            }
        }
コード例 #4
0
 //constructor of IslandTileEdge
 public IslandTileEdge(VoronoiEdge e)
 {
     edge    = e;
     cornera = IslandTileCorner.Index[e.VVertexA];
     cornerb = IslandTileCorner.Index[e.VVertexB];
 }
コード例 #5
0
        public void AddCorners(VoronoiEdge e)
        {
            IslandTileCorner ca;

            if (IslandTileCorner.Index.ContainsKey(e.VVertexA))
            {
                ca = IslandTileCorner.Index[e.VVertexA];
            }
            else
            {//conflicts of out of boundaries
                //and through this progress, all tile near border will be seted as water
                //(IslandTile.water is false by default)
                if (e.VVertexA.data[0] <= 0)
                {
                    e.VVertexA.data[0] = 0;
                    //this.iswater = true;
                }
                if (e.VVertexA.data[0] >= (width - 1))
                {
                    e.VVertexA.data[0] = (width - 1);
                    //this.iswater = true;
                }
                if (e.VVertexA.data[1] <= 0)
                {
                    e.VVertexA.data[1] = 0;
                    //this.iswater = true;
                }
                if (e.VVertexA.data[1] >= (hight - 1))
                {
                    e.VVertexA.data[1] = (hight - 1);
                    //this.iswater = true;
                }
                ca = new IslandTileCorner(e.VVertexA);
            }
            IslandTileCorner cb;

            if (IslandTileCorner.Index.ContainsKey(e.VVertexB))
            {
                cb = IslandTileCorner.Index[e.VVertexB];
            }
            else
            {
                if (e.VVertexB.data[0] <= 0)
                {
                    e.VVertexB.data[0] = 0;
                    //this.iswater = true;
                }
                if (e.VVertexB.data[0] >= (width - 1))
                {
                    e.VVertexB.data[0] = (width - 1);
                    //this.iswater = true;
                }
                if (e.VVertexB.data[1] <= 0)
                {
                    e.VVertexB.data[1] = 0;
                    //this.iswater = true;
                }
                if (e.VVertexB.data[1] >= (hight - 1))
                {
                    e.VVertexB.data[1] = (hight - 1);
                    //this.iswater = true;
                }
                cb = new IslandTileCorner(e.VVertexB);
            }
            ca.adjacent.Add(cb);
            cb.adjacent.Add(ca);
            ca.protrudes.Add(e);
            cb.protrudes.Add(e);
            ca.touches.Add(this);
            cb.touches.Add(this);
            corners.Add(ca);
            // total_corners.Add(ca);
            corners.Add(cb);
            //total_corners.Add(cb);
        }
コード例 #6
0
ファイル: Island.cs プロジェクト: longde123/VolumetricTerrain
        private void GenerateMainRiver(River rc)
        {
            IslandTileCorner maxima      = rc.data;
            bool             existMaxima = false;

            foreach (var c in rc.data.adjacent)
            {
                if (c.elevation > maxima.elevation)
                {
                    maxima      = c;
                    existMaxima = true;
                }
            }

            if (!existMaxima)
            {
                return;
            }

            if (rc.right == null)
            {
                rc.right        = new River(maxima);
                rc.right.father = rc;
            }
            countm++;
            if (countm < _mainStreamLength)
            {
                GenerateMainRiver(rc.right);
            }

            double doSplit = _rndGen.NextDouble();

            if (doSplit > _riverSplitFreq)
            {
                return;
            }

            IslandTileCorner secondMaxima      = rc.data;
            bool             existSecondMaxima = false;

            foreach (var c in rc.data.adjacent)
            {
                if ((c.elevation > secondMaxima.elevation) && (c != maxima))
                {
                    secondMaxima      = c;
                    existSecondMaxima = true;
                }
            }
            if (!existSecondMaxima)
            {
                return;
            }

            if (rc.left == null)
            {
                rc.left        = new River(secondMaxima);
                rc.left.father = rc;
            }
            GenerateSubRiver(rc.left);
            counts = 0;
        }