Пример #1
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            MAstroBody b = MPlanetHandler.CurrentNear;

            if (b == null)
            {
                return;
            }
            MTerrainTile tile = b.CurrentTile;

            if (tile == null)
            {
                return;
            }

            /*
             * if ((tile.PhysicsIsComplete == true) && (tile.GrassPlanter.IsComplete == false))
             * {
             * tile.GrassPlanter.PrepareGrass(tile);
             * }
             */
            lock (matlocker)
            {
                PlantGrass(b, tile);
            }
        }
Пример #2
0
        public void PrepareGrass(MTerrainTile tile)
        {
            MTerrainTile Tile         = tile;
            Matrix4d     TreeRotation = Matrix4d.CreateFromQuaternion(Quaterniond.FromEulerAngles(tile.transform.Up()));

            float numxinterps = LOD0Size / Tile.x_res;
            float numzinterps = LOD0Size / Tile.z_res;

            for (int x = 0; x < LOD0Size; x++)
            {
                for (int z = 0; z < LOD0Size; z++)
                {
                    Vector3d PlantingPos = new Vector3d((x / numxinterps), 0, (z / numzinterps));
                    //PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos);
                    //double y = tile.ElevationAtPoint(x / numxinterps, z / numzinterps);
                    //PlantingPos = new Vector3d(x, y, z);
                    PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos);
                    Matrix4d TreeScale    = Matrix4d.Scale(10, 10, 10);
                    Matrix4d TreePosition = Matrix4d.CreateTranslation(PlantingPos);
                    Matrix4  final        = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
                    Grassmats[x, z] = final;
                }
            }

            IsComplete = true;
            Console.WriteLine("Grass Planted:" + Tile.TileX + "," + Tile.TileY);
        }
Пример #3
0
        public void GetPOI(int tx, int ty, Vector3d AvatarPosLonLat)
        {
            string TileNum = TerrainNumber(tx, ty);

            if (!Tiles.ContainsKey(TileNum))
            {
                return;
            }
            MTerrainTile tile = Tiles[TileNum];

            Tiles[TileNum].UpdateAvatarLonLat(AvatarPosLonLat);
        }
Пример #4
0
        //TODO: pull the nearest blades from the Grassmats and add to mats
        //OR: Rolling buffer, taking from behind and adding edges of direction of travel
        public void PlantGrass3(MAstroBody planet, MTerrainTile tile)
        {
            Tile = tile;
            if (tile.material == null)
            {
                return;
            }
            if (Tile.GrassPlanter.IsComplete == false)
            {
                return;
            }

            Vector3d    AP   = Globals.Avatar.GetPosition();
            Barycentric bary = new Barycentric(Tile.Boundary.TL, Tile.Boundary.BR, Tile.Boundary.TR, AP);

            Vector3d Centroid = new Vector3d((1 - bary.u) * MGrassPlanter.LOD0Size, 0, bary.v * MGrassPlanter.LOD0Size);

            int cx = (int)(bary.u * MGrassPlanter.LOD0Size);
            int cz = (int)(bary.v * MGrassPlanter.LOD0Size);

            float numxinterps = MGrassPlanter.LOD0Size / Tile.x_res;
            float numzinterps = MGrassPlanter.LOD0Size / Tile.z_res;

            TotalInstances = 0;
            for (int x = 0; x < 100; x++)
            {
                for (int z = 0; z < 100; z++)
                {
                    if (TotalInstances >= Settings.MaxGrassPerTerrain)
                    {
                        continue;
                    }
                    if (cx + x > MGrassPlanter.LOD0Size)
                    {
                        continue;
                    }
                    if (cz + z > MGrassPlanter.LOD0Size)
                    {
                        continue;
                    }

                    mats[TotalInstances] = Tile.GrassPlanter.Grassmats[cx + x, cz + z];
                    TotalInstances++;
                }
            }

            Planted = true;
        }
Пример #5
0
        void InitializeTile(string TileNum, int tx, int ty, int zoom)
        {
            TileCount++;
            Console.WriteLine("Tile:" + TileCount + " Initialize " + tx + "," + ty);

            MTerrainTile tile = new MTerrainTile(tx, ty, ZoomLevel, CurrentBody.Radius.X);

            tile.SetShader(TerrainShader);
            Tiles.Add(TileNum, tile);
            MScene.Background.Add(Tiles[TileNum]);
            MTerrainBoundary tb             = CurrentBody.GetTileBoundaryLonLat(tx, ty, ZoomLevel);
            double           metersperpixel = CurrentBody.GroundResolution(tb.LonLatTL.Y, ZoomLevel);

            //Tiles[TileNum].transform.Scale = new Vector3d(256*metersperpixel, 1, 256 *metersperpixel);
            //Vector3d ll = CurrentBody.TileToLonLat(tx, ty, zoom);
            Vector3d ll = tb.LonLatTL;
            //Vector3d pos = CurrentBody.LonLatToUniPosition(ll.X, ll.Y, 0);
            Vector3d pos = MGISTools.LonLatMercatorToPosition(ll.X, ll.Y, CurrentBody.Radius.X) + CurrentBody.Position;

            Tiles[TileNum].transform.Position = pos;
            Tiles[TileNum].SetBoundary(tb);
            Tiles[TileNum].Setup(CurrentBody);
        }
Пример #6
0
        public void PlantTrees(MAstroBody planet, MTerrainTile tile)
        {
            //DistanceThreshold = tile.DistanceThreshold;
            Tile = tile;
            if (tile.material == null)
            {
                return;
            }
            MTexture tex = Tile.Biome;

            if (tex == null)
            {
                return;
            }

            this.transform.Position = tile.transform.Position;

            Random ran = new Random(1234);

            Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation());

            int i = 0;

            for (int z = 0; z < tile.z_res - 1; z++)
            {
                for (int x = 0; x < tile.x_res - 1; x++)
                {
                    float[] c = tex.GetPixel(x, z);
                    float   r = c[0];
                    float   g = c[1];
                    float   b = c[2];
                    float   a = c[3];

                    float t = 0;
                    //if ((b > r) && (b > g)) t = g;
                    if ((r < 0.05) && (g > 0.1) && (b < 0.05))
                    {
                        t = g;
                    }
                    else
                    {
                        continue;
                    }

                    if (ran.NextDouble() > Settings.TreeDensity)
                    {
                        continue;
                    }

                    //if (g < 0.7) continue;
                    //Console.WriteLine(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);
                    if (i >= Settings.MaxTreesPerTerrain)
                    {
                        break;
                    }
                    Vector3d Treepos = new Vector3d(x,
                                                    0,
                                                    z);
                    //Vector3d PlantingPos = planet.GetNearestPointOnSphere(Treepos, 0);
                    Matrix4d TreeScale    = Matrix4d.Scale(1 + ran.NextDouble(), 1 + ran.NextDouble() * 2, 1 + ran.NextDouble());
                    Vector3d PlantingPos  = Tile.GetPointOnSurfaceFromGrid(Treepos); //; + new Vector3d(r.NextDouble()*5, r.NextDouble() * 5, r.NextDouble()*5);
                    Matrix4d TreePosition = Matrix4d.CreateTranslation(PlantingPos);
                    //find point at y with raycast
                    Matrix4 final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
                    mats[i] = final;
                    i++;
                }
            }

            TotalInstances = i;

            for (int j = TotalInstances; j < Settings.MaxTreesPerTerrain; j++)
            {
                Matrix4 final = Matrix4.CreateTranslation(j, 0, 0);
                mats[j] = final;
            }

            //Setup();
            //UploadBuffer();
            Planted = false;
        }
Пример #7
0
        public void PlantGrass(MAstroBody planet, MTerrainTile tile)
        {
            // if (Planted == true) return;
            //DistanceThreshold = tile.DistanceThreshold;
            Tile = tile;
            if (tile.material == null)
            {
                return;
            }
            MTexture tex = Tile.Biome;

            if (tex == null)
            {
                return;
            }

            this.transform.Position = tile.transform.Position;

            //Random ran = new Random(1234);

            Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation());

            //int i = 0;
            TotalInstances = 0;

            Vector3d AP = Globals.Avatar.GetPosition();
            // Console.WriteLine(AP);

            Barycentric bary = new Barycentric(Tile.Boundary.TL, Tile.Boundary.BR, Tile.Boundary.TR, AP);

            PlantPatch(bary, 64 * 64, 2, 0.8);
            //PlantPatch(bary, 32 * 32, 8, 0.3);

            // Console.WriteLine(bary.ToString());

            /*
             * double sq = 64 * 64;
             * double sq2 = Math.Sqrt(sq);
             *
             * Matrix4d TreePosition;
             * Matrix4 final;
             * Matrix4d TreeScale;
             * Vector3d PlantingPos = new Vector3d();
             * for (int x = (int)-sq2; x < sq2; x++)
             * for (int z = (int)-sq2; z < sq2; z++)
             * {
             *  PlantingPos.X = (int)(Tile.x_res * (1 - bary.u)) - x * 0.05;
             *  PlantingPos.Y = 0;
             *  PlantingPos.Z = (int)(Tile.z_res * (bary.v)) - z * 0.05;
             *
             *  double yv =
             *    (MPerlin.Noise(PlantingPos.X, PlantingPos.Z) * 0.4)
             + (MPerlin.Noise(PlantingPos.X * 1.1, PlantingPos.Z * 1.1) * 0.4)
             +    ;
             +  if (yv < 0.1) continue;
             +
             +  TreeScale = Matrix4d.Scale(0.03+0.04 * yv,  0.01 + yv * 0.14 , 0.03+0.04* yv);
             +
             +  PlantingPos.X += MPerlin.Noise(PlantingPos.X * 4.0, PlantingPos.Z * 4.1) * 1.1;
             +  PlantingPos.Z += MPerlin.Noise(PlantingPos.X * 3.8, PlantingPos.Z * 4.2) * 1.1;
             +  PlantingPos = Tile.GetInterpolatedPointOnSurfaceFromGrid2(PlantingPos);
             +
             +  TreePosition = Matrix4d.CreateTranslation(PlantingPos);
             +  final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
             +  if (i < Settings.MaxGrassPerTerrain)
             +  {
             +    mats[i] = final;
             +    i++;
             +  }
             + }
             +
             + TotalInstances = i;
             */

            for (int j = TotalInstances; j < Settings.MaxGrassPerTerrain; j++)
            {
                Matrix4 final = Matrix4.CreateTranslation(9999999999, 0, 0);
                mats[j] = final;
            }


            //Setup();
            //UploadBuffer();
            Planted = true;
        }