/// <summary> /// CAPTURE ALL SENSOR DATA AND DRAW MAIN HUD /// </summary> private void DrawRegion_4(GameTime gameTime, SpriteBatch spriteBatch) { #region "REGION 4 MAIN FEEDBACK" xnaDrawPanel.GraphicsDevice.Viewport = v4; //********************HUD******************** spriteBatch.Begin(); //Draw Capture Image DrawCaptureImage(gameTime, spriteBatch); //HUD TITLE spriteBatch.DrawString(xnaDrawPanel.HUDfont, "MAIN HUD 4", new Vector2(0, 0), Color.Black); //ARMED SIGN String armString = "NOT ARMED"; if (isArmed) { armString = "ARMED"; if (tcpCore != null) { armString += tcpCore.ConnectionStatus; } } Rectangle aRect = new Rectangle(0, v4.Height - (v4.Height / 20), v4.Width, v4.Height / 20); XNADrawPanel.DrawStringUsingRectangleBox(spriteBatch, xnaDrawPanel.ArialFont, armString, aRect, Color.DarkRed); spriteBatch.Draw(IMAGELIST[5], aRect, Color.FromNonPremultiplied(10, 255, 10, 20)); String camString = "Cam Off"; if (isCapture) { camString = "Cam On"; } Rectangle bRect = new Rectangle(0, 0, v4.Width, v4.Height / 20); XNADrawPanel.DrawStringUsingRectangleBox(spriteBatch, xnaDrawPanel.ArialFont, camString, bRect, Color.DarkRed); spriteBatch.Draw(IMAGELIST[5], bRect, Color.FromNonPremultiplied(10, 255, 10, 20)); if (ISHUDON) { DrawRollHUD(gameTime, spriteBatch); DrawAuxHUD(gameTime, spriteBatch); ThrottleBar.Draw(gameTime, spriteBatch); ElevatorBar.Draw(gameTime, spriteBatch); RudderBar.Draw(gameTime, spriteBatch); AileronBar.Draw(gameTime, spriteBatch); } spriteBatch.End(); #endregion }
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 }