コード例 #1
0
ファイル: Game.cs プロジェクト: bondjames12/spheregame
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // If enabling this option does NOT reduce frame rate,
            // we must be GPU bound
            //System.Threading.Thread.Sleep(100);



            //Input processor update KB,Mouse,Gamepad
            input.Update(gameTime);


            //this logic should be integrated into the main update loop somewhere
            //must be after physics and position updates then set the final camera positions then call update

            /*          if (currentCamera == driverCamera)
             *        {
             *            //set position is Head bone of the Car model!
             *            driverCamera.Position = Vector3.Transform(Vector3.Zero, Matrix.Identity * Car.Car.GetWorldMatrix(Car.Chassis.Model, Vector3.Zero)[0] * Car.Chassis.Model.Bones["Head"].Transform);
             *            //driverCamera.Update(ref gameTime);
             *        }
             */
            //Advance physics engine
            X.AdvancePhysics(ref gameTime);

            //After physics run, update chase cameras positions/orientation.
            if (currentCamera == chase)
            {
                chase.ChaseTargetPosition = Car.Position;
                chase.ChaseTargetForward  = Car.Orientation.Forward;
                chase.Up = Car.Orientation.Up;
            }

            //Call engine update will call update on all updateable engine components
            X.UpdateComponents(ref gameTime);


            //XNA Update
            base.Update(gameTime);
        }
コード例 #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();
        }