Пример #1
0
        public override void Update(float dtime)
        {
            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);


            if (sceneQuadtree != null)
            {
                sceneRendererConnector.CullScene(sceneQuadtree);
            }

            sceneRendererConnector.UpdateAnimations(dtime);

            Device9.BeginScene();

            if (wireframe)
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
            }
            else
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Solid);
            }

            renderer.Render(dtime);

            Device9.EndScene();

            var time = (DateTime.Now - startTime);

            Application.MainWindow.Text = "running for: " +
                                          time.Hours + ":" + time.Minutes.ToString().PadLeft(2, '0') + ":" +
                                          time.Seconds.ToString().PadLeft(2, '0') + ", " +
                                          FPS + " fps, " + nEntitiesInScene + " entities";
        }
Пример #2
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(sceneQuadtree);
            sceneRendererConnector.UpdateAnimations(dtime);

            if (InputHandler != null)
            {
                InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                    Dtime = dtime
                });
            }

            renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, 0, 0, 0), 1.0f, 0);

            Device9.BeginScene();

            renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = "ParticleSystem || Particles: " + nParticles + " || Fps: " + FPS;
        }
Пример #3
0
        public override void Update(float dtime)
        {
            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);

            Device9.BeginScene();

            if (wireframe)
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
            }
            else
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Solid);
            }

            renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = FPS + " fps";
        }
Пример #4
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            //accDtime += 2.0f * dtime;

            billboards[0].Scale = new Vector3(1, 1, 1);

            //billboards[0].Translation = accDtime * direction;

            sceneRendererConnector.CullScene(sceneQuadtree);
            sceneRendererConnector.UpdateAnimations(dtime);

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            Renderer.Render(dtime);

            Device9.EndScene();
            //Draw3DLines(Scene.Camera, Matrix.Identity, new Vector3[] { Vector3.Zero, ((LookatCamera)Scene.Camera).Lookat}, Color.Red);
            Application.MainWindow.Text = "BillboardTest || Fps: " + FPS + " || Number of billboards: " + nBillboards;
        }
Пример #5
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(sceneQuadtree);
            sceneRendererConnector.UpdateAnimations(dtime);

            accDtime += dtime;
            for (int i = 0; i < nBillboards; i++)
            {
                billboards[i].Translation = accDtime * directions[i];
            }

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            Renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = "BillboardTest || Fps: " + FPS + " || Number of billboards: " + nBillboards;
        }
Пример #6
0
        public override void Update(float dtime)
        {
            InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                Dtime = dtime
            });
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkGray, 1.0f, 0);

            Device9.BeginScene();
            editorRenderer.Render(this);

            Device9.EndScene();
        }
Пример #7
0
        public override void Update(float dtime)
        {
            sceneRendererConnector.UpdateAnimations(dtime);
            sceneRendererConnector.CullScene(null);

            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);

            Device9.BeginScene();

            renderer.Render(dtime);

            Device9.EndScene();
        }
Пример #8
0
        public override void Update(float dtime)
        {
            if (InputHandler != null)
            {
                InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                    Dtime = dtime
                });
            }

            if (Direct3DVersion == Direct3DVersion.Direct3D10)
            {
                Device10.ClearRenderTargetView(GraphicsDevice.RenderView, clearColor);
            }
            else
            {
                Device9.Clear(SlimDX.Direct3D9.ClearFlags.Target | SlimDX.Direct3D9.ClearFlags.ZBuffer,
                              clearColor, 1.0f, 0);

                Device9.BeginScene();
            }

            InterfaceRenderer.Render(dtime);
            if (pb != null)
            {
                pb.Value += dtime * 10;
                if (pb.Value > 100)
                {
                    pb.Value = 0;
                }

                tt.SetToolTip(pb, "This is a progress bar\n" + (int)(pb.Value) + "/" + pb.MaxValue);
            }

            //if (cb != null && cb.Checked)
            //{
            //    bvr.Begin(InterfaceScene.Camera);
            //    foreach (var v in Manager.Clickables.All)
            //        bvr.Draw(v.CombinedWorldMatrix, v.PickingLocalBounding, Color.Red);
            //    bvr.End();
            //}

            if (Direct3DVersion == Direct3DVersion.Direct3D9)
            {
                Device9.EndScene();
            }

            Application.MainWindow.Text = "Using " + Direct3DVersion + ", " + FPS.ToString() + " fps";
            System.Console.WriteLine(x++ + " : " + x * 2 + " * " + x * 3 + " - " + x * 4 + " s " + x * 5);
        }
Пример #9
0
        public override void Update(float dtime)
        {
            windowsCursor.Position = new Vector2(LocalMousePosition.X, LocalMousePosition.Y);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            InterfaceRenderer.Render(dtime);
            Application.MainWindow.Text = FPS.ToString();

            Device9.EndScene();

            System.Threading.Thread.Sleep(1000 / 30);
        }
Пример #10
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            Renderer.Render(dtime);
            Device9.EndScene();
        }
Пример #11
0
        public override void Update(float dtime)
        {
            sceneRendererConnector.UpdateAnimations(dtime);

            sceneRendererConnector.CullScene(null);

            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);

            Device9.BeginScene();

            Device9.SetRenderState(RenderState.FillMode, wireframe ? FillMode.Wireframe : FillMode.Solid);

            renderer.Render(dtime);

            Device9.EndScene();
        }
        public override void Update(float dtime)
        {
            base.Update(dtime);
            var o = npc.VisibilityWorldBounding;

            if (InputHandler is WalkaroundCameraInputHandler && !Paused)
            {
                motionSimulation.Step(dtime);
                if (npc.MotionObject.Position.Z < 0.5f)
                {
                    Console.Write("asd");
                }
            }

            if (InputHandler != null)
            {
                InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                    Dtime = dtime
                });
            }

            Graphics.Renderer.Renderer renderer = (Graphics.Renderer.Renderer) this.renderer;

            sceneRendererConnector.CullScene(sceneQuadtree);
            sceneRendererConnector.UpdateAnimations(dtime);

            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateGray, 1.0f, 0);

            /////////////////////////////////////////////////////////////////////
            Device9.BeginScene();

            renderer.Render(dtime);
            editorRenderer.Render(this);

            if (activeGrid != null)
            {
                DrawGrid(activeGrid);
            }

            Device9.EndScene();
            /////////////////////////////////////////////////////////////////////

            Window.Text = "FPS: " + FPS + ", NPos: " + npc.Translation /*+ ", PPos: " + pursuer.Translation*/;
        }
Пример #13
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            renderer.PreRender(dtime);
            Device9.Clear(SlimDX.Direct3D9.ClearFlags.Target | SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.DarkSlateGray, 1.0f, 0);

            Device9.BeginScene();

            renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = "FPS: " + FPS + ", Compuation time: " + lastCalculationTime;
        }
Пример #14
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            Renderer.Render(dtime);

            Device9.EndScene();
            //Draw3DLines(Scene.Camera, Matrix.Identity, new Vector3[] { Vector3.Zero, ((LookatCamera)Scene.Camera).Lookat}, Color.Red);
            Application.MainWindow.Text = "IndicesTest || Fps: " + FPS;
        }
Пример #15
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
                          Color.FromArgb(255, (int)(Renderer.Settings.FogColor.X * 255), (int)(Renderer.Settings.FogColor.Y * 255), (int)(Renderer.Settings.FogColor.Z * 255)), 1.0f, 0);

            Device9.BeginScene();

            Renderer.Render(dtime);

            Application.MainWindow.Text = "Furie       FPS: " + FPS;

            Device9.EndScene();
        }
Пример #16
0
        public override void Update(float dtime)
        {
            //dtime = timestep;    // fixed time step
            base.Update(dtime);

            if (neverStop || playing)
            {
                //((Common.Motion.Simulation)motionSimulation).DebugResolve();
                motionSimulation.Step(dtime);
            }

            foreach (var u in unitGroupA)
            {
                var umo = (Common.Motion.Unit)u.MotionObject;
                if (umo.IntersectedUnits)
                {
                    playing = false;
                }
                DisplayCollision(u);
            }
            foreach (var u in unitGroupB)
            {
                var umo = (Common.Motion.Unit)u.MotionObject;
                if (umo.IntersectedUnits)
                {
                    playing = false;
                }
                DisplayCollision(u);
            }

            renderer.PreRender(dtime);
            Device9.Clear(SlimDX.Direct3D9.ClearFlags.Target | SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.DarkSlateGray, 1.0f, 0);

            Device9.BeginScene();

            renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = "FPS: " + FPS;
        }
Пример #17
0
        public override void Update(float dtime)
        {
            base.Update(dtime);

            if (motionSimulation.Running)
            {
                AdvanceFrame();
            }

            sceneRendererConnector.CullScene(null);
            sceneRendererConnector.UpdateAnimations(dtime);

            renderer.PreRender(dtime);
            Device9.Clear(SlimDX.Direct3D9.ClearFlags.Target | SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.DarkSlateGray, 1f, 0);
            Device9.BeginScene();

            renderer.Render(dtime);

            foreach (var o in motionSimulation.All)
            {
                var proj = o as Common.IMotion.IProjectile;
                if (proj != null)
                {
                    Vector3 endpoint = proj.Position + dtime * proj.Velocity;
                    Draw3DLines(scene.Camera, Matrix.Identity, new Vector3[] { proj.Position, endpoint }, Color.Blue);
                }

                var umo = o as Common.IMotion.IUnit;
                if (umo != null)
                {
                    Common.Bounding.Cylinder cyl = (Common.Bounding.Cylinder)umo.WorldBounding;
                    DrawCircle(scene.Camera, Matrix.Identity, cyl.Position, cyl.Radius, 12, Color.Orange);
                    DrawCircle(scene.Camera, Matrix.Identity, cyl.Position + new Vector3(0, 0, cyl.Height), cyl.Radius, 12, Color.Orange);
                }
            }

            Device9.EndScene();

            Application.MainWindow.Text = "FPS: " + FPS + ", Units hit last shot: " + unitsHitLastShot;
        }
Пример #18
0
        public override void Update(float dtime)
        {
            sceneRendererConnector.UpdateAnimations(dtime);

            sceneRendererConnector.CullScene(null);

            renderer.PreRender(dtime);
            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);

            Device9.BeginScene();

            renderer.Render(dtime);
            bvr.Begin(scene.Camera);
            foreach (var v in scene.AllEntities)
            {
                if (v is BVEntity)
                {
                    bvr.Draw(v.WorldMatrix, ((BVEntity)v).BoundingVolume, Color.Blue);
                }
            }
            bvr.End();

            Device9.EndScene();
        }
Пример #19
0
        public override void Update(float dtime)
        {
            dtime *= speed;
            base.Update(dtime);

            if (sceneQuadtree != null)
            {
                SRC.CullScene(sceneQuadtree);
            }

            SRC.UpdateAnimations(dtime);

            SRC.Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(1, (int)(0.6 * 255), (int)(0.8 * 255), 255), 1.0f, 0);

            Device9.BeginScene();

            SRC.Renderer.Render(dtime);

            Device9.EndScene();

            Application.MainWindow.Text = "" + FPS;
        }
Пример #20
0
        public override void Update(float dtime)
        {
            Renderer.Settings.WaterLevel     = MainWindow.Instance.CurrentMap.Settings.WaterHeight;
            Renderer.Settings.AmbientColor   = MainWindow.Instance.CurrentMap.Settings.AmbientColor;
            Renderer.Settings.DiffuseColor   = MainWindow.Instance.CurrentMap.Settings.DiffuseColor;
            Renderer.Settings.FogColor       = MainWindow.Instance.CurrentMap.Settings.FogColor;
            Renderer.Settings.SpecularColor  = MainWindow.Instance.CurrentMap.Settings.SpecularColor;
            Renderer.Settings.LightDirection = MainWindow.Instance.CurrentMap.Settings.LightDirection;
            if (FogEnabled)
            {
                Renderer.Settings.FogDistance = MainWindow.Instance.CurrentMap.Settings.FogDistance;
                Renderer.Settings.FogExponent = MainWindow.Instance.CurrentMap.Settings.FogExponent;
            }
            else
            {
                Renderer.Settings.FogDistance = 100000;
                Renderer.Settings.FogExponent = 100000;
            }

            Renderer.CalcShadowmapCamera(Renderer.Settings.LightDirection, 0);

            if (sceneQuadtree != null)
            {
                SceneRendererConnector.CullScene(sceneQuadtree);
            }

            SceneRendererConnector.UpdateAnimations(dtime);

            if (InputHandler != null)
            {
                InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                    Dtime = dtime
                });
            }

            Renderer.PreRender(dtime);

            Device9.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(Renderer.Settings.FogColor), 1.0f, 0);
            Device9.BeginScene();

            if (Wireframe)
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Wireframe);
            }
            else
            {
                Device9.SetRenderState(RenderState.FillMode, FillMode.Solid);
            }

            Renderer.Render(dtime);
            state.OnRender();

            bvRenderer.Begin(Scene.Camera);

            if (Program.Settings.DisplayGroundBoundings)
            {
                foreach (var v in MainWindow.Instance.CurrentMap.Ground.quadtree.All)
                {
                    var b = MainWindow.Instance.CurrentMap.Ground.quadtree.GetBounding(v);
                    bvRenderer.Draw(Matrix.Identity, b, Color.Yellow);
                }
            }

            if (MainWindow.Instance.placementBoundingsToolStripMenuItem.Checked)
            {
                foreach (var v in PlacementBoundings.All)
                {
                    var b = ((Client.Game.Map.GameEntity)v).EditorPlacementWorldBounding;
                    bvRenderer.Draw(Matrix.Identity, b, Color.Yellow);
                }
            }

            helperVisualizations.Settings.PhysicsBoundings           = MainWindow.Instance.physicsBoundingsToolStripMenuItem.Checked;
            helperVisualizations.Settings.PhysicsBoundingsFullChains = MainWindow.Instance.showFullChainsToolStripMenuItem.Checked;
            helperVisualizations.Settings.PhysicsBoundingsHideGround = MainWindow.Instance.physicsBoundingsHideGroundToolStripMenuItem.Checked;
            helperVisualizations.Settings.AggroRange      = MainWindow.Instance.aggroRangeToolStripMenuItem.Checked;
            helperVisualizations.Settings.VisualBoundings = MainWindow.Instance.visualBoundingsToolStripMenuItem.Checked;

            helperVisualizations.Render(bvRenderer,
                                        this,
                                        Scene,
                                        MainWindow.Instance.CurrentMap.NavMesh,
                                        Renderer.Frame);

            if (MainWindow.Instance.mapBoundsToolStripMenuItem.Checked)
            {
                float border = 20;
                bvRenderer.Draw(Matrix.Identity, new BoundingBox(
                                    new Vector3(border, border, 0),
                                    new Vector3(MainWindow.Instance.CurrentMap.Settings.Size.Width - border,
                                                MainWindow.Instance.CurrentMap.Settings.Size.Height - border, 0)
                                    ), Color.Black);
            }

            if (MainWindow.Instance.pickingBoundingsToolStripMenuItem.Checked)
            {
                foreach (var v in Scene.AllEntities)
                {
                    if (v is Client.Game.Map.GameEntity)
                    {
                        bvRenderer.Draw(Matrix.Identity,
                                        v.PickingWorldBounding,
                                        Color.Orange);
                    }
                }
            }

            bvRenderer.End();

            Device9.EndScene();
            Device9.Present();
        }
Пример #21
0
        //private float timestep = 0.1f;
        public override void Update(float dtime)
        {
            //dtime = timestep;
            base.Update(dtime);

            Random r = new Random();

            if (InputHandler != null)
            {
                InputHandler.ProcessMessage(MessageType.Update, new UpdateEventArgs {
                    Dtime = dtime
                });
            }

            if (droppingUnits)
            {
                if (DateTime.Now.Subtract(lastDrop).TotalMilliseconds >= 6000)
                {
                    int nUnits = units.Count;
                    foreach (var u in units)
                    {
                        u.Remove();
                    }
                    units.Clear();
                    for (int i = 0; i < nUnits; i++)
                    {
                        InsertUnit(r);
                    }
                    lastDrop = DateTime.Now;
                }
            }
            else
            {
                if (DateTime.Now.Subtract(lastJump).TotalMilliseconds >= 3000)
                {
                    foreach (var u in units)
                    {
                        var umo = (Common.IMotion.IUnit)u.MotionObject;
                        if (r.NextDouble() > 0 && umo.IsOnGround)
                        {
                            umo.VelocityImpulse(new Vector3(8f * (float)r.NextDouble() - 4f, 8f * (float)r.NextDouble() - 4f, 3f * (float)r.NextDouble() + 2f));
                        }
                        //umo.VelocityImpulse(new Vector3(0, 0, 3f * (float)r.NextDouble() + 2f));
                    }
                    lastJump = DateTime.Now;
                }

                if (DateTime.Now.Subtract(lastDirectionChange).TotalMilliseconds >= 3000)
                {
                    foreach (var u in units)
                    {
                        var umo = (Common.IMotion.IUnit)u.MotionObject;
                        umo.RunVelocity = new Vector2(8f * (float)r.NextDouble() - 4f, 8f * (float)r.NextDouble() - 4f);
                    }
                    lastDirectionChange = DateTime.Now;
                    if (lastJump == DateTime.MinValue)
                    {
                        lastJump = DateTime.Now.AddMilliseconds(750);
                    }
                }
            }

            if (motionSimulation.Running)
            {
                motionSimulation.Step(dtime);
            }

            if (recordingHeight)
            {
                float height = ((Common.Motion.Simulation)motionSimulation).DebugReturnQuadtree.DebugCheckGroundHeight(controlledUnit.MotionObject.Position);
                recordedHeight.Add(new Vector3(controlledUnit.MotionObject.Position.X, controlledUnit.MotionObject.Position.Y, height));
            }

            if (renderingScene)
            {
                Graphics.Renderer.Renderer renderer = (Graphics.Renderer.Renderer) this.renderer;

                if (sceneQuadtree != null)
                {
                    sceneRendererConnector.CullScene(sceneQuadtree);
                }

                sceneRendererConnector.UpdateAnimations(dtime);

                renderer.PreRender(dtime);
                Device9.Clear(SlimDX.Direct3D9.ClearFlags.Target | SlimDX.Direct3D9.ClearFlags.ZBuffer, Color.DarkSlateGray, 1.0f, 0);

                Device9.BeginScene();

                renderer.Render(dtime);

                if (drawingUnitBBs)
                {
                    foreach (var u in units)
                    {
                        Vector3 min, max;
                        UnitBoxCoords(u.MotionObject.Position, out min, out max);
                        Draw3DAABB(scene.Camera, Matrix.Identity, min, max, Color.Red);
                        UnitBoxCoords(u.MotionObject.InterpolatedPosition, out min, out max);
                        Draw3DAABB(scene.Camera, Matrix.Identity, min, max, Color.Blue);
                    }
                }
                if (controlledUnit != null)
                {
                    Vector3 min, max;
                    UnitBoxCoords(controlledUnit.MotionObject.Position, out min, out max);
                    Draw3DAABB(scene.Camera, Matrix.Identity, min, max, Color.Red);
                    UnitBoxCoords(controlledUnit.MotionObject.InterpolatedPosition, out min, out max);
                    Draw3DAABB(scene.Camera, Matrix.Identity, min, max, Color.Blue);
                }

                if (drawingGroundLines)
                {
                    int   xPieces  = xSize;
                    int   yPieces  = xSize;
                    float stepx    = size.Width / (float)(heightMap[0].Length - 1);
                    float stepy    = size.Height / (float)(heightMap.Length - 1);
                    int   nxPieces = heightMap[0].Length / xPieces;
                    int   nyPieces = heightMap.Length / yPieces;
                    for (int yp = 0; yp < yPieces; yp++)
                    {
                        for (int xp = 0; xp < xPieces; xp++)
                        {
                            for (int y = 0; y < nyPieces; y++)
                            {
                                for (int x = 0; x < nxPieces; x++)
                                {
                                    //Vector3 pos0 = new Vector3((xp * nxPieces + x) * stepx, (yp * nyPieces + y) * stepy, heightMap[yp * (nyPieces - 1) + y][xp * (nxPieces - 1) + x]);
                                    Vector3 pos0 = GetPosOrSmth(x, xp, nxPieces, stepx, y, yp, nyPieces, stepy);
                                    Vector3 pos1 = GetPosOrSmth(x + 1, xp, nxPieces, stepx, y, yp, nyPieces, stepy);
                                    Vector3 pos2 = GetPosOrSmth(x, xp, nxPieces, stepx, y + 1, yp, nyPieces, stepy);

                                    Draw3DLines(scene.Camera, Matrix.Identity, new Vector3[] { pos0, pos1 }, (xp == xPieces - 1 ? Color.Red : Color.Green));
                                    Draw3DLines(scene.Camera, Matrix.Identity, new Vector3[] { pos0, pos2 }, Color.Green);
                                }
                            }
                        }
                    }
                }

                Device9.EndScene();
            }

            //var unit = ValidateUnitPositions();
            MotionEntity unit = null;

            if (motionSimulation.Running && unit != null)
            {
                motionSimulation.Running = false;
                ((MetaModel)unit.MainGraphic).Texture = new TextureConcretizer
                {
                    Texture = global::Graphics.Software.ITexture.SingleColorTexture(Color.Red)
                };

                var umo = ((Common.IMotion.IUnit)unit.MotionObject);
                tag = "Position: " + unit.MotionObject.Position + ". RunVelocity: " + umo.RunVelocity +
                      ". OnGround: " + umo.IsOnGround;
                FocusCamera(umo.Position);
            }

            var forRemoval = new List <MotionEntity>();

            foreach (var u in units)
            {
                if (u.MotionObject.Position.Z < -18 + heightOffset)
                {
                    forRemoval.Add(u);
                }
            }
            foreach (var u in forRemoval)
            {
                units.Remove(u);
                u.Remove();
                InsertUnit(r);   // Keep balance
            }

            if (motionSimulation.Running)
            {
                Application.MainWindow.Text = "FPS: " + FPS + ". #Static: " +
                                              ". #ListUnits: " + units.Count + (controlledUnit != null ? ". UnitPos: " + Common.Math.ToVector2(controlledUnit.Translation).ToString() : "") +
                                              ". CamPos: " + scene.Camera.Position;
            }
            else
            {
                Application.MainWindow.Text = tag + ". CamPos: " + scene.Camera.Position;
            }
        }