下面列出了android.view.MotionEvent#AXIS_RY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Scale an axis to be zero-centered with a proper range.
*/
public float scaleAxis(InputDevice inputDevice, int axis, float value)
{
if (isDualShock4(inputDevice))
{
// Android doesn't have correct mappings for this controller's triggers. It reports them
// as RX & RY, centered at -1.0, and with a range of [-1.0, 1.0]
// Scale them to properly zero-centered with a range of [0.0, 1.0].
if (axis == MotionEvent.AXIS_RX || axis == MotionEvent.AXIS_RY)
{
return (value + 1) / 2.0f;
}
}
else if (isXboxOneWireless(inputDevice))
{
// Same as the DualShock 4, the mappings are missing.
if (axis == MotionEvent.AXIS_Z || axis == MotionEvent.AXIS_RZ)
{
return (value + 1) / 2.0f;
}
if (axis == MotionEvent.AXIS_GENERIC_1)
{
// This axis is stuck at ~.5. Ignore it.
return 0.0f;
}
}
else if (isMogaPro2Hid(inputDevice))
{
// This controller has a broken axis that reports a constant value. Ignore it.
if (axis == MotionEvent.AXIS_GENERIC_1)
{
return 0.0f;
}
}
return value;
}
/**
* Method for mapping PS4 gamepad axis and button values
* to standard gamepad button and axes values.
*/
@Override
public void mapToStandardGamepad(
float[] mappedAxes, float[] mappedButtons, float[] rawAxes, float[] rawButtons) {
float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A];
float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B];
float c = rawButtons[KeyEvent.KEYCODE_BUTTON_C];
float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X];
mappedButtons[CanonicalButtonIndex.PRIMARY] = b;
mappedButtons[CanonicalButtonIndex.SECONDARY] = c;
mappedButtons[CanonicalButtonIndex.TERTIARY] = a;
mappedButtons[CanonicalButtonIndex.QUATERNARY] = x;
float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y];
float z = rawButtons[KeyEvent.KEYCODE_BUTTON_Z];
mappedButtons[CanonicalButtonIndex.LEFT_SHOULDER] = y;
mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = z;
float rx = rawAxes[MotionEvent.AXIS_RX];
float ry = rawAxes[MotionEvent.AXIS_RY];
mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = scaleRxRy(rx);
mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = scaleRxRy(ry);
mapHatAxisToDpadButtons(mappedButtons, rawAxes);
mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);
mapXYAxes(mappedAxes, rawAxes);
mapZAndRZAxesToRightStick(mappedAxes, rawAxes);
}
UnknownGamepadMappings(int[] axes) {
int hatAxesFound = 0;
for (int axis : axes) {
switch (axis) {
case MotionEvent.AXIS_LTRIGGER:
case MotionEvent.AXIS_BRAKE:
mLeftTriggerAxis = axis;
break;
case MotionEvent.AXIS_RTRIGGER:
case MotionEvent.AXIS_GAS:
case MotionEvent.AXIS_THROTTLE:
mRightTriggerAxis = axis;
break;
case MotionEvent.AXIS_RX:
case MotionEvent.AXIS_Z:
mRightStickXAxis = axis;
break;
case MotionEvent.AXIS_RY:
case MotionEvent.AXIS_RZ:
mRightStickYAxis = axis;
break;
case MotionEvent.AXIS_HAT_X:
hatAxesFound++;
break;
case MotionEvent.AXIS_HAT_Y:
hatAxesFound++;
break;
default:
break;
}
}
if (hatAxesFound == 2) {
mUseHatAxes = true;
}
}
private static void mapRXAndRYAxesToRightStick(float[] mappedAxes, float[] rawAxes) {
mappedAxes[CanonicalAxisIndex.RIGHT_STICK_X] = rawAxes[MotionEvent.AXIS_RX];
mappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y] = rawAxes[MotionEvent.AXIS_RY];
}