Skip to content

Instantly share code, notes, and snippets.

@ocornut
Last active October 13, 2020 12:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ocornut/d2d82bbb224c071d7d085e336cc92e37 to your computer and use it in GitHub Desktop.
Save ocornut/d2d82bbb224c071d7d085e336cc92e37 to your computer and use it in GitHub Desktop.
// Mapping for PlayStation 4 DualShock 4 (PS4, DS4) controller exposed via DirectInput
// FYI the numbers here don't make much sense out of context
// I am using https://github.com/ThemsAllTook/libstem_gamepad which remaps xinput and dinput states to arrays of button + arrays of axises.
// So those are my tables to read back from them and handle DS4 which provide dinput data.
// The PAD_*** enums are mine, the AXIS_*** enums tells which remapping function to use on the float data.
// You may prefer to handle the axises data in a different manner (e.g. some people like the analog trigger to go -1 to +1, I'm using 0 to 1).
// This is merely a loose reference to get you started if you want to support DS4 in your application.
// Mapping for PlayStation 4 DualShock 4 (PS4, DS4) controller exposed via DInput.
// VendorId = 0x0000054C, ProductId = 0x000009CC
static const GamePadMappingEntry g_DInputDS4Mapping[] =
{
{ PAD_UP, AXIS_10_00_00, 5 }, // [-1.0f.. 0.0f] --> [+1.0f.. 0.0f]
{ PAD_DOWN, AXIS_00_00_10, 5 }, // [ 0.0f..+1.0f] --> [ 0.0f..+1.0f]
{ PAD_LEFT, AXIS_10_00_00, 4 }, // [-1.0f.. 0.0f] --> [+1.0f.. 0.0f]
{ PAD_RIGHT, AXIS_00_00_10, 4 }, // [ 0.0f..+1.0f] --> [ 0.0f..+1.0f]
{ PAD_START, BUTTON, 9 },
{ PAD_SELECT, BUTTON, 8 },
{ PAD_TOUCH_BUTTON, BUTTON, 13 },
{ PAD_L3, BUTTON, 10 },
{ PAD_R3, BUTTON, 11 },
{ PAD_L1, BUTTON, 4 },
{ PAD_R1, BUTTON, 5 },
{ PAD_CROSS, BUTTON, 1 },
{ PAD_CIRCLE, BUTTON, 2 },
{ PAD_SQUARE, BUTTON, 0 },
{ PAD_TRIANGLE, BUTTON, 3 },
{ PAD_STICK_LEFT_X, AXIS, 3 },
{ PAD_STICK_LEFT_Y, AXIS, 2 },
{ PAD_STICK_RIGHT_X,AXIS, 1 },
{ PAD_STICK_RIGHT_Y,AXIS, 0 },
{ PAD_L2, AXIS_00_05_10, 7 }, // [-1.0f..+1.0f] --> [ 0.0f..+1.0f]
{ PAD_R2, AXIS_00_05_10, 6 }, // [-1.0f..+1.0f] --> [ 0.0f..+1.0f]
{ KEY_INVALID }
};
// Regular XInput controller for reference.
static const GamePadMappingEntry g_XInputMapping[] =
{
{ PAD_UP, BUTTON, 0 },
{ PAD_DOWN, BUTTON, 1 },
{ PAD_LEFT, BUTTON, 2 },
{ PAD_RIGHT, BUTTON, 3 },
{ PAD_START, BUTTON, 4 },
{ PAD_SELECT, BUTTON, 5 },
{ PAD_TOUCH_BUTTON, ZERO, -1 },
{ PAD_L3, BUTTON, 6 },
{ PAD_R3, BUTTON, 7 },
{ PAD_L1, BUTTON, 8 },
{ PAD_R1, BUTTON, 9 },
{ PAD_CROSS, BUTTON, 10 },
{ PAD_CIRCLE, BUTTON, 11 },
{ PAD_SQUARE, BUTTON, 12 },
{ PAD_TRIANGLE, BUTTON, 13 },
{ PAD_STICK_LEFT_X, AXIS, 0 },
{ PAD_STICK_LEFT_Y, AXIS, 1 },
{ PAD_STICK_RIGHT_X,AXIS, 2 },
{ PAD_STICK_RIGHT_Y,AXIS, 3 },
{ PAD_L2, AXIS_00_05_10, 4 },
{ PAD_R2, AXIS_00_05_10, 5 },
{ KEY_INVALID }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment