Beispiel #1
0
        public void ConstructPieces()
        {
            Random r = new Random();

            GroundPieces = new TestGroundPiece[NPieces.Height, NPieces.Width];
            float xstep = Size.Width / NPieces.Width;
            float ystep = Size.Height / NPieces.Height;

            for (int y = 0; y < NPieces.Height; y++)
            {
                for (int x = 0; x < NPieces.Width; x++)
                {
                    var piece = new TestGroundPiece
                    {
                        Translation        = new Vector3(xstep * x, ystep * y, 0),
                        Ground             = this,
                        HeightmapSelection = new RectangleF(
                            x / (float)NPieces.Width,
                            y / (float)NPieces.Height,
                            1 / (float)NPieces.Width,
                            1 / (float)NPieces.Height),
                        Size       = new Vector2(xstep, ystep),
                        Color      = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255)),
                        Simulation = Simulation
                    };
                    piece.ConstructAll();
                    var xmesh = ((MetaModel)piece.MainGraphic).XMesh;
                    var mo    = Simulation.CreateStatic();
                    mo.LocalBounding = new Common.Bounding.Chain
                    {
                        Shallow   = true,
                        Boundings = new object[]
                        {
                            new MetaBoundingBox {
                                Mesh = xmesh
                            },
                            new BoundingMetaMesh
                            {
                                Mesh = xmesh,
                            }
                        }
                    };

                    mo.Position                   = piece.Translation;
                    piece.MotionObject            = mo;
                    piece.VisibilityLocalBounding = Scene.View.Content.Peek <StructBoxer <BoundingBox> >(piece.MainGraphic).Value;

                    Scene.Add(GroundPieces[y, x] = piece);
                }
            }
        }
        public void ConstructPieces()
        {
            Random r = new Random();

            GroundPieces = new TestGroundPiece[NPieces.Height, NPieces.Width];
            float xstep = Size.Width / NPieces.Width;
            float ystep = Size.Height / NPieces.Height;
            for (int y = 0; y < NPieces.Height; y++)
                for (int x = 0; x < NPieces.Width; x++)
                {
                    var piece = new TestGroundPiece
                    {
                        Translation = new Vector3(xstep * x, ystep * y, 0),
                        Ground = this,
                        HeightmapSelection = new RectangleF(
                            x / (float)NPieces.Width,
                            y / (float)NPieces.Height,
                            1 / (float)NPieces.Width,
                            1 / (float)NPieces.Height),
                        Size = new Vector2(xstep, ystep),
                        Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255)),
                        Simulation = Simulation
                    };
                    piece.ConstructAll();
                    var xmesh = ((MetaModel)piece.MainGraphic).XMesh;
                    var mo = Simulation.CreateStatic();
                    mo.LocalBounding = new Common.Bounding.Chain
                    {
                        Shallow = true,
                        Boundings = new object[]
                        {
                            new MetaBoundingBox { Mesh = xmesh },
                            new BoundingMetaMesh
                            {
                                Mesh = xmesh,
                            }
                        }
                    };

                    mo.Position = piece.Translation;
                    piece.MotionObject = mo;
                    piece.VisibilityLocalBounding = Scene.View.Content.Peek<StructBoxer<BoundingBox>>(piece.MainGraphic).Value;

                    Scene.Add(GroundPieces[y, x] = piece);
                }
        }