Пример #1
0
        public void OnUpdateFrame(FrameEventArgs e, KeyboardDevice Keyboard)
        {
            float deltaShift = DeltaShift;

            if (Keyboard[Key.ShiftLeft] || Keyboard[Key.ShiftRight])
            {
                deltaShift /= 10.0f;
            }

            if (Keyboard[Key.W])
            {
                Position   += deltaShift * View;
                IsViewDirty = true;
            }
            else if (Keyboard[Key.S])
            {
                Position   -= deltaShift * View;
                IsViewDirty = true;
            }

            if (Keyboard[Key.D])
            {
                Position   -= deltaShift * Right;
                IsViewDirty = true;
            }
            else if (Keyboard[Key.A])
            {
                Position   += deltaShift * Right;
                IsViewDirty = true;
            }

            if (Keyboard[Key.E])
            {
                Position   -= deltaShift * Up;
                IsViewDirty = true;
            }
            else if (Keyboard[Key.Q])
            {
                Position   += deltaShift * Up;
                IsViewDirty = true;
            }

            if (Keyboard[Key.Plus])
            {
                Camera.Lens.FocalLength *= 1.05f;
                IsViewDirty              = true;
            }
            else if (Keyboard[Key.Minus])
            {
                Camera.Lens.FocalLength /= 1.05f;
                IsViewDirty              = true;
            }

            bool perspectiveChanged = false;

            if (Keyboard[Key.Insert])
            {
                Camera.FieldOfView /= 1.1f;
                perspectiveChanged  = true;
            }
            else if (Keyboard[Key.Delete])
            {
                Camera.FieldOfView *= 1.1f;
                perspectiveChanged  = true;
            }

            if (Keyboard[Key.R])
            {
                if (Keyboard[Key.ShiftLeft] || Keyboard[Key.ShiftRight])
                {
                    ResetNavigation();
                }
                else
                {
                    ResetCamera();
                }
                IsViewDirty        = true;
                perspectiveChanged = true;
            }

            float viewRotDelta = 0.025f;

            if (Keyboard[Key.Up])
            {
                RotateViewVertical(-viewRotDelta);
            }
            else if (Keyboard[Key.Down])
            {
                RotateViewVertical(viewRotDelta);
            }
            if (Keyboard[Key.Right])
            {
                RotateViewHorizontal(viewRotDelta);
            }
            else if (Keyboard[Key.Left])
            {
                RotateViewHorizontal(-viewRotDelta);
            }

            if (Keyboard[Key.Home])
            {
                Camera.Lens.ApertureNumber *= 1.05f;
                perspectiveChanged          = true;
            }
            else if (Keyboard[Key.End])
            {
                Camera.Lens.ApertureNumber /= 1.05f;
                perspectiveChanged          = true;
            }
            if (Keyboard[Key.PageUp])
            {
                Camera.FocusZ      = Math.Min(Camera.FocusZ * 1.05f, -float.Epsilon);
                perspectiveChanged = true;
            }
            else if (Keyboard[Key.PageDown])
            {
                Camera.FocusZ      = Math.Min(Camera.FocusZ / 1.05f, -float.Epsilon);
                perspectiveChanged = true;
            }

            if (Keyboard[Key.I])
            {
                float shiftY = BokehLab.Math.MathHelper.Clamp(Camera.LensShift.Y + 0.01f, -Camera.Lens.ApertureRadius, Camera.Lens.ApertureRadius);
                Camera.LensShift = new Vector2(Camera.LensShift.X, shiftY);
                IsViewDirty      = true;
            }
            else if (Keyboard[Key.K])
            {
                float shiftY = BokehLab.Math.MathHelper.Clamp(Camera.LensShift.Y - 0.01f, -Camera.Lens.ApertureRadius, Camera.Lens.ApertureRadius);
                Camera.LensShift = new Vector2(Camera.LensShift.X, shiftY);
                IsViewDirty      = true;
            }
            else if (Keyboard[Key.L])
            {
                float shiftX = BokehLab.Math.MathHelper.Clamp(Camera.LensShift.X + 0.01f, -Camera.Lens.ApertureRadius, Camera.Lens.ApertureRadius);
                Camera.LensShift = new Vector2(shiftX, Camera.LensShift.Y);
                IsViewDirty      = true;
            }
            else if (Keyboard[Key.J])
            {
                float shiftX = BokehLab.Math.MathHelper.Clamp(Camera.LensShift.X - 0.01f, -Camera.Lens.ApertureRadius, Camera.Lens.ApertureRadius);
                Camera.LensShift = new Vector2(shiftX, Camera.LensShift.Y);
                IsViewDirty      = true;
            }

            // sensor tilt
            if (Keyboard[Key.X])
            {
                float rotX = BokehLab.Math.MathHelper.Clamp(Camera.SensorRotation.X + 0.01f, -MaxSensorTiltAngle, MaxSensorTiltAngle);
                Camera.SensorRotation = new Vector2(rotX, Camera.SensorRotation.Y);
                IsViewDirty           = true;
                perspectiveChanged    = true;
            }
            else if (Keyboard[Key.Z])
            {
                float rotX = BokehLab.Math.MathHelper.Clamp(Camera.SensorRotation.X - 0.01f, -MaxSensorTiltAngle, MaxSensorTiltAngle);
                Camera.SensorRotation = new Vector2(rotX, Camera.SensorRotation.Y);
                IsViewDirty           = true;
                perspectiveChanged    = true;
            }
            if (Keyboard[Key.V])
            {
                float rotY = BokehLab.Math.MathHelper.Clamp(Camera.SensorRotation.Y + 0.01f, -MaxSensorTiltAngle, MaxSensorTiltAngle);
                Camera.SensorRotation = new Vector2(Camera.SensorRotation.X, rotY);
                IsViewDirty           = true;
                perspectiveChanged    = true;
            }
            else if (Keyboard[Key.C])
            {
                float rotY = BokehLab.Math.MathHelper.Clamp(Camera.SensorRotation.Y - 0.01f, -MaxSensorTiltAngle, MaxSensorTiltAngle);
                Camera.SensorRotation = new Vector2(Camera.SensorRotation.X, rotY);
                IsViewDirty           = true;
                perspectiveChanged    = true;
            }

            // sensor shift
            if (Keyboard[Key.N])
            {
                float shiftX = Camera.SensorShift2.X + 0.01f * Camera.SensorSize.X;
                Camera.SensorShift2 = new Vector2(shiftX, Camera.SensorShift2.Y);
                IsViewDirty         = true;
                perspectiveChanged  = true;
            }
            else if (Keyboard[Key.B])
            {
                float shiftX = Camera.SensorShift2.X - 0.01f * Camera.SensorSize.X;
                Camera.SensorShift2 = new Vector2(shiftX, Camera.SensorShift2.Y);
                IsViewDirty         = true;
                perspectiveChanged  = true;
            }
            if (Keyboard[Key.Comma])
            {
                float shiftY = Camera.SensorShift2.Y + 0.01f * Camera.SensorSize.Y;
                Camera.SensorShift2 = new Vector2(Camera.SensorShift2.X, shiftY);
                IsViewDirty         = true;
                perspectiveChanged  = true;
            }
            else if (Keyboard[Key.M])
            {
                float shiftY = Camera.SensorShift2.Y - 0.01f * Camera.SensorSize.Y;
                Camera.SensorShift2 = new Vector2(Camera.SensorShift2.X, shiftY);
                IsViewDirty         = true;
                perspectiveChanged  = true;
            }

            if (perspectiveChanged)
            {
                Camera.UpdatePerspective();
                Matrix4 perspective = Camera.Perspective;

                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref perspective);
                IsViewDirty = true;
            }
        }