public InputManager(IntPtr windowHandle) { this.windowHandle = windowHandle; inputDevices = new List<GenericInput>(); AddNewDevices(); lastInputState = new InputState(); StartInputThread(); }
private InputState GetCurrentState() { InputState currentInputState = new InputState(); for (int i = 0; i < inputDevices.Count; i++) { currentInputState = inputDevices[i].GetCurrentState(); if (currentInputState != null) { lastInputState = currentInputState; return currentInputState; } } return null; }
private void InvokeNewInputStateEvent(InputState inputState) { if (NewInputState != null) { NewInputStateEventArgs eventArgs = new NewInputStateEventArgs(inputState); NewInputState.Invoke(this, eventArgs); } }
public InputState GetCurrentState() { List<String> buttonsPressed = GetPressedButtons(); Dictionary<String, float> axisValues = GetAxisValues(); if (buttonsPressed.Contains("")) { buttonsPressed.Remove(""); } if (axisValues.ContainsKey("")) { axisValues.Remove(""); } float roll = GetAxisValue(mapping.RollAxisMapping, buttonsPressed, axisValues); float pitch = GetAxisValue(mapping.PitchAxisMapping, buttonsPressed, axisValues); float yaw = GetAxisValue(mapping.YawAxisMapping, buttonsPressed, axisValues); float gaz = GetAxisValue(mapping.GazAxisMapping, buttonsPressed, axisValues); bool cameraSwap = IsFlightButtonPressed(mapping.CameraSwapButton, buttonsPressed); bool takeOff = IsFlightButtonPressed(mapping.TakeOffButton, buttonsPressed); bool land = IsFlightButtonPressed(mapping.LandButton, buttonsPressed); bool hover = IsFlightButtonPressed(mapping.HoverButton, buttonsPressed); bool emergency = IsFlightButtonPressed(mapping.EmergencyButton, buttonsPressed); bool flatTrim = IsFlightButtonPressed(mapping.FlatTrimButton, buttonsPressed); if (roll != lastInputState.Roll || pitch != lastInputState.Pitch || yaw != lastInputState.Yaw || gaz != lastInputState.Gaz || cameraSwap != lastInputState.CameraSwap || takeOff != lastInputState.TakeOff || land != lastInputState.Land || hover != lastInputState.Hover || emergency != lastInputState.Emergency || flatTrim != lastInputState.FlatTrim) { InputState newInputState = new InputState(roll, pitch, yaw, gaz, cameraSwap, takeOff, land, hover, emergency, flatTrim); lastInputState = newInputState; return newInputState; } else { return null; } }
private void UpdateDroneState(InputState inputState) { labelInputRoll.Text = String.Format("{0:+0.000;-0.000;+0.000}", inputState.Roll); labelInputPitch.Text = String.Format("{0:+0.000;-0.000;+0.000}", -inputState.Pitch); labelInputYaw.Text = String.Format("{0:+0.000;-0.000;+0.000}", -inputState.Yaw); labelInputGaz.Text = String.Format("{0:+0.000;-0.000;+0.000}", -inputState.Gaz); checkBoxInputTakeoff.Checked = inputState.TakeOff; checkBoxInputLand.Checked = inputState.Land; checkBoxInputHover.Checked = inputState.Hover; checkBoxInputEmergency.Checked = inputState.Emergency; checkBoxInputFlatTrim.Checked = inputState.FlatTrim; checkBoxInputChangeCamera.Checked = inputState.CameraSwap; }
private void SendDroneCommands(InputState inputState) { if (inputState.CameraSwap) { ChangeCamera(); } if (inputState.TakeOff && arDroneControl.CanTakeoff) { Takeoff(); } else if (inputState.Land && arDroneControl.CanLand) { Land(); } if (inputState.Hover && arDroneControl.CanEnterHoverMode) { EnterHoverMode(); } else if (inputState.Hover && arDroneControl.CanLeaveHoverMode) { LeaveHoverMode(); } if (inputState.Emergency) { Emergency(); } else if (inputState.FlatTrim) { FlatTrim(); } float roll = inputState.Roll / 1.0f; float pitch = inputState.Pitch / 1.0f; float yaw = inputState.Yaw / 2.0f; float gaz = inputState.Gaz / 2.0f; Navigate(roll, pitch, yaw, gaz); }
public NewInputStateEventArgs(InputState currentInputState) { this.currentInputState = currentInputState; }