Пример #1
0
        /// <summary>
        /// Triggers the key event callback functions programatically with the given byte data
        /// array. Use the GetNetworkData(KeyboardEventType, Keys, KeyModifier) function to convert
        /// each of the keyboard events and the necessary information (e.g., key) to a byte array.
        /// </summary>
        /// <see cref="GetNetworkData(KeyboardEventType, Keys, KeyModifier)"/>
        /// <param name="data">An array of bytes containing specific data used to trigger
        /// the key event callback functions</param>
        public void TriggerDelegates(byte[] data)
        {
            byte        type     = data[0];
            Keys        key      = (Keys)data[1];
            KeyModifier modifier = new KeyModifier();

            modifier.AltKeyPressed   = BitConverter.ToBoolean(data, 2);
            modifier.CtrlKeyPressed  = BitConverter.ToBoolean(data, 3);
            modifier.ShiftKeyPressed = BitConverter.ToBoolean(data, 4);

            switch (type)
            {
            case (byte)KeyboardEventType.Press:
                if (KeyPressEvent != null)
                {
                    KeyPressEvent(key, modifier);
                }
                break;

            case (byte)KeyboardEventType.Release:
                if (KeyReleaseEvent != null)
                {
                    KeyReleaseEvent(key, modifier);
                }
                break;

            case (byte)KeyboardEventType.Type:
                if (KeyTypeEvent != null)
                {
                    KeyTypeEvent(key, modifier);
                }
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Converts the keyboard event type, the key, and the modifier keys' information
        /// to an array of bytes so that it can be sent over the network.
        /// </summary>
        /// <param name="type">Press, Release, or Type</param>
        /// <param name="key">The key</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier
        /// keys are held down</param>
        /// <returns></returns>
        public byte[] GetNetworkData(KeyboardEventType type, Keys key, KeyModifier modifier)
        {
            // 1 byte for type, 1 byte for key, and 1 (bool) * 3 bytes for modifier
            byte[] data = new byte[5];

            data[0] = (byte)type;
            data[1] = (byte)key;
            data[2] = BitConverter.GetBytes(modifier.AltKeyPressed)[0];
            data[3] = BitConverter.GetBytes(modifier.CtrlKeyPressed)[0];
            data[4] = BitConverter.GetBytes(modifier.ShiftKeyPressed)[0];

            return(data);
        }
Пример #3
0
        public static KeyModifier GetKeyModifier(List <Keys> keys)
        {
            KeyModifier modifier = new KeyModifier();

            if (keys.Contains(Keys.RightShift) || keys.Contains(Keys.LeftShift))
            {
                modifier.ShiftKeyPressed = true;
            }
            if (keys.Contains(Keys.RightAlt) || keys.Contains(Keys.LeftAlt))
            {
                modifier.AltKeyPressed = true;
            }
            if (keys.Contains(Keys.RightControl) || keys.Contains(Keys.LeftControl))
            {
                modifier.CtrlKeyPressed = true;
            }

            return(modifier);
        }
Пример #4
0
        void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            String cameraName = "";
            if (key == Keys.N)
                cameraName = "NearCamera";
            else if (key == Keys.F)
                cameraName = "FarCamera";
            else if (key == Keys.C)
                cameraName = "ChasingCamera";

            if (!cameraName.Equals(""))
            {
                CameraNode cam = (CameraNode)scene.GetNode(cameraName);

                // Set the selected camera to be our active camera
                scene.CameraNode = cam;
            }
        }
Пример #5
0
 private void Instance_KeyPressEvent(Keys key, KeyModifier modifier)
 {
     if (key == Keys.Escape)
         this.Exit();
 }
Пример #6
0
        /// <summary>
        /// Implements how a key release event should be handled. 
        /// </summary>
        /// <param name="key">The key released</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier keys 
        /// (e.g., Shift, Alt, or Ctrl) are pressed</param>
        protected virtual void HandleKeyRelease(Keys key, KeyModifier modifier)
        {
            if (!focused || !enabled || !visible)
                return;

            if(KeyReleasedEvent != null)
                KeyReleasedEvent(key, modifier);

            keyDown = false;
        }
Пример #7
0
 public void Instance_KeyPress(Keys key, KeyModifier target)
 {
     if (Keys.Z == key)
     {
         if(baseClass.staticCamera.FieldOfViewY < MathHelper.ToRadians(180))
             baseClass.staticCamera.FieldOfViewY = baseClass.staticCamera.FieldOfViewY + (float)0.01;
         else
             baseClass.staticCamera.FieldOfViewY = MathHelper.ToRadians(45);
     }
     if (Keys.X == key)
     {
         if (baseClass.staticCamera.FieldOfViewY > 0)
             baseClass.staticCamera.FieldOfViewY = baseClass.staticCamera.FieldOfViewY - (float)0.01;
         else
             baseClass.staticCamera.FieldOfViewY = MathHelper.ToRadians(45);
     }
 }
Пример #8
0
 protected override void HandleKeyPress(Keys key, KeyModifier modifier)
 {
     if (focused && editable && enabled && visible)
     {
         base.HandleKeyPress(key, modifier);
         UpdateText(key, modifier);
         UpdateCaret(key, modifier);
     }
 }
Пример #9
0
        private void KeyPressHandler(Keys keys, KeyModifier modifier)
        {
            if (keys == Keys.OemMinus)
            {
                currentInterpolation = 0;
                textToPrint = "Linear interpolation";
            }

            if (keys == Keys.D1)
            {
                currentInterpolation = 1;
                textToPrint = "Quadratic interpolation";
            }

            if (keys == Keys.D2)
            {
                currentInterpolation = 2;
                textToPrint = "Cubic interpolation";
            }

            if (keys == Keys.D3)
            {
                currentInterpolation = 3;
                textToPrint = "Quartic interpolation";

            }

            if (keys == Keys.D4)
            {
                currentInterpolation = 4;
                textToPrint = "Quintic interpolation";
            }

            if (keys == Keys.D5)
            {
                currentInterpolation = 5;
                textToPrint = "Sinusoidal interpolation";
            }

            if (keys == Keys.D6)
            {
                currentInterpolation = 6;
                textToPrint = "Exponential interpolation";
            }

            if (keys == Keys.D7)
            {
                currentInterpolation = 7;
                textToPrint = "Circular interpolation";
            }

            if (keys == Keys.D8)
            {
                currentInterpolation = 8;
                textToPrint = "Elastic interpolation";
            }

            if (keys == Keys.D9)
            {
                currentInterpolation = 9;
                textToPrint = "Back interpolation";
            }

            if (keys == Keys.D0)
            {
                currentInterpolation = 10;
                textToPrint = "Bounce interpolation";
            }

            if (keys == Keys.Q)
            {
                currentEasing = 0;
                textToPrint = "Ease in";
            }

            if (keys == Keys.W)
            {
                currentEasing = 1;
                textToPrint = "Ease out";
            }

            if (keys == Keys.E)
            {
                currentEasing = 2;
                textToPrint = "Ease in and out";
            }

            //Play the animation
            if (keys == Keys.Space)
            {

                shipTransParentNode.Rotation = Quaternion.CreateFromYawPitchRoll(0,0,0);

                animationTranslation.CurrentEasing = arrayOfEasing[currentEasing];
                animationTranslation.Animate(arrayOfTransitions[currentInterpolation], endPosition, startPosition, 2);

                animationTranslation.SetEndAction(delegate()
                {
                    animationRotation.CurrentEasing = arrayOfEasing[currentEasing];
                    animationRotation.Animate(arrayOfTransitions[currentInterpolation], startRotationVector, endRotationVector, 2.0);
                });

                //Switch all the values.
                Vector3 temp; Vector3 tempRotation;
                temp = endPosition;
                tempRotation = endRotationVector;

                endPosition = startPosition;
                endRotationVector = startRotationVector;

                startPosition = temp;
                startRotationVector = tempRotation;
            }

            if (keys == Keys.Escape)
            {
                Exit();
            }
        }
Пример #10
0
 /// <summary>
 /// Handle the key input to change the light direction
 /// </summary>
 /// <param name="key"></param>
 /// <param name="modifier"></param>
 private void KeyTypeHandler(Keys key, KeyModifier modifier)
 {
     if (key == Keys.A && lightSource.Direction.X < 1)
         lightSource.Direction = new Vector3(lightSource.Direction.X + 0.1f, 
             lightSource.Direction.Y, lightSource.Direction.Z);
     else if (key == Keys.Z && lightSource.Direction.X > -1)
         lightSource.Direction = new Vector3(lightSource.Direction.X - 0.1f,
             lightSource.Direction.Y, lightSource.Direction.Z);
     else if (key == Keys.S && lightSource.Direction.Y < 1)
         lightSource.Direction = new Vector3(lightSource.Direction.X,
             lightSource.Direction.Y + 0.1f, lightSource.Direction.Z);
     else if (key == Keys.X && lightSource.Direction.Y > -1)
         lightSource.Direction = new Vector3(lightSource.Direction.X,
             lightSource.Direction.Y - 0.1f, lightSource.Direction.Z);
     else if (key == Keys.D && lightSource.Direction.Z < 1)
         lightSource.Direction = new Vector3(lightSource.Direction.X,
             lightSource.Direction.Y, lightSource.Direction.Z + 0.1f);
     else if (key == Keys.C && lightSource.Direction.Z > -1)
         lightSource.Direction = new Vector3(lightSource.Direction.X,
             lightSource.Direction.Y, lightSource.Direction.Z - 0.1f);
 }
Пример #11
0
        private void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            if ((key == Keys.Escape) && finalized)
                this.Exit();

            if ((key == Keys.Enter || key == Keys.Space) && useImageSequence && !finalized)
            {
                calibrateNextSequence = true;
            }
        }
Пример #12
0
        private void HandleKeyPressEvent(Keys key, KeyModifier modifier)
        {
            // This is somewhat necessary to exit from full screen mode
            if (key == Keys.Escape)
                this.Exit();

            if(!finalized)
            {
                if (key == Keys.Space)
                {
                    if (!calibrating)
                    {
                        calibrationThread = new Thread(CalibrateStereo);
                        calibrationThread.Start();
                    }
                }
            }
            else
            {
                switch (key)
                {
                    case Keys.Space:
                        SaveAdjustments();
                        break;
                    case Keys.Down:
                        if (adjustingLeft)
                        {
                            camWidthAdjustmentLeft++;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camWidthAdjustmentRight++;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.Up:
                        if (adjustingLeft)
                        {
                            camWidthAdjustmentLeft--;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camWidthAdjustmentRight--;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.Right:
                        if (adjustingLeft)
                        {
                            camHShiftAdjustmentLeft--;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camHShiftAdjustmentRight--;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.Left:
                        if (adjustingLeft)
                        {
                            camHShiftAdjustmentLeft++;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camHShiftAdjustmentRight++;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.PageUp:
                        if (adjustingLeft)
                        {
                            camVShiftAdjustmentLeft--;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camVShiftAdjustmentRight--;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.PageDown:
                        if (adjustingLeft)
                        {
                            camVShiftAdjustmentLeft++;
                            int camHeightAdjustment = camWidthAdjustmentLeft * stereoHeight / stereoWidth;

                            leftSource = new Rectangle(camWidthAdjustmentLeft + camHShiftAdjustmentLeft,
                                camHeightAdjustment + camVShiftAdjustmentLeft,
                                stereoWidth - camWidthAdjustmentLeft * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        else
                        {
                            camVShiftAdjustmentRight++;
                            int camHeightAdjustment = camWidthAdjustmentRight * stereoHeight / stereoWidth;

                            rightSource = new Rectangle(camWidthAdjustmentRight + camHShiftAdjustmentRight,
                                camHeightAdjustment + camVShiftAdjustmentRight,
                                stereoWidth - camWidthAdjustmentRight * 2, stereoHeight - camHeightAdjustment * 2);
                        }
                        break;
                    case Keys.Enter:
                        adjustingLeft = !adjustingLeft;
                        break;
                }
            }
        }
        void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            if (key == Keys.Escape)
                this.Exit();
            if (key == Keys.R)
            {
                resetFlag = true;
                ((Model)humvee.Model).ShowBoundingBox = false;
                ((Model)gears.Model).ShowBoundingBox = false;
                ((Model)cup.Model).ShowBoundingBox = false;
                ((Model)g36c.Model).ShowBoundingBox = false;
                label = "Nothing is selected";
                objectFrame.Visible = false;
                rotationFlag = false;
                slider.Value = 0;
                rotationSpeed = 0;

                humveeX = 0;
                humveeY = 0;
                humveeZ = 0;
                gearsX = 0;
                gearsY = 0;
                gearsZ = 0;
                cupX = 0;
                cupY = 0;
                cupZ = 0;
                g36cX = 0;
                g36cY = 0;
                g36cZ = 0;

                // Get the dimension of the model.
                Vector3 dimension1 = Vector3Helper.GetDimensions(humvee.Model.MinimumBoundingBox);
                // Scale the model to fit to the size of 5 markers.
                float scale1 = markerSize * (float)1.5 / Math.Max(dimension1.X, dimension1.Z);
                // Transformation node of the humvee model.
                humveeSize = scale1;
                humveeTrans = Matrix.CreateTranslation(0, 30, 0);
                humveeRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(0));
                humveeMatrix = Matrix.Identity;

                // Get the dimension of the model.
                Vector3 dimension2 = Vector3Helper.GetDimensions(gears.Model.MinimumBoundingBox);
                // Scale the model to fit to the size of 5 markers.
                float scale2 = markerSize / Math.Max(dimension2.X, dimension2.Z);
                // Transformation node of the gears model.
                gearsSize = scale2;
                gearsTrans = Matrix.CreateTranslation(0, 110, 0);
                gearsRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(60));
                gearsMatrix = Matrix.Identity;

                // Get the dimension of the model.
                Vector3 dimension3 = Vector3Helper.GetDimensions(cup.Model.MinimumBoundingBox);
                // Scale the model to fit to the size of 5 markers.
                float scale3 = markerSize / Math.Max(dimension3.X, dimension3.Z);
                cupSize = scale3;
                cupTrans = Matrix.CreateTranslation(60, 60, 0);
                cupRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(0));
                cupMatrix = Matrix.Identity;

                // Get the dimension of the model.
                Vector3 dimension4 = Vector3Helper.GetDimensions(g36c.Model.MinimumBoundingBox);
                // Scale the model to fit to the size of 5 markers.
                float scale4 = markerSize * 2 / Math.Max(dimension4.X, dimension4.Z);
                g36cSize = scale4;
                g36cTrans = Matrix.CreateTranslation(-60, 80, 0);
                g36cRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(0));
                g36cMatrix = Matrix.Identity;

                if (translationModeFlag == true)
                    translationModeFlag = false;
                if (transferFlag == true)
                    transferFlag = false;
                if (rotationObjectFlag == true)
                    rotationObjectFlag = false;
                if (panelTrigger == true)
                    panelTrigger = false;
                if (scaleFlag == true)
                    scaleFlag = false;

                if (humveeflag == true)
                {
                    toolbarMarkerNode.RemoveChild(humvee);
                    groundMarkerNode.AddChild(humvee);
                    humveeflag = false;
                }
                if (gearsflag == true)
                {
                    toolbarMarkerNode.RemoveChild(gears);
                    groundMarkerNode.AddChild(gears);
                    gearsflag = false;
                }
                if (cupflag == true)
                {
                    toolbarMarkerNode.RemoveChild(cup);
                    groundMarkerNode.AddChild(cup);
                    cupflag = false;
                }
                if (g36cflag == true)
                {
                    toolbarMarkerNode.RemoveChild(g36c);
                    groundMarkerNode.AddChild(g36c);
                    g36cflag = false;
                }
            }
            if (key == Keys.Q)
            {
                ((Model)humvee.Model).ShowBoundingBox = false;
                ((Model)gears.Model).ShowBoundingBox = false;
                ((Model)cup.Model).ShowBoundingBox = false;
                ((Model)g36c.Model).ShowBoundingBox = false;
                label = "Nothing is selected";
                objectFrame.Visible = false;
                rotationFlag = false;
                slider.Value = 0;
                rotationSpeed = 0;
                if (translationModeFlag == true)
                    translationModeFlag = false;
                if (transferFlag == true)
                    transferFlag = false;
                if (rotationObjectFlag == true)
                    rotationObjectFlag = false;
                if (panelTrigger == true)
                    panelTrigger = false;
                if (scaleFlag == true)
                    scaleFlag = false;
                resetFlag = false;
                UI2DRenderer.WriteText(Vector2.Zero, "", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            if (key == Keys.Up)
            {
                if(label == "Humvee")
                    humveeSize += (float) 0.02;
                if (label == "Gears")
                    gearsSize += (float)0.04;
                if (label == "Cup")
                    cupSize += (float)0.02;
                if (label == "G36C Gun")
                    g36cSize += (float)0.02;
            }
            if (key == Keys.Down)
            {
                if (label == "Humvee")
                    humveeSize -= (float)0.02;
                if (label == "Gears")
                    gearsSize -= (float)0.04;
                if (label == "Cup")
                    cupSize -= (float)0.02;
                if (label == "G36C Gun")
                    g36cSize -= (float)0.02;
            }
            if (key == Keys.T)
            {
                if (label != "Nothing is selected")
                {
                    resetFlag = false;
                    translationModeFlag = true;
                    objectFrame.Visible = false;
                    if (transferFlag == true)
                        transferFlag = false;
                    if (rotationObjectFlag == true)
                        rotationObjectFlag = false;
                    if (panelTrigger == true)
                        panelTrigger = false;
                    if (scaleFlag == true)
                        scaleFlag = false;
                }
                else
                    UI2DRenderer.WriteText(Vector2.Zero, "Please select an object", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            if (key == Keys.M)
            {
                if (label != "Nothing is selected")
                {
                    resetFlag = false;
                    transferFlag = true;
                    objectFrame.Visible = false;
                    if (translationModeFlag == true)
                        translationModeFlag = false;
                    if (rotationObjectFlag == true)
                        rotationObjectFlag = false;
                    if (panelTrigger == true)
                        panelTrigger = false;
                    if (scaleFlag == true)
                        scaleFlag = false;
                }
                else
                    UI2DRenderer.WriteText(Vector2.Zero, "Please select an object", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            if (key == Keys.C)
            {
                if (label != "Nothing is selected")
                {
                    resetFlag = false;
                    rotationObjectFlag = true;
                    objectFrame.Visible = false;
                    if (translationModeFlag == true)
                        translationModeFlag = false;
                    if (transferFlag == true)
                        transferFlag = false;
                    if (panelTrigger == true)
                        panelTrigger = false;
                    if (scaleFlag == true)
                        scaleFlag = false;
                }
                else
                    UI2DRenderer.WriteText(Vector2.Zero, "Please select an object", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            if (key == Keys.S)
            {
                if (label != "Nothing is selected")
                {
                    resetFlag = false;
                    scaleFlag = true;
                    objectFrame.Visible = false;
                    if (translationModeFlag == true)
                        translationModeFlag = false;
                    if (transferFlag == true)
                        transferFlag = false;
                    if (rotationObjectFlag == true)
                        rotationObjectFlag = false;
                    if (panelTrigger == true)
                        panelTrigger = false;
                }
                else
                    UI2DRenderer.WriteText(Vector2.Zero, "Please select an object", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            if (key == Keys.E)
            {
                if (label != "Nothing is selected")
                {
                    resetFlag = false;
                    panelTrigger = true;
                    if (translationModeFlag == true)
                        translationModeFlag = false;
                    if (transferFlag == true)
                        transferFlag = false;
                    if (rotationObjectFlag == true)
                        rotationObjectFlag = false;
                    if (scaleFlag == true)
                        scaleFlag = false;
                }
                else
                    UI2DRenderer.WriteText(Vector2.Zero, "Please select an object", Color.Red, textFont1, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
        }
Пример #14
0
        void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            if (key == Keys.Escape)
                this.Exit();
            //Quit button
            if (key == Keys.Q)
            {
                rotationMode = false;
                selectionMode = false;

                myPyramid.Material.Diffuse = new Vector4(myPyramid.Material.Diffuse.X, myPyramid.Material.Diffuse.Y, myPyramid.Material.Diffuse.Z, 0);
                UI2DRenderer.WriteText(Vector2.Zero, "", Color.Red, textFontLarge, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);
            }
            //Reset button
            if (key == Keys.R)
            {
                rotationMode = false;
                selectionMode = false;
                //Initialize rotation of Manhattan.
                manhattanRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(0));

                myPyramid.Material.Diffuse = new Vector4(myPyramid.Material.Diffuse.X, myPyramid.Material.Diffuse.Y, myPyramid.Material.Diffuse.Z, 0);
                UI2DRenderer.WriteText(Vector2.Zero, "", Color.Red, textFontLarge, GoblinEnums.HorizontalAlignment.Right, GoblinEnums.VerticalAlignment.Top);

                cameraX = 0;
                cameraY = 0;
                cameraZ = 200;

                cameraLocation = "None";
                uptown = false;
                midtownWest = false;
                midtownWest = false;
                downtown = false;
                cameraFly = false;
                cameraTrans.Translation = new Vector3(0, 0, 0);

                modelEDUdisplay= false;
                modelHOUdisplay = false;
                modelDEMdisplay = false;
                modelEMPdisplay = false;
            }
            //Activate rotation mode.
            if (key == Keys.C)
            {
                rotationMode = true;
            }
            //Activate selection mode.
            if (key == Keys.P)
            {
                selectionMode = true;
            }
            //Move the camera up when press the "Up" key.
            if (key == Keys.Up)
                cameraY += (float)5;
            //Move the camera down when press the "Down" key.
            if (key == Keys.Down)
                cameraY -= (float)5;
            //Move the camera left when press the "Left" key.
            if (key == Keys.Left)
                cameraX -= (float)5;
            //Move the camera right when press the "Right" key.
            if (key == Keys.Right)
                cameraX += (float)5;
            //Move the camera in when press the "I" key.
            if (key == Keys.OemPlus)
                cameraZ -= (float)5;
            //Move the camera out when press the "O" key.
            if (key == Keys.OemMinus)
                cameraZ += (float)5;

            //Display Education Block.
            if (key == Keys.D1)
            {
                modelHOUdisplay = false;
                modelDEMdisplay = false;
                modelEMPdisplay = false;

                modelEDUdisplay= true;
            }
            //Display Employment Block.
            if (key == Keys.D2)
            {
                modelEDUdisplay= false;
                modelHOUdisplay = false;
                modelDEMdisplay = false;

                modelEMPdisplay = true;
            }
            //Display Demographic Block.
            if (key == Keys.D3)
            {
                modelEMPdisplay = false;
                modelEDUdisplay= false;
                modelHOUdisplay = false;

                modelDEMdisplay = true;
            }
            //Display Housing Block.
            if (key == Keys.D4)
            {
                modelDEMdisplay = false;
                modelEMPdisplay = false;
                modelEDUdisplay= false;

                modelHOUdisplay = true;
            }
        }
Пример #15
0
        protected override void HandleKeyRelease(Keys key, KeyModifier modifier)
        {
            base.HandleKeyRelease(key, modifier);

            if (clickKeyPressed)
            {
                DoClick();
                clickKeyPressed = false;
            }
        }
Пример #16
0
        protected override void HandleKeyPress(Keys key, KeyModifier modifier)
        {
            base.HandleKeyPress(key, modifier);

            if (focused && enabled && visible && (key == clickKey))
                clickKeyPressed = true;
        }
Пример #17
0
        private void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            if (key == Keys.Escape)
                this.Exit();

            if (key == Keys.S)
            {
                scene.EnableShadowMapping = !scene.EnableShadowMapping;
            }
            if (key == Keys.C)
            {
                if (gameState.CurrentGameMode == GameState.GameMode.Play)
                {
                    shootCenterMode = !shootCenterMode;
                    if (shootCenterMode)
                        uiManager.CrossHairPoint = new Point(State.Width / 2, State.Height / 2);
                }
            }

            if (key == Keys.G)
            {
                showGUI = !showGUI;
                if (showGUI)
                {
                    uiManager.Frame.Visible = true;
                    uiManager.Frame.Enabled = true;
                    uiManager.ModeChoiceEnabled = false;
                }
                else
                {
                    uiManager.Frame.Visible = false;
                    uiManager.Frame.Enabled = false;
                }
            }
            else if (key == Keys.P)
                uiManager.GamePlay.DoClick();
            else if (key == Keys.A)
                uiManager.GameAdd.DoClick();
            else if (key == Keys.E)
                uiManager.GameEdit.DoClick();
            else if (key == Keys.R)
                ResetGame();
            else if (key == Keys.H)
                uiManager.EnableHelpMenu = !uiManager.EnableHelpMenu;

            if (gameState.CurrentGameMode == GameState.GameMode.Add)
            {
                if (key == Keys.Right)
                    rightKeyPressed = true;
                if (key == Keys.Left)
                    leftKeyPressed = true;
            }
            else if (gameState.CurrentGameMode == GameState.GameMode.Edit)
            {
                if (key == Keys.Right)
                    rightKeyPressed = true;
                if (key == Keys.Left)
                    leftKeyPressed = true;

                if (key == Keys.D || key == Keys.Delete)
                {
                    foreach (GeometryNode domino in selectedDominos)
                    {
                        dominos.Remove(domino);
                        ((TransformNode)domino.Parent).RemoveChild(domino);
                    }

                    selectedDominos.Clear();
                }
            }
            else
            {
                if (key == Keys.Up || key == Keys.Right)
                    if (volume < MAX_VOLUME)
                        volume += 0.5f;
                if (key == Keys.Down || key == Keys.Left)
                    if (volume > 1)
                        volume -= 0.5f;
            }
        }
Пример #18
0
        private void KeyPressHandler(Keys keys, KeyModifier modifier)
        {
            // Detect key press "a"
            if (keys == Keys.A)
            {

            }
            if (keys == Keys.R)
            {
                isFineRotation = !isFineRotation;
            }
            if (keys == Keys.Delete || keys == Keys.Back)
            {
                if (actionState != STATES.MANIPULATING)
                {
                    deleteIsActive = false;
                    return;
                }

                if (deleteIsActive)
                {

                    if (actionState == STATES.MANIPULATING)
                    {
                        selectedItem.Unbind();
                        setState(STATES.SELECTING);
                    }
                    deleteIsActive = false;
                }
                else
                {
                    deleteIsActive = true;
                }

                showCursor = !deleteIsActive;
                showModal = deleteIsActive;
            }
            if (keys == Keys.Escape)
            {
                deleteIsActive = false;
                showCursor = !deleteIsActive;
                showModal = deleteIsActive;
            }
        }
Пример #19
0
 protected override void UpdateCaret(Keys key, KeyModifier modifier)
 {
     UpdateCaretPosition();
 }
Пример #20
0
 private void HandleKeyPressEvent(Keys key, KeyModifier modifier)
 {
     // This is somewhat necessary to exit from full screen mode
     if (key == Keys.Escape)
         this.Exit();
 }
Пример #21
0
        protected override void UpdateText(Keys key, KeyModifier modifier)
        {
            if (textFont == null)
                return;

            switch (key)
            {
                case Keys.Back:
                case Keys.Delete:
                    if (label.Length > 0)
                        Text = label.Substring(0, label.Length - 1);
                    break;
                case Keys.Enter:
                    break;
                default:
                    bool handle = true;
                    if (columns > 0)
                    {
                        if (label.Length >= columns)
                            handle = false;
                    }
                    else
                        if (textWidth >= (bounds.Width - 8))
                            handle = false;
                    
                    if(handle)
                        Text += "" + KeyboardInput.KeyToChar(key, modifier.ShiftKeyPressed);
                    break;
            }

            if(Text.Length != 0)
                textHeight = (int)textFont.MeasureString(Text).Y;
        }
Пример #22
0
        private void HandleKeyPressEvent(Keys key, KeyModifier modifier)
        {
            // This is somewhat necessary to exit from full screen mode
            if (key == Keys.Escape)
                this.Exit();

            if (key == Keys.Enter)
            {
                if (scene.RightEyeVideoID == 2)
                    scene.RightEyeVideoID = 1;
                else
                    scene.RightEyeVideoID = 2;
            }
        }
Пример #23
0
        public void Update(TimeSpan elapsedTime, bool deviceActive)
        {
            // If the window is not on focus (only for the case of windowed version)
            // then we don't need to process the keyboard events
            if (onlyTrackWhenFocused && !deviceActive)
            {
                return;
            }

            // Update the current keyboard state
            keyboardState = Keyboard.GetState();
            keysBeingPressed.Clear();
            keysBeingPressed.AddRange(keyboardState.GetPressedKeys());
            // First remove weird keys being pressed without doing anything
            keysBeingPressed.Remove(Keys.Attn);
            keysBeingPressed.Remove(Keys.Zoom);
            KeyModifier modifier = GetKeyModifier(keysBeingPressed);

            // First handle repetition press that is handled as key type action
            if (currentPressedKeys.Count > 0)
            {
                KeyJustPressed keyPressed = currentPressedKeys[currentPressedKeys.Count - 1];

                if (keysPressedLastFrame.Contains(keyPressed.Key))
                {
                    repetitionTime += (int)elapsedTime.TotalMilliseconds;
                    bool processTypeEvent = false;

                    if (keyPressed.JustPressed)
                    {
                        if (repetitionTime >= initialRepetitionWait)
                        {
                            processTypeEvent       = true;
                            repetitionTime         = 0;
                            keyPressed.JustPressed = false;
                        }
                    }
                    else
                    {
                        if (repetitionTime >= repetitionWait)
                        {
                            processTypeEvent = true;
                            repetitionTime   = 0;
                        }
                    }

                    if (processTypeEvent && (KeyTypeEvent != null))
                    {
                        KeyTypeEvent(keyPressed.Key, modifier);
                    }
                }
            }

            // HANDLE KEY RELEASE AND TYPE
            foreach (KeyJustPressed key in currentPressedKeys)
            {
                if (keysPressedLastFrame.Contains(key.Key) &&
                    !keysBeingPressed.Contains(key.Key))
                {
                    if (KeyReleaseEvent != null)
                    {
                        KeyReleaseEvent(key.Key, modifier);
                    }

                    if (KeyTypeEvent != null)
                    {
                        KeyTypeEvent(key.Key, modifier);
                    }

                    releasedKeys.Add(key);
                    releasedKeyList.Add(key.Key);
                }
            }

            foreach (KeyJustPressed key in releasedKeys)
            {
                currentPressedKeys.Remove(key);
            }
            releasedKeys.Clear();

            // HANDLE KEY PRESS
            foreach (Keys key in keysBeingPressed)
            {
                if (!releasedKeyList.Contains(key) && !keysPressedLastFrame.Contains(key) &&
                    !IsKeyModifier(key))
                {
                    currentPressedKeys.Add(new KeyJustPressed(key));

                    if (KeyPressEvent != null)
                    {
                        KeyPressEvent(key, modifier);
                    }
                }
            }

            releasedKeyList.Clear();

            keysPressedLastFrame.Clear();
            keysPressedLastFrame.AddRange(keysBeingPressed);
        }
Пример #24
0
 /// <summary>
 /// Updates the text when there is a keyboard input.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="modifier"></param>
 abstract protected void UpdateText(Keys key, KeyModifier modifier);
Пример #25
0
        public static KeyModifier GetKeyModifier(List<Keys> keys)
        {
            KeyModifier modifier = new KeyModifier();

            if (keys.Contains(Keys.RightShift) || keys.Contains(Keys.LeftShift))
                modifier.ShiftKeyPressed = true;
            if (keys.Contains(Keys.RightAlt) || keys.Contains(Keys.LeftAlt))
                modifier.AltKeyPressed = true;
            if (keys.Contains(Keys.RightControl) || keys.Contains(Keys.LeftControl))
                modifier.CtrlKeyPressed = true;

            return modifier;
        }
Пример #26
0
        /// <summary>
        /// Implements how a key typed event should be handled. 
        /// </summary>
        /// <param name="key">The key typed</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier keys 
        /// (e.g., Shift, Alt, or Ctrl) are pressed</param>
        protected virtual void HandleKeyType(Keys key, KeyModifier modifier)
        {
            if (!focused || !enabled || !visible)
                return;

            if(KeyTypedEvent != null)
                KeyTypedEvent(key, modifier);
        }
Пример #27
0
        /// <summary>
        /// Converts the keyboard event type, the key, and the modifier keys' information 
        /// to an array of bytes so that it can be sent over the network.
        /// </summary>
        /// <param name="type">Press, Release, or Type</param>
        /// <param name="key">The key</param>
        /// <param name="modifier">A struct that indicates whether any of the modifier 
        /// keys are held down</param>
        /// <returns></returns>
        public byte[] GetNetworkData(KeyboardEventType type, Keys key, KeyModifier modifier)
        {
            // 1 byte for type, 1 byte for key, and 1 (bool) * 3 bytes for modifier
            byte[] data = new byte[5];

            data[0] = (byte)type;
            data[1] = (byte)key;
            data[2] = BitConverter.GetBytes(modifier.AltKeyPressed)[0];
            data[3] = BitConverter.GetBytes(modifier.CtrlKeyPressed)[0];
            data[4] = BitConverter.GetBytes(modifier.ShiftKeyPressed)[0];

            return data;
        }
Пример #28
0
 /// <summary>
 /// Invokes the key type event.
 /// </summary>
 /// <param name="key">The key typed.</param>
 /// <param name="modifier"></param>
 protected void InvokeKeyTypedEvent(Keys key, KeyModifier modifier)
 {
     if (KeyTypedEvent != null)
         KeyTypedEvent(key, modifier);
 }
Пример #29
0
 protected override void UpdateText(Keys key, KeyModifier modifier)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #30
0
        /// <summary>
        /// Triggers the key event callback functions programatically with the given byte data
        /// array. Use the GetNetworkData(KeyboardEventType, Keys, KeyModifier) function to convert 
        /// each of the keyboard events and the necessary information (e.g., key) to a byte array.
        /// </summary>
        /// <see cref="GetNetworkData(KeyboardEventType, Keys, KeyModifier)"/>
        /// <param name="data">An array of bytes containing specific data used to trigger
        /// the key event callback functions</param>
        public void TriggerDelegates(byte[] data)
        {
            byte type = data[0];
            Keys key = (Keys)data[1];
            KeyModifier modifier = new KeyModifier();
            modifier.AltKeyPressed = BitConverter.ToBoolean(data, 2);
            modifier.CtrlKeyPressed = BitConverter.ToBoolean(data, 3);
            modifier.ShiftKeyPressed = BitConverter.ToBoolean(data, 4);

            switch (type)
            {
                case (byte)KeyboardEventType.Press:
                    if(KeyPressEvent != null)
                        KeyPressEvent(key, modifier);
                    break;
                case (byte)KeyboardEventType.Release:
                    if(KeyReleaseEvent != null)
                        KeyReleaseEvent(key, modifier);
                    break;
                case (byte)KeyboardEventType.Type:
                    if(KeyTypeEvent != null)
                        KeyTypeEvent(key, modifier);
                    break;
            }
        }
Пример #31
0
 private void KeyReleaseHandler(Keys key, KeyModifier modifier)
 {
     if (gameState.CurrentGameMode != GameState.GameMode.Play)
     {
         if (key == Keys.Right)
             rightKeyPressed = false;
         if (key == Keys.Left)
             leftKeyPressed = false;
     }
 }
Пример #32
0
        private void KeyPressHandler(Keys keys, KeyModifier modifier)
        {
            if (keys == Keys.Enter)
            {
                sendResponse(response);
                textF.Clear();
                response = "";
            }
            else
            {
                Boolean ignore = false;

                if (keys == Keys.Left) ignore = true;
                if (keys == Keys.Right) ignore = true;
                if (keys == Keys.Space) ignore = true;
                if (ignore) return;

                if (keys == Keys.Back)
                {
                    int i = response.Length;
                    if (i > 0)
                    {
                        response = response.Substring(0, i - 1);
                        textF.Text = response;
                        return;
                    }
                }
                String nr = keys.ToString();

                if (keys == Keys.D1) nr = "1";
                if (keys == Keys.D2) nr = "2";
                if (keys == Keys.D3) nr = "3";
                if (keys == Keys.D4) nr = "4";
                if (keys == Keys.D5) nr = "5";
                if (keys == Keys.D6) nr = "6";
                if (keys == Keys.D7) nr = "7";
                if (keys == Keys.D8) nr = "8";
                if (keys == Keys.D9) nr = "9";
                if (keys == Keys.D0) nr = "10";

                if (keys == Keys.Space) nr = " ";
                nr = nr.ToUpper();
                char c = nr[0];
                if ((c >= '0') && (c <= 'Z'))
                {
                    response = response + nr;
                    textF.Text = response;
                }
            }
        }
Пример #33
0
        void KeyPressHandler(Keys key, KeyModifier modifier)
        {
            //Move the camera up when press the "Up" key.
            if (key == Keys.Up)
                cameraY += (float)0.05;
            //Move the camera down when press the "Down" key.
            if (key == Keys.Down)
                cameraY -= (float)0.05;
            //Move the camera left when press the "Left" key.
            if (key == Keys.Left)
                cameraX -= (float)0.05;
            //Move the camera right when press the "Right" key.
            if (key == Keys.Right)
                cameraX += (float)0.05;
            //Move the camera in when press the "I" key.
            if (key == Keys.I)
                cameraZ -= (float)0.05;
            //Move the camera out when press the "O" key.
            if (key == Keys.O)
                cameraZ += (float)0.05;
            //Increase the field of view when press the "A" key.
            if (key == Keys.A)
            {
                cameraFieldY += 1;
            }
            //Decrease the field of view when press the "S" key.
            if (key == Keys.S)
            {
                cameraFieldY -= 1;
            }
            // Return to the initial view of the solar system
            if (key == Keys.R)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                cameraFieldY = 60;
                cameraNode.Camera.View = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);

                slider.Value = 0;
                rotationSpeed = 0;
                dubrisEscape = false;

                earthControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                earthControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                earthControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                moonControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                moonControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                moonControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                mercuryControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                mercuryControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                mercuryControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                marsControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                marsControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                marsControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                jupiterControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                jupiterControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                jupiterControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                coneControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                coneControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                coneControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                coneControlPanel.Translation = Vector3.Zero;
                cylinderControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                cylinderControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                cylinderControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                cylinderControlPanel.Translation = Vector3.Zero;
                boxControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                boxControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                boxControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                boxControlPanel.Translation = Vector3.Zero;
                torusControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, 0);
                torusControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                torusControlPanel.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, 0);
                torusControlPanel.Translation = Vector3.Zero;

                earthRotateX = false;
                moonRotateX = false;
                mercuryRotateX = false;
                marsRotateX = false;
                jupiterRotateX = false;
                cylinderRotateX = false;
                coneRotateX = false;
                boxRotateX = false;
                torusRotateX = false;
                earthRotateY = false;
                moonRotateY = false;
                mercuryRotateY = false;
                marsRotateY = false;
                jupiterRotateY = false;
                cylinderRotateY = false;
                coneRotateY = false;
                boxRotateY = false;
                torusRotateY = false;
                earthRotateZ = false;
                moonRotateZ = false;
                mercuryRotateZ = false;
                marsRotateZ = false;
                jupiterRotateZ = false;
                cylinderRotateZ = false;
                coneRotateZ = false;
                boxRotateZ = false;
                torusRotateZ = false;
                valueX = 0;
                valueY = 0;
                valueZ = 0;

                earthRotationSpeed1 = 0;
                moonRotationSpeed1 = 0;
                marsRotationSpeed1 = 0;
                jupiterRotationSpeed1 = 0;
                mercuryRotationSpeed1 = 0;
                cylinderRotationSpeed1 = 0;
                coneRotationSpeed1 = 0;
                torusRotationSpeed1 = 0;
                boxRotationSpeed1 = 0;
                earthRotationSpeed2 = 0;
                moonRotationSpeed2 = 0;
                marsRotationSpeed2 = 0;
                jupiterRotationSpeed2 = 0;
                mercuryRotationSpeed2 = 0;
                cylinderRotationSpeed2 = 0;
                coneRotationSpeed2 = 0;
                torusRotationSpeed2 = 0;
                boxRotationSpeed2 = 0;
                earthRotationSpeed3 = 0;
                moonRotationSpeed3 = 0;
                marsRotationSpeed3 = 0;
                jupiterRotationSpeed3 = 0;
                mercuryRotationSpeed3 = 0;
                cylinderRotationSpeed3 = 0;
                coneRotationSpeed3 = 0;
                torusRotationSpeed3 = 0;
                boxRotationSpeed3 = 0;
            }
            //Attach the camera to the Sun.
            if (key == Keys.D1)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Move the camera along z axis for 1.5 unit.
                cameraNode.Camera.View = Matrix.CreateLookAt(new Vector3(0, 0, (float)1.5), Vector3.Zero, Vector3.Up);
            }
            //Attach the camera to the Earth.
            if (key == Keys.D2)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 1: Turn on transformations and rotations for the Earth.
                flag = 1;
            }
            //Attach the camera to the Mercury
            if (key == Keys.D3)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Mercury.
                flag = 2;
            }
            //Attach the camera to the Mars.
            if (key == Keys.D4)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 3: Turn on transformations and rotations for the Mars.
                flag = 3;
            }
            //Attach the camera to the Jupiter.
            if (key == Keys.D5)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Jupiter.
                flag = 4;
            }
            //Attach the camera to the Moon.
            if (key == Keys.D6)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Moon.
                flag = 5;
            }
            //Attach the camera to the cylinder.
            if (key == Keys.D7)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Moon.
                flag = 6;
            }
            //Attach the camera to the cone
            if (key == Keys.D8)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Moon.
                flag = 7;
            }
            //Attach the camera to the torus.
            if (key == Keys.D9)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Moon.
                flag = 8;
            }
            //Attach the camera to the box.
            if (key == Keys.D0)
            {
                // Initialize flag to 0. Turn off all transformations and rotations that applied to the camera.
                flag = 0;
                // Initialize camera nodes rotations and tranformations to default value.
                myCameraNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode1.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0);
                myCameraNode.Translation = Vector3.Zero;
                myCameraNode1.Translation = Vector3.Zero;
                myCameraNode2.Translation = Vector3.Zero;
                cameraX = 0;
                cameraY = 0;
                cameraZ = 0;
                // Set the flag to 2: Turn on transformations and rotations for the Moon.
                flag = 9;
            }
            if (key == Keys.Escape)
            {
                MouseInput.Instance.MouseClickEvent += new HandleMouseClick(MouseClickHandler);
                label = "Nothing is selected";
                rotationSpeed = 0;
                dubrisEscape = false;
                planetFrame.Visible = false;
                dubrisFrame.Visible = false;
                valueX = 0;
                valueY = 0;
                valueZ = 0;
                slider.Value = 0;
                slider1.Value = 0;
                rotationSpeed = 0;

                earthRotationSpeed1 = 0;
                moonRotationSpeed1 = 0;
                marsRotationSpeed1 = 0;
                jupiterRotationSpeed1 = 0;
                mercuryRotationSpeed1 = 0;
                cylinderRotationSpeed1 = 0;
                coneRotationSpeed1 = 0;
                torusRotationSpeed1 = 0;
                boxRotationSpeed1 = 0;
                earthRotationSpeed2 = 0;
                moonRotationSpeed2 = 0;
                marsRotationSpeed2 = 0;
                jupiterRotationSpeed2 = 0;
                mercuryRotationSpeed2 = 0;
                cylinderRotationSpeed2 = 0;
                coneRotationSpeed2 = 0;
                torusRotationSpeed2 = 0;
                boxRotationSpeed2 = 0;
                earthRotationSpeed3 = 0;
                moonRotationSpeed3 = 0;
                marsRotationSpeed3 = 0;
                jupiterRotationSpeed3 = 0;
                mercuryRotationSpeed3 = 0;
                cylinderRotationSpeed3 = 0;
                coneRotationSpeed3 = 0;
                torusRotationSpeed3 = 0;
                boxRotationSpeed3 = 0;
            }
        }