Ejemplo n.º 1
0
        protected override void Initialize()
        {
            time = new XEditorGameTime();
            X    = new XMain(this.GraphicsDevice, this.Services, ContentRootDir, camera);
            //setup some basic usefull settings
            X.Gravity       = new Vector3(0, -40, 0);
            X.UpdatePhysics = false;
            X.FrameRate.DisplayFrameRate = true;
            X.Console.AutoDraw           = false;
            X.Debug.StartPosition.Y      = 200;

            camera = new XFreeLookCamera(ref X, 0.1f, 1000f);
            //set the initial position of the camera such that we are looking at the center of the game world (0,0,0)
            camera.Position = new Vector3(30f, 15f, 40f);
            //so we look at center add in a rotation (trial and error)
            camera.Rotate(new Vector3(MathHelper.ToRadians(-10f), MathHelper.ToRadians(40f), 0));

            X.LoadContent();

            X.Physics.EnableFreezing = true;

            time.TotalGameTime.Reset();
            time.TotalGameTime.Start();
            time.ElapsedGameTime.Reset();
            time.ElapsedGameTime.Start();

            hasFocus        = false;
            dragdroprelease = false;
            SetupBaseComponents();

            //Begin draw timer!
            //redraw = new Timer();
            //redraw.Interval = 1;
            //redraw.Start();

            //redraw.Tick += new EventHandler(redraw_Tick);
            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };
        }
Ejemplo n.º 2
0
        protected override void Draw()
        {
            this.GraphicsDevice.Clear(Color.Red);
            GameTime gameTime = new GameTime(time.TotalGameTime.Elapsed, time.ElapsedGameTime.Elapsed, time.TotalGameTime.Elapsed, time.ElapsedGameTime.Elapsed, false);

            time.ElapsedGameTime.Reset();
            time.ElapsedGameTime.Start();



            if (hasFocus && keyboard != null && mouse != null)
            {
                if (keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                {
                    camera.Translate(Vector3.Backward * 400);
                }
                if (keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.W))
                {
                    camera.Translate(Vector3.Forward * 400);
                }
                if (keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.A))
                {
                    camera.Translate(Vector3.Left * 400);
                }
                if (keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    camera.Translate(Vector3.Right * 400);
                }

                if (mouse.ButtonPressed(XMouse.Buttons.Left))
                {
                    mouse.InitialPosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                    mouse.CurrentPosition = mouse.InitialPosition;
                    mouse.Delta           = Vector2.Zero;
                    mouse.Reset           = true;
                    manipulators          = false;
                    //Cursor.Hide();
                }
                else if (mouse.ButtonReleased(XMouse.Buttons.Left))
                {
                    mouse.Reset  = false;
                    manipulators = true;

                    if (!dragdroprelease)
                    {
                        Cursor.Show();
                    }
                    else
                    {
                        dragdroprelease = false;
                    }

                    ((EditorForm)Tag).RefreshPropertiesTab();
                }

                if (mouse.ButtonDown(XMouse.Buttons.Left))
                {
                    camera.Rotate(new Vector3(mouse.Delta.Y * .0016f, mouse.Delta.X * .0016f, 0));
                }

                if (mouse.ButtonReleased(XMouse.Buttons.Right))
                {
                    ((EditorForm)Tag).RefreshPropertiesTab();
                }
            }

            X.AdvancePhysics(ref gameTime);
            X.UpdateComponents(ref gameTime);

            if (manipulators)
            {
                mManipulator.Update();
            }

            X.Renderer.Draw(ref gameTime, ref camera.Base);
            mManipulator.Draw();

            float fps = (float)1000.0f / (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            this.Parent.Parent.Parent.Text = "Elapsed:" + gameTime.ElapsedGameTime.ToString() + " Total:" + gameTime.TotalGameTime.ToString() + " FPS:" + fps.ToString();
        }