Пример #1
0
        protected override void OnConstruct()
        {
            base.OnConstruct();
            ClearGraphics();
            MainGraphic = new MetaModel
            {
                //XMesh = new MeshConcretize
                //{
                //    MeshDescription = new Graphics.Software.Meshes.MeshFromHeightmap
                //    {
                //        Grid = new Graphics.Software.Meshes.Grid
                //        {
                //            Position = Vector3.Zero,
                //            MeshType = MeshType.Indexed,
                //            Size = Size,
                //            NWidth = (int)((Ground.Heightmap.GetLength(1) - 1) * HeightmapSelection.Width),
                //            NHeight = (int)((Ground.Heightmap.GetLength(0) - 1) * HeightmapSelection.Height),
                //            UVMin = new Vector2(0, 0),
                //            UVMax = new Vector2(1, 1)
                //        },
                //        Height = Ground.Height,
                //        Heightmap = Ground.Heightmap,
                //        Rectangle = HeightmapSelection,
                //        PointSample = true
                //    },
                //    Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                //},
                Texture = new TextureFromFile("Models/GroundTextures/Grass1.png")
            };
            Random r = new Random();

            for (int i = 0; i < 100; i++)
            {
                float x = (float)r.NextDouble() * Size.X;
                float y = (float)r.NextDouble() * Size.Y;
                AddGraphic(new MetaModel
                {
                    XMesh = new MeshConcretize
                    {
                        MeshDescription = new Graphics.Software.Meshes.IndexedPlane
                        {
                            Facings  = Facings.Frontside | Facings.Backside,
                            Position = new Vector3(0, -1, 0),
                            Size     = new Vector2(1, 1),
                            UVMin    = new Vector2(0.05f, 0.05f),
                            UVMax    = new Vector2(0.95f, 0.95f)
                        },
                        Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                    },
                    Texture = new TextureFromFile("Models/GroundTextures/Sand1.png"),
                    World   = Matrix.RotationX(-(float)System.Math.PI / 2f) *
                              Matrix.RotationZ((float)(r.NextDouble() * System.Math.PI * 2f)) *
                              Matrix.Translation(x, y,
                                                 TextureUtil.BilinearSample(Ground.Heightmap,
                                                                            (Translation.Y + y) / Ground.Size.Height,
                                                                            (Translation.Y + x) / Ground.Size.Width).R),
                });
            }
        }