This project is read-only.

Unconverted Gamepad inputs?

Nov 21, 2010 at 2:36 PM
Edited Nov 21, 2010 at 2:40 PM

Hi I'm trying to use the Nuclex.Input to work with a joystick, and i seam to be limited to xbox controls; this is ok for the buttons but It doesn't map the twist and throttle to anything, also when the "pitch" of the joystick is left centred it returns a value of 3 for the Y value [which is supposed to be between -1 and 1].

So I was wondering is there a way to directly access the [Unmapped to Xbox] buttons/axes of a direct input device through Nuclex or do I have to resort to working with SlimDX on its own?

[EDIT] just noticed that the throttle and twist are mapped to the triggers, this is mostly ok except that the twist is limited between 0 and 1 thus no anti-clockwise twist is registered

Nov 21, 2010 at 10:31 PM

I designed Nuclex.Input to be as simple as possible, so it only returns those buttons that fit in a GamePadState and ignores the rest, same with any axes and sliders. To obtain the full state, you'll have to either use SlimDX directly or modify the source code of the library like this:

/// <summary>Retrieves the current DirectInput joystick state</summary>
/// <returns>The current state of the DirectInput joystick</returns>
public override JoystickState GetStateEx() {
  return this.currentJoystickState;

Then you could attempt to downcast IGamePad to DirectInputGamePad and, if the cast succeeds (meaning it's not an Xbox 360 game pad), use GetStateEx() to obtain the full state.

I could add a similar method in the next release, returning a GamePadStateEx structure with a number of buttons, sliders and axes (to avoid exposing the SlimDX interfaces). Design-wise, that wouldn't be a big change, but it would put the task of mapping those axes to the proper controls in the hands of the game.


That your Y axis returns a value of 3.0 is indeed not desired :)

I normalize the integers returned by DirectInput using the DIPROPRANGE structure, maybe I still have a bug somewhere in there. Would you be able to link Nuclex.Input in source and give me the values of the .LowerRange and .UpperRange fields being assigned in the GamePadConverter.addAxisConverters() method?

That axes are mapped to triggers is also not what I had in mind. I only have a single game pad to test on and even there, the right analog stick is reported to DirectInput as a slider. I fear I'll have to create some kind of reporting tool and ask people to send me back reports about their game pads to understand the logic behind DirectInput's axis/slider mapping :/


Dec 12, 2010 at 4:37 PM

I added support for all of DirectInput's axes, sliders, PoVs and buttons in the current trunk. The entire state is encapsulated in a new structure, ExtendedGamePadState, that can be queried using the IGamePad.GetExtendedState() method:


This achieves several things:

  • It prevents the game from requiring a reference to SlimDX.DirectInput.dll (because Nuclex.Input doesn't have any data structures pertaining to SlimDX in its public interface)
  • It isolates the game from having to deal with the messy DeviceObjectInstance and ObjectProperties stuff
  • In case someone wants to use another DirectInput wrapper instead of Nuclex.Input (though I honestly can't imagine why :P), he can just provide a compatible ExtendedGamePadState class instead of rewriting all his code.

I also rewrote the DirectInput -> XNA GamePad mapping code, hopefully achieving an even better mapping of common DirectInput controllers than before.

As an added bonus, if extended states aren't used by a game, there will be no overhead at all from the new functionality. SlimDX joystick states are queried into a ring buffer of reused state structures and GamePadStates as well as ExtendedGamePadStates are only constructed from that on demand. I hope that way everyone is happy :)