private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); // A joystick at rest does not always report an absolute position of // (0,0). Use the getFlat() method to determine the range of values // bounding the joystick axis center. if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis): event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the joystick axis center. // A joystick at rest does not always report an absolute position of (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the joystick axis center. // A joystick at rest does not always report an absolute position of (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. // A joystick at rest does not always report an absolute position of // (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); // A joystick at rest does not always report an absolute position of // (0,0). Use the getFlat() method to determine the range of values // bounding the joystick axis center. if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); // A joystick at rest does not always report an absolute position of // (0,0). Use the getFlat() method to determine the range of values // bounding the joystick axis center. if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. if (Math.abs(value) > flat) { return value; } } return 0; }
public void dealWithMotionEvent(MotionEvent event){ //Log.i(LOG_TAG, "Input device: " + event.getDevice().getName()); /*if axis has a range of 1 (0 -> 1) instead of 2 (-1 -> 0) do not invert axis value, this is necessary for analog R1 (Brake) or analog R2 (Gas) shoulder buttons on PS3 controller*/ if (event != null) { if (event.getDevice() != null) { InputDevice device = event.getDevice(); mRightAnalogYAxisInvertFactor = (device.getMotionRange(mRightAnalogYAxis).getRange() == 1) ? 1 : -1; mLeftAnalogYAxisInvertFactor = (device.getMotionRange(mLeftAnalogYAxis).getRange() == 1) ? 1 : -1; } else { Log.w(LOG_TAG, "event.getDevice() == null! => event.getClass(): " + event.getClass()); } // default axis are set to work with PS3 controller mControls.setRightAnalogX((float) event.getAxisValue(mRightAnalogXAxis)); mControls.setRightAnalogY((float) (event.getAxisValue(mRightAnalogYAxis)) * mRightAnalogYAxisInvertFactor); mControls.setLeftAnalogX((float) event.getAxisValue(mLeftAnalogXAxis)); mControls.setLeftAnalogY((float) (event.getAxisValue(mLeftAnalogYAxis)) * mLeftAnalogYAxisInvertFactor); mSplit_axis_yaw_right = (float) event.getAxisValue(mSplitAxisYawRightAxis); mSplit_axis_yaw_left = (float) event.getAxisValue(mSplitAxisYawLeftAxis); } }