public static partial class FilterUtilities { // @kurtdekker // // Part of Jetpack Kurt Space Flight available for iOS/Android // // Evalutes a normalized analog input signal (such as an analog // axis) and filters it: // // If signal is below the deadband in absolute magnitude: // - set signal to zero // - return false, no input present in signal // // If signal is at or above the deadband in absolute magnitude: // - re-zero-scale the signal from 0 to 1 (preserving sign!) // - return true, yes we have input // // The purpose is to allow deadbands without a discontinuity // (eg, no sudden snap from 0.0 to deadband minimum) // // Expected signal input domain is [-1 .. +1]. You are responsible for this. // Expected deadband input is zero or positive, but always less than +1 // public static bool DeadbandAndExpand( ref float axis, float deadband) { bool haveInput = false; if (axis < 0) { if (axis > -deadband) { axis = 0; } else { haveInput = true; axis = (axis + deadband) / ( 1.0f - deadband); } } else { if (axis < deadband) { axis = 0; } else { haveInput = true; axis = (axis - deadband) / ( 1.0f - deadband); } } return haveInput; } }