private static InputMap <WingsuitAction, float> AddMouseLook( Func <bool> whenActive, InputMap <WingsuitAction, float> mouseInput, InputSettings inputSettings) { var adaptedInput = mouseInput.Source; Action <WingsuitAction> activeOn = playerAction => { Func <float> pollFn; adaptedInput.TryGetValue(playerAction, out pollFn); if (pollFn != null) { var pollInput = pollFn .Adapt <float, float>(WithDefault(whenActive, 0.0f)) .Adapt <float, float>(ApplyMouseSensitivity(inputSettings.WingsuitMouseSensitivity)); adaptedInput = adaptedInput.SetItem(playerAction, pollInput); } }; activeOn(WingsuitAction.LookLeft); activeOn(WingsuitAction.LookUp); activeOn(WingsuitAction.LookDown); activeOn(WingsuitAction.LookRight); return(adaptedInput.ToInputMap()); }
private static InputMap <WingsuitAction, float> CreateControllerAxisInput( InputSourceMapping <WingsuitAction> inputMapping, InputSettings inputSettings, Peripherals.ControllerPeripheral peripheral) { var controllerAxisSourceMap = peripheral.Axes; var inputWithJoystickAxisSource = inputMapping.ApplyMapping(controllerAxisSourceMap, Adapters.MergeAxes); // Circularize input of pitch and roll if both are mapped to a joystick if (new [] { WingsuitAction.PitchUp, WingsuitAction.PitchDown, WingsuitAction.RollLeft, WingsuitAction.RollRight }.All(inputWithJoystickAxisSource.Keys.Contains)) { var pitchUp = inputWithJoystickAxisSource.Source[WingsuitAction.PitchUp]; var pitchDown = inputWithJoystickAxisSource.Source[WingsuitAction.PitchDown]; var rollLeft = inputWithJoystickAxisSource.Source[WingsuitAction.RollLeft]; var rollRight = inputWithJoystickAxisSource.Source[WingsuitAction.RollRight]; Func <Vector2> circularizedInput = () => InputUtilities.CircularizeInput(new Vector2(rollRight() - rollLeft(), pitchUp() - pitchDown())); inputWithJoystickAxisSource = inputWithJoystickAxisSource.Source .SetItem(WingsuitAction.PitchUp, () => Adapters.FilterPositiveInput(circularizedInput().y)) .SetItem(WingsuitAction.PitchDown, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().y))) .SetItem(WingsuitAction.RollLeft, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().x))) .SetItem(WingsuitAction.RollRight, () => Adapters.FilterPositiveInput(circularizedInput().x)) .ToInputMap(); } // Scale all pitch, roll and yaw input of a joystick inputWithJoystickAxisSource = inputWithJoystickAxisSource.Adapt <WingsuitAction, float, float>((id, pollFn) => { if (PilotBodyMovementActions.Contains(id)) { return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, inputSettings.InputGamma))); } else if (PilotArmMovementActions.Contains(id)) { return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, 2))); } return(pollFn); }); return(inputWithJoystickAxisSource); }
private static InputMap <WingsuitAction, float> AddMousePlayerControls(Func <bool> whenActive, InputMap <WingsuitAction, float> mouseInput, InputSettings inputSettings) { var adaptedInput = mouseInput.Source; Action <WingsuitAction> resetOnFalse = playerAction => { Func <float> pollFn; adaptedInput.TryGetValue(playerAction, out pollFn); if (pollFn != null) { var pollInput = pollFn .Adapt <float, float>(WithDefault(whenActive, 0.0f)) .Adapt <float, float>(ApplyMouseSensitivity(inputSettings.WingsuitMouseSensitivity)); adaptedInput = adaptedInput.SetItem(playerAction, pollInput); } }; resetOnFalse(WingsuitAction.PitchUp); resetOnFalse(WingsuitAction.PitchDown); resetOnFalse(WingsuitAction.RollLeft); resetOnFalse(WingsuitAction.RollRight); return(adaptedInput.ToInputMap()); }