Game Development Community

ActionMapping for XBOX 360 Controller for Windows?

by Markus Nuebel · in Torque Game Engine Advanced · 02/11/2006 (12:17 pm) · 6 replies

Hi guys.

I am currently trying to get an XBOX 360 Controller for Windows to work with our game.
It is basically working and we do not have serious problems, but I am curious, if there is some unfinished gamepad code in the tse codebase.

Tse code defies some new codes, to support gamepades:

enum GamepadCodes {
   XB_BTN_A          = KEY_BUTTON0,
   XB_BTN_B          = KEY_BUTTON1,
   XB_BTN_X          = KEY_BUTTON2,
   XB_BTN_Y          = KEY_BUTTON3,
   
   // Xbox
   XB_BTN_BLACK      = KEY_BUTTON4,
   XB_BTN_WHITE      = KEY_BUTTON5,
   
   // Xenon
   XB_BTN_LSHOULDER  = KEY_BUTTON4,
   XB_BTN_RSHOULDER  = KEY_BUTTON5,

   XB_BTN_START      = KEY_BUTTON6,
   XB_BTN_BACK       = KEY_BUTTON7,
   XB_BTN_LSTICK     = KEY_BUTTON8,
   XB_BTN_RSTICK     = KEY_BUTTON9,
   XB_BTN_LTRIGGER   = KEY_BUTTON10,
   XB_BTN_RTRIGGER   = KEY_BUTTON11
};
What looks strange here, is that all gamepad features, including the two sticks are mapped to buttons. This does not make sense to me, since the sticks have two axis.

The virtual key map has been extended, to allow XBOX friendly keybindings from your script code.

//-----------------------------------------------
   // XBOX 360 Controller
   //-------------------------------------- GAMEPAD EVENTS (Xbox)
   { "btn_a",         SI_BUTTON, XB_BTN_A       },
   { "btn_b",         SI_BUTTON, XB_BTN_B       },
   { "btn_x",         SI_BUTTON, XB_BTN_X       },
   { "btn_y",         SI_BUTTON, XB_BTN_Y       },
   { "black",         SI_BUTTON, XB_BTN_BLACK   },
   { "white",         SI_BUTTON, XB_BTN_WHITE   },
   { "lshoulder",     SI_BUTTON, XB_BTN_LSHOULDER },
   { "rshoulder",     SI_BUTTON, XB_BTN_RSHOULDER },
   { "start",         SI_BUTTON, XB_BTN_START   },
   { "back",          SI_BUTTON, XB_BTN_BACK    },
   { "lstick",        SI_BUTTON, XB_BTN_LSTICK  },
   { "rstick",        SI_BUTTON, XB_BTN_RSTICK  },
   { "ltrigger",      SI_BUTTON, XB_BTN_LTRIGGER },
   { "rtrigger",      SI_BUTTON, XB_BTN_RTRIGGER },
   { "dpad_up",       SI_POV,    SI_UPOV        },
   { "dpad_down",     SI_POV,    SI_DPOV        },
   { "dpad_left",     SI_POV,    SI_LPOV        },
   { "dpad_right",    SI_POV,    SI_RPOV        },

From this mapping I would conclude, that you have to use something like this to map your stick actions:

moveMap.bind( gamepad0, "lstick", moverightleft  );

But this does not work since DirectInput generates xaxis, yaxis, rxaxis , ryaxis events when you move the sticks and TSE builds SI_MOVE events from them.

This results in any command, bound to lstick or rstick to not being called, since there is never a DirectInput event for the associated button.

When binding the usual xaxis, yaxis ... events to your movement functions anything is working fine, because these are the event, my XBOX 360 controller generates.


Is the current code, that deals with lstick and rstick obsolete?
Or is this work in progress?

It would have made sense to me if there were actions like: lstickxaxis and lstickyaxis that get mapped to axis events, e.g. SI_XAXIS and SI_YAXIS instead of mapping the sticks to buttons.

Does anyone know if I am missing something here?

Thanks.
-- Markus

#1
02/11/2006 (2:52 pm)
Here's a resource on TDN (unfortunately, it's ACLed to T2D users, but has no requirement for being ACLed to T2D users) Here.

It is both the source code and some samples that show how to use the controller.
#2
02/12/2006 (1:56 am)
Thanks Jason.

This is very interesting to get the Rumble to work. Will have a read (Luckily I have a T2D license).
But I am still interested, if the current implementation has some flaws, or if I am missing something.
Maybe someone from GG can give some feedback.

-- Markus
#3
02/12/2006 (3:38 am)
Rumble is very platform specific so we've not exposed it in the general input system. Just add some special console functions that hook into whatever it is that will make the device rumble and call them as needed.

It's what we've done every time we've needed it, and it's worked fine. It's at least worth a try in this situation. :)
#4
02/12/2006 (4:51 am)
I understand, Ben.
This makes sense, but what about the mapping of sticks to buttons, as described in my initial post?

I still don't see, how this should work and in fact it did not work for me, since my xbox 360 controller generates axis events for the sticks instead of button events.

-- Markus
#5
02/12/2006 (8:37 am)
Markus,

When I built the diff for the Xbox controller, I found a bunch of problems with the Windows implementation of input for joysticks and gamepads. There are a few crashing bugs in there and DPADs (called POV hats in DInput) just didn't work right. My diff fixed all of those problems too.
#6
02/13/2006 (11:52 am)
Just want to let you know that my talk from above is indeed nonsens.

The TSE code absolutely makes sense, as I found out.
I wasn't aware, that the controller has two additional buttons. Pressing the sticks down gives you button clicks.

So it make sense, to map lstick and rstick to two buttons.

Sorry for the confusion and thanks for the information on the feedback/rumble stuff.

-- Markus