Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  XBox 360 Controller Issue  (Read 3402 times)
0 Members and 1 Guest are viewing this topic.
Offline mclldrd

Senior Newbie


Exp: 3 years



« Posted 2012-06-05 06:31:26 »

Hi,

I'm using an XBox 360 Controller with the LWJGL API, more specifically the Controller Class, and every time I start up the default values for the left and right axis's are ( -1.0, -1.0 ) until I move the analog sticks. Is this the default behaviour and is there anything I can do to make it default to ( 0.0 , 0.0 )?

Thanks
Offline princec

« JGO Spiffy Duke »


Medals: 422
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2012-06-05 08:37:46 »

This is "expected" behaviour though it would be nice if the LWJGL fixed it under-the-hood for the purposes of homogonising it across all controllers and platforms... but basically how I handle this quirk is:
1. At controller create time, I record the initial polled values for each axis
2. I then wait until all initially non-zero axes are different from this initial value before I decide the controller is "initialised".

Actual live code in the pastebin. Notice that I try and specifically detect a 360 controller - turns out reading the axes varies on different controllers - grr.

Cas Smiley

Offline Cero
« Reply #2 - Posted 2012-06-05 16:10:48 »

This is relevant to my interests.

From the start I wanted to support Gamepads strongly, and special code for the Xbox pad seemed like a good idea.
Because, in case on "any controller", of course there is a default mapping which can be "wrong", so the user should be able to just map the pad himself, ingame.
In case of the Xbox controller, they are popular and all internally the same, a default mapping for these should therefore be a "good" one.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mclldrd

Senior Newbie


Exp: 3 years



« Reply #3 - Posted 2012-06-05 22:14:45 »

First of all, thanks for the code, Cas, it's really helpful, but I just have a couple of questions about it

  1. What I found was that it stayed at the default value until I moved the sticks, do you get the user to move them?
  2. Do you keep calling the getController() until isControllerInitialised() returns true

Thanks
Offline princec

« JGO Spiffy Duke »


Medals: 422
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2012-06-05 22:25:14 »

The idea is that somebody wanting to use the controller generally picks it up and wiggles it. I just call getController() every time I want to use it - that's all (if it's null, it's not "ready"). Upon detecting real movement in the controller I also inform the rest of the game and hide the mouse cursor as well, and the whole UI switches to "controller mode".

Cas Smiley

Offline mclldrd

Senior Newbie


Exp: 3 years



« Reply #5 - Posted 2012-06-05 23:48:54 »

Ok, thanks! That clears it up nicely
Offline princec

« JGO Spiffy Duke »


Medals: 422
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2012-06-06 08:23:41 »

Forgot to say, if I subsequently detect mouse movement, I make the mouse visible again and switch back to mouse mode.

Cas Smiley

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #7 - Posted 2012-06-06 08:40:28 »

What JInput does under the covers is whatever the OS tells it, this means that it's up to the device drivers to identify the axis that the controller has. This means that different devices and sometimes the same device but on a different OS will list different axis. It's not ideal, but JInput was only designed to expose the hardware in a consistent way, not to make the devices or drivers underneath consistent Smiley. As for the initial value issue, this is again down to the OS, JInput reads the initial values of the axis and then waits for the OS to notify it of changes in value, again, we could ignore the initial read and just use the updates, but that's not what the OS tells us, so we leave that up to the user of JInput.

There might be an argument for a layer above JInput that handles things like axis mappings and the initial value issue, if anyone fancies doing that, feel free Smiley

Endolf

Offline princec

« JGO Spiffy Duke »


Medals: 422
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2012-06-06 09:45:13 »

JInput's perfect; I just think we probably need to try and plug the leaky abstraction at the LWJGL level and try to incorporate some of my hacks into LWJGL to make as many controllers on as many OSes behave as consistently as possible.

Cas Smiley

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #9 - Posted 2012-06-06 09:47:15 »

JInput's perfect;

Lol.

There are at least 2 features that are not implemented that were supposed to be, and the code that I've written certainly isn't perfect Smiley

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 422
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2012-06-06 09:47:53 »

Well, it works for me! Smiley

So far anyway. I've yet to unleash it in the wild.
 
Cas Smiley

Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #11 - Posted 2012-06-06 09:53:51 »

Well, it works for me! Smiley

I guess it depends on your definition of perfect, for me, perfect and 'works for me' are not quite the same, but I did stop 'perfecting' it once it reached that stage, hence the missing features Smiley

Endolf

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (67 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (13 views)
2014-11-26 15:20:08

SHC (26 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (30 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!