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*/;
        }
Ejemplo n.º 2
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;
            }
        }