Beispiel #1
0
        public TerrainMesh(RenderSystem rs, int x, int y, int size)
            : base(TerrainMeshManager.Instance, GetHashString(x, y, size))
        {
            this.opBuffer = new FastList <RenderOperation>();

            this.terrEdgeSize = size;
            this.tileX        = x;
            this.tileY        = y;

            renderSystem = rs;
            factory      = rs.ObjectFactory;

            material          = new Material(rs);
            material.CullMode = CullMode.None;


            material.Ambient      = new Color4F(1, 0.5f, 0.5f, 0.5f);
            material.Diffuse      = new Color4F(1f, 1f, 1f, 1f);
            material.Specular     = new Color4F(0, 0, 0, 0);
            material.Power        = 1;
            material.PriorityHint = RenderPriority.Second;


            PlanetEarth.TileCoord2CoordNew(x, y, out tileCol, out tileLat);

            // 估算包围球
            {
                float radtc = MathEx.Degree2Radian(tileCol);
                float radtl = MathEx.Degree2Radian(tileLat);
                float rad5  = PlanetEarth.DefaultTileSpan * 0.5f;

                BoundingSphere.Center = PlanetEarth.GetPosition(radtc + rad5, radtl - rad5);
                BoundingSphere.Radius = MathEx.Root2 * PlanetEarth.GetTileHeight(rad5 * 2);

                if (ObjectSpaceChanged != null)
                {
                    ObjectSpaceChanged(Transformation, BoundingSphere);
                }
            }
        }
Beispiel #2
0
        static void SrtmBath(string srcDir, string bathy)
        {
            const string tmpDir = @"E:\Desktop\tmp\";

            const int bathWidth  = 18433;
            const int bathHeight = 9217;

            byte[] bathyData;

            BinaryReader br = new BinaryReader(File.Open(bathy, FileMode.Open));

            bathyData = br.ReadBytes(bathWidth * bathHeight);
            br.Close();

            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0" + ".tdmp");
                    if (File.Exists(file))
                    {
                        string file2 = Path.Combine(tmpDir, "tile_" + x.ToString("D2") + "_" + (y + 6).ToString("D2") + "_0" + ".tdmp");
                        File.Copy(file, file2);
                    }
                }
            }


            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file = Path.Combine(tmpDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0" + ".tdmp");

                    int startX = (x - 1) * 256;
                    int startY = (y - 1) * 256;// +1536;

                    if (y > 3 && y < 33)
                    {
                        if (File.Exists(file))
                        {
                            TDMPIO d1 = new TDMPIO();
                            d1.Load(new DevFileLocation(file));
                            d1.XSpan *= 2;
                            d1.YSpan *= 2;
                            PlanetEarth.TileCoord2CoordNew(x, y, out d1.Xllcorner, out d1.Yllcorner);

                            float[] data = d1.Data;

                            for (int i = 0; i < d1.Height; i++)
                            {
                                for (int j = 0; j < d1.Width; j++)
                                {
                                    int idx = i * d1.Height + j;
                                    data[idx] *= 5000;

                                    data[idx] += 1500;
                                    data[idx] -= (0xff - bathyData[(startY + i) * bathWidth + startX + j]) * (1500f / 256f);

                                    //data[idx] /= 7000;
                                }
                            }

                            Stream sout = File.Open(Path.Combine(@"E:\Desktop\out\", Path.GetFileNameWithoutExtension(file) + ".tdmp"), FileMode.OpenOrCreate);
                            d1.Save(sout);



                            for (int i = 0; i < d1.Height; i++)
                            {
                                for (int j = 0; j < d1.Width; j++)
                                {
                                    int idx = i * d1.Height + j;
                                    data[idx] /= 7000;
                                }
                            }
                            TDmpBlur.OutPng(data, d1.Width, d1.Height, Path.Combine(@"E:\Desktop\out\",
                                                                                    Path.GetFileNameWithoutExtension(file) + ".png"));
                        }
                        else
                        {
                            TDMPIO d2 = new TDMPIO();
                            d2.Width  = 513;
                            d2.Height = 513;
                            d2.XSpan  = 10;
                            d2.YSpan  = 10;
                            d2.Bits   = 16;

                            PlanetEarth.TileCoord2CoordNew(x, y, out d2.Xllcorner, out d2.Yllcorner);

                            d2.Data = new float[513 * 513];

                            for (int i = 0; i < d2.Height; i++)
                            {
                                for (int j = 0; j < d2.Width; j++)
                                {
                                    int idx = i * d2.Height + j;

                                    d2.Data[idx]  = 1600;
                                    d2.Data[idx] -= (0xff - bathyData[(startY + i) * bathWidth + startX + j]) * (1500f / 256f);
                                }
                            }

                            Stream sout = File.Open(Path.Combine(@"E:\Desktop\out\", Path.GetFileNameWithoutExtension(file) + ".tdmp"), FileMode.OpenOrCreate);
                            d2.Save(sout);



                            for (int i = 0; i < d2.Height; i++)
                            {
                                for (int j = 0; j < d2.Width; j++)
                                {
                                    int idx = i * d2.Height + j;
                                    d2.Data[idx] /= 7000;
                                }
                            }
                            TDmpBlur.OutPng(d2.Data, d2.Width, d2.Height, Path.Combine(@"E:\Desktop\out\",
                                                                                       Path.GetFileNameWithoutExtension(file) + ".png"));
                        }
                    }
                }
            }
        }