Example #1
0
        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            _texture = _mjpeg.GetMjpegFrame(this.GraphicsDevice);

            base.Update(gameTime);
        }
Example #2
0
        //Draw Camera Feed as feedback
        public override void Draw(TimeSpan elapsedTime, TimeSpan totalTime)
        {
            //screenManager.GraphicsDevice.Clear(myColor);
            spriteBatch.Begin();
            try
            {
                //Grab Current Image
                camImage = videoDecoder.GetMjpegFrame(screenManager.GraphicsDevice);


                //Draw the image (video stream)
                if (camImage != null)
                {
                    spriteBatch.Draw(camImage, new Vector2(SCREENWIDTH / 2.0f - ((camImage.Height * videoScale) / 2.0f), SCREENHEIGHT / 2.0f + ((camImage.Width * videoScale) / 2.0f)), null, Color.White, -(float)Math.PI / 2, Vector2.Zero, videoScale, SpriteEffects.None, 0);
                }
                else
                {
                    spriteBatch.Draw(myImage, new Vector2(SCREENWIDTH / 2.0f - 320, SCREENHEIGHT / 2.0f - 320), Color.White);
                }
            }
            catch (Exception) { }

            //Draw Mask
            //  spriteBatch.Draw(mask, Vector2.Zero, Color.DarkGray);

            ////Draw All Fixation Crosses
            //for (int i = 9; i < 16; i = i + 2)
            //{
            //    spriteBatch.Draw(Arrow[i], Radial[i], null, Color.White, 0, Vector2.Zero, 0.1f, SpriteEffects.None, 1);
            //}

            ////Draw feedback target
            //if (FB.X != 0 && FB.Y != 0)
            //{
            //    spriteBatch.Draw(fbArrow, FB, null, Color.FromNonPremultiplied(new Vector4(0, 0.8f, 0, 1)), 0, Vector2.Zero, 0.1f, SpriteEffects.None, 1);
            //}

            spriteBatch.End();

            base.Draw(elapsedTime, totalTime);
        }
Example #3
0
        public void Update(GameTime gameTime)
        {
            #region "INPUTS => KEYBOARD & JOYSTICK"
            #region "Keyboard INput"
            oldKeyboardState    = Keyboard.GetState();
            currentGamePadState = GamePad.GetState(pIndex);
            //------------------------------------------>
            //Change viewport
            xnaDrawPanel.GRAPHICS_DEBUGDATA += "\nVIEWPORT MODE:" + ViewPortMode + "\nAXES [" + Axes_X_Axis + " " + Axes_Y_Axis + " " + Axes_Trigger_Left + " " + Axes_Trigger_Right + " " + Axes_X_Rotation + " " + Axes_Y_Rotation + "] \nButtons [ " + Buttons_X + " " + Buttons_Y + " " + Buttons_A + " " + Buttons_B + " " + Buttons_RB + " " + Buttons_LB + " \n" + Buttons_Start + " " + Buttons_Back + " " + Buttons_AnalogBtn1 + " " + Buttons_AnalogBtn2 + " ]";//DEBUG
            if ((oldGamepadState.DPad.Right == ButtonState.Pressed && currentGamePadState.DPad.Right == ButtonState.Released))
            {
                ViewPortMode++; if (ViewPortMode > ViewPortModeMax)
                {
                    ViewPortMode = 0;
                }
            }
            else if ((oldGamepadState.DPad.Left == ButtonState.Pressed && currentGamePadState.DPad.Left == ButtonState.Released))
            {
                ViewPortMode--; if (ViewPortMode < ViewPortModeMin)
                {
                    ViewPortMode = ViewPortModeMax;
                }
            }
            if (oldKeyboardState.IsKeyDown(Keys.End) && currentKeyboardState.IsKeyUp(Keys.End))
            {
                if (ISHUDON)
                {
                    ISHUDON = false;
                }
                else
                {
                    ISHUDON = true;
                }
            }

            #endregion
            //Get Joystick Data
            #region "Buttons For Indicator Only"
            if (currentGamePadState.Buttons.Y == ButtonState.Pressed && oldGamepadState.Buttons.Y == ButtonState.Released)
            {
                AuxMode++; if (AuxMode > 4)
                {
                    AuxMode = 1;
                }
            }

            if (currentGamePadState.Buttons.X == ButtonState.Pressed && oldGamepadState.Buttons.X == ButtonState.Released)
            {
                if (!Buttons_X)
                {
                    Buttons_X = true; Buttons_A = false; Buttons_B = false;
                }
            }
            if (currentGamePadState.Buttons.A == ButtonState.Pressed && oldGamepadState.Buttons.A == ButtonState.Released)
            {
                if (!Buttons_A)
                {
                    Buttons_A = true; Buttons_X = false; Buttons_B = false;
                }
            }
            if (currentGamePadState.Buttons.B == ButtonState.Pressed && oldGamepadState.Buttons.B == ButtonState.Released)
            {
                if (!Buttons_B)
                {
                    Buttons_B = true; Buttons_A = false; Buttons_X = false;
                }
            }

            if (currentGamePadState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                Buttons_RB = true;
            }
            else
            {
                Buttons_RB = false;
            }
            if (currentGamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                Buttons_LB = true;
            }
            else
            {
                Buttons_LB = false;
            }

            if (currentGamePadState.Buttons.Start == ButtonState.Pressed)
            {
                Buttons_Start = true;
            }
            else
            {
                Buttons_Start = false;
            }
            if (currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Buttons_Back = true;
            }
            else
            {
                Buttons_Back = false;
            }

            if (currentGamePadState.Buttons.LeftStick == ButtonState.Pressed)
            {
                Buttons_AnalogBtn1 = true;
            }
            else
            {
                Buttons_AnalogBtn1 = false;
            }
            if (currentGamePadState.Buttons.RightStick == ButtonState.Pressed)
            {
                Buttons_AnalogBtn2 = true;
            }
            else
            {
                Buttons_AnalogBtn2 = false;
            }

            if (currentGamePadState.DPad.Up == ButtonState.Pressed)
            {
                DPad = 1;
            }                                                                     //Up
            else if (currentGamePadState.DPad.Down == ButtonState.Pressed)
            {
                DPad = 2;
            }                                                                            //Down
            else if (currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                DPad = 3;
            }                                                                            //Left
            else if (currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                DPad = 4;
            }                                                                             //Right
            else
            {
                DPad = 0;
            }

            #endregion
            #region "Axes Analog Value"
            Axes_X_Axis        = currentGamePadState.ThumbSticks.Left.X;
            Axes_Y_Axis        = currentGamePadState.ThumbSticks.Left.Y;
            Axes_Trigger_Left  = currentGamePadState.Triggers.Left;
            Axes_Trigger_Right = currentGamePadState.Triggers.Right;
            Axes_X_Rotation    = currentGamePadState.ThumbSticks.Right.X;
            Axes_Y_Rotation    = currentGamePadState.ThumbSticks.Right.Y;
            //Scale Region
            int scaleFactor = 1000, TriggerBalancer = (int)((MaxAileron + MinAileron) / 2);
            Axes_X_Axis_Scaled        = Utils.map((int)((Axes_X_Axis + 1.0f) * scaleFactor), 0, 2000, 1000, 2000);
            Axes_Y_Axis_Scaled        = Utils.map((int)((Axes_Y_Axis + 1.0f) * scaleFactor), 0, 2000, (int)MinThrottle, (int)MaxThrottle);//Throttle
            Axes_Trigger_Left_Scaled  = Utils.map((int)(Axes_Trigger_Left * scaleFactor), 0, 2000, 1000, 2000);
            Axes_Trigger_Right_Scaled = Utils.map((int)(Axes_Trigger_Right * scaleFactor), 0, 2000, 1000, 2000);
            Axes_X_Rotation_Scaled    = Utils.map((int)((Axes_X_Rotation + 1.0f) * scaleFactor), 0, 2000, (int)MinRudder, (int)MaxRudder);     //Rudder
            Axes_Y_Rotation_Scaled    = Utils.map((int)((Axes_Y_Rotation + 1.0f) * scaleFactor), 0, 2000, (int)MinElevator, (int)MaxElevator); //Elevator
            //Trigger
            Axes_Trigger_Scaled = TriggerBalancer + Axes_Trigger_Right_Scaled - Axes_Trigger_Left_Scaled;                                      //Aileron
            #endregion
            #region "JOYSTICK EVENTS"
            if (Axes_Y_Axis_Scaled <= MinThrottle && (oldGamepadState.Buttons.Start == ButtonState.Pressed && currentGamePadState.Buttons.Start == ButtonState.Released))
            {
                if (isArmed)
                {
                    isArmed = false;
                    ArmDisArmNazeBoard();
                    DisposeMe();
                }
                else
                {
                    isArmed = true;

                    /*
                     * mJpegDecoder.ParseStream(new Uri("http://" + ControlsSets.BaseControlStation_TabControls.IP_ADDRESS +":"+ ControlsSets.BaseControlStation_TabControls.PORT_IMAGE +"/cam.mjpg"));
                     *
                     */
                    tcpCore = new TCPCore(IP_ADDRESS, PORT_CONTROL, PORT_STATUS, PORT_IMAGE);

                    STATUSCONTROL_THREAD = new Thread(new ThreadStart(StatusMessage));
                    STATUSCONTROL_THREAD.Start();
                }
            }
            if (oldGamepadState.Buttons.LeftShoulder == ButtonState.Pressed && currentGamePadState.Buttons.LeftShoulder == ButtonState.Released)
            {
                if (ISSTATUSMESSAGEON)
                {
                    ISSTATUSMESSAGEON = false; Console.WriteLine("OK..");
                }
                else
                {
                    ISSTATUSMESSAGEON = true; Console.WriteLine("off..");
                }
            }
            if (oldGamepadState.Buttons.RightShoulder == ButtonState.Pressed && currentGamePadState.Buttons.RightShoulder == ButtonState.Released)
            {
                if (isCapture)
                {
                    isCapture = false; Console.WriteLine("OK..2");
                }
                else
                {
                    isCapture = true; Console.WriteLine("off2");
                }
            }
            #endregion
            //------------------------------------------>
            oldGamepadState      = currentGamePadState;
            currentKeyboardState = oldKeyboardState;
            #endregion
            #region "VIEWPORT INITLIZE"
            defaultViewPort = xnaDrawPanel.GraphicsDevice.Viewport;
            #endregion
            #region "VIEWPORT REGISTER"
            int Q_W = defaultViewPort.Width / 4, Q_H = defaultViewPort.Height / 3;

            Viewport temp_v1 = new Viewport(0, 0, Q_W, Q_H);
            Viewport temp_v2 = new Viewport(0, Q_H, Q_W, Q_H);
            Viewport temp_v3 = new Viewport(0, Q_H * 2, Q_W, Q_H);
            Viewport temp_v4 = new Viewport(Q_W, 0, Q_W * 3, Q_H * 3);
            //--------------------------------------->
            if (ViewPortMode == 0)
            {
                v1 = temp_v1; v2 = temp_v2; v3 = temp_v3; v4 = temp_v4;
            }
            else if (ViewPortMode == 1)
            {
                v1 = temp_v2; v2 = temp_v3; v3 = temp_v4; v4 = temp_v1;
            }
            else if (ViewPortMode == 2)
            {
                v1 = temp_v3; v2 = temp_v4; v3 = temp_v1; v4 = temp_v2;
            }
            else if (ViewPortMode == 3)
            {
                v1 = temp_v4; v2 = temp_v1; v3 = temp_v2; v4 = temp_v3;
            }
            //--------------------------------------->
            pM_1 = Matrix.CreatePerspectiveFieldOfView(ModelMaker.fieldOfViewAngleDegree, v1.AspectRatio, ModelMaker.nearPlaneDistance, ModelMaker.farPlaneDistance);
            pM_2 = Matrix.CreatePerspectiveFieldOfView(ModelMaker.fieldOfViewAngleDegree, v2.AspectRatio, ModelMaker.nearPlaneDistance, ModelMaker.farPlaneDistance);
            pM_3 = Matrix.CreatePerspectiveFieldOfView(ModelMaker.fieldOfViewAngleDegree, v3.AspectRatio, ModelMaker.nearPlaneDistance, ModelMaker.farPlaneDistance);
            pM_4 = Matrix.CreatePerspectiveFieldOfView(ModelMaker.fieldOfViewAngleDegree, v4.AspectRatio, ModelMaker.nearPlaneDistance, ModelMaker.farPlaneDistance);
            #endregion
            #region "Model Update"
            modelMaker_DroneModel.setRotation(MODEL_Rotation_X, MODEL_Rotation_Y, MODEL_Rotation_Z);
            modelMaker_DroneModel.Update(gameTime);
            #endregion
            #region "BAR"
            //Throttle bar
            ThrottleBar.SetMaxMinVal((int)MaxThrottle, (int)MinThrottle);
            ThrottleBar.Update_Pos(new Vector2(xnaDrawPanel.GraphicsDevice.Viewport.Width / 12, xnaDrawPanel.GraphicsDevice.Viewport.Height / 2));
            ThrottleBar.SetCurrentVal((int)Axes_Y_Axis_Scaled);
            ThrottleBar.Update(gameTime);
            //Elevator Bar
            ElevatorBar.SetMaxMinVal((int)MaxElevator, (int)MinElevator);
            ElevatorBar.Update_Pos(new Vector2(xnaDrawPanel.GraphicsDevice.Viewport.Width / 6, xnaDrawPanel.GraphicsDevice.Viewport.Height / 2));
            ElevatorBar.SetCurrentVal((int)Axes_Y_Rotation_Scaled);
            ElevatorBar.Update(gameTime);
            //Rudder Bar
            RudderBar.SetMaxMinVal((int)MaxRudder, (int)MinRudder);
            RudderBar.Update_Pos(new Vector2(xnaDrawPanel.GraphicsDevice.Viewport.Width / 8, xnaDrawPanel.GraphicsDevice.Viewport.Height / 2 + (xnaDrawPanel.GraphicsDevice.Viewport.Height / 6)));
            RudderBar.SetCurrentVal((int)Axes_X_Rotation_Scaled);
            RudderBar.Update(gameTime);
            //Aileron Bar
            AileronBar.SetMaxMinVal((int)MaxAileron, (int)MinAileron);
            AileronBar.Update_Pos(new Vector2(xnaDrawPanel.GraphicsDevice.Viewport.Width / 8, xnaDrawPanel.GraphicsDevice.Viewport.Height / 2 + (xnaDrawPanel.GraphicsDevice.Viewport.Height / 4)));
            AileronBar.SetCurrentVal((int)Axes_Trigger_Scaled);
            AileronBar.Update(gameTime);
            #endregion
            #region UDPMessage
            TCPMessageSystemSync(gameTime);
            #endregion
            #region "MJPG UPDATE CONTROLLER"
            if (isArmed)
            {
                try
                {
                    if (isCapture)
                    {
                        MJPG_captureImage = mJpegDecoder.GetMjpegFrame(xnaDrawPanel.GraphicsDevice);
                    }
                }
                catch (System.Net.WebException ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            #endregion
        }