MGShaderEditor.Game1.Update C# (CSharp) Метод

Update() защищенный Метод

Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio.
protected Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime Provides a snapshot of timing values.
Результат void
        protected override void Update(GameTime gameTime)
        {

            //Inputs
            var ms = Mouse.GetState();
            var ks = Keyboard.GetState();

            //Control Mouse pos under Game Window
            bool bUnderWindows = false;

            if (Window.ClientBounds.Contains(ms.Position))
                bUnderWindows = true;

            //Process mouse events
            if (bUnderWindows)
            {

                //LMouse Down
                if (ms.LeftButton == ButtonState.Pressed && m_prevMouseState.LeftButton == ButtonState.Released)
                {

                    m_nStartDragX = ms.X;
                    m_nStartDragY = ms.Y;

                    if (ks.IsKeyDown(Keys.LeftControl) == true)
                    {
                        m_bZoomingCamera = true;
                    }
                    else
                    {
                        m_bDraggingCamera = true;
                    }
                }

                //LMouse Up
                if (ms.LeftButton == ButtonState.Released && m_prevMouseState.LeftButton == ButtonState.Pressed)
                {
                    m_bDraggingCamera = false;
                    m_bZoomingCamera = false;
                }

                //Mouse Move and camera dragging
                if (m_bDraggingCamera == true)
                {
                    float turnSpeed = 8f;

                    float offsetX = ((ms.X - m_nStartDragX) * turnSpeed * 0.001f); // pitch degree
                    float offsetY = ((ms.Y - m_nStartDragY) * turnSpeed * 0.001f); // yaw degree

                    var a = m_camera.AngleRad;
                    a.X -= offsetY;
                    a.Y -= offsetX;

                    a.Y = MathHelper.Clamp(a.Y, 0, MathHelper.Pi * 2);
                    a.X = MathHelper.Clamp(a.X, -(MathHelper.PiOver2 - 0.1f), (MathHelper.PiOver2 - 0.1f));

                    m_camera.AngleRad = a;

                    m_nStartDragX = ms.X;
                    m_nStartDragY = ms.Y;
                }

                //Mouse Move and camera zooming 
                if (m_bZoomingCamera == true)
                {
                    float speed = 8f;
                    float offsetY = ((ms.Y - m_nStartDragY) * speed * 0.001f);

                    m_camera.TargetDistance += offsetY;
                    m_camera.TargetDistance = MathHelper.Clamp(m_camera.TargetDistance, 1.0f, 10);

                    m_nStartDragY = ms.Y;
                }

                //Mouse Wheel
                var wheelDelta = m_prevMouseState.ScrollWheelValue - ms.ScrollWheelValue;
                if (wheelDelta != 0)
                {
                    m_camera.TargetDistance += (wheelDelta / 100.0f);
                    m_camera.TargetDistance = MathHelper.Clamp(m_camera.TargetDistance, 1.0f, 10);
                }

                m_prevMouseState = ms;
            }

            //Update Camera Matrices
            m_camera.Update(0);

            //Update Model World Matrice
            if (m_bDraggingCamera == false)
                m_fmodelRotation += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;

            m_World = Matrix.CreateRotationX(m_fmodelRotation) * Matrix.CreateRotationY(m_fmodelRotation) * Matrix.CreateRotationZ(m_fmodelRotation);


            base.Update(gameTime);
        }