LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Sardtok on July 17, 2009, 23:17:30

Title: getAxisValue prior to events always returns -1
Post by: Sardtok on July 17, 2009, 23:17:30
Not sure if this is a known problem, and I'm guessing it's a jInput problem, rather than a LWJGL problem.
If I get axis values with getXAxisValue and getYAxisValue, it always returns -1 prior to other events on the controller (haven't tried using getAxisValue(axisId), but I'm guessing it would have the same result.)
If a button is pressed, or an axis is moved, it instantly changes to the correct value.

Can't remember this happening in old versions of LWJGL (1.4), but I just started working on stuff again and changed to 2.1.
Title: Re: getAxisValue prior to events always returns -1
Post by: broumbroum on July 18, 2009, 13:17:17
How do you read jinput events ? Me, it's always worked like that from within a while(pad.hasEvent()) {
Event e = pad.nextEvent()} : float val = Math.round(e.getValue());
       net.java.games.input.Component button = e.getComponent();
       if (_isDebugEnabled()) {
           System.out.println(button.getIdentifier().getName());
       }
       int ID = (val == -1f || val == 1f) ? KeyEvent.KEY_PRESSED : KeyEvent.KEY_RELEASED;
       if (button.getIdentifier() instanceof net.java.games.input.Component.Identifier.Axis) {
       ...
       }


And to answer your asking : I need to store the val=e.getValue() for the next event to know when the button is released in what direction did it go.
Title: Re: getAxisValue prior to events always returns -1
Post by: Sardtok on July 19, 2009, 17:26:42
Actually I'm not using the event system for axes here.
I discard axis events.
What I meant about prior to other events, was if no events have happened on the controller (i.e. the user hasn't touched the controller), then all axes return -1 as their coordinates.
So something like this:
// In init
Controllers.create();
controller = Controllers.getController(0); // I actually put all the controllers in an array, but anyway.
…
// In update
xAxis = controller.getXAxisValue();
yAxis = controller.getYAxisValue();
…
// In render
bitmapFont.drawString(String.format("xAxis: %3.1f%nyAxis: %3.1f"), x, y);


Until I actually do something with the controller, both the x and y axes have the position -1.
Of course, I could probably make a check to see if all axes return -1 and that way tell that the controller isn't ready, but it doesn't seem very efficient.
Title: Re: getAxisValue prior to events always returns -1
Post by: broumbroum on July 19, 2009, 22:07:45
I think Axis should return 0 as the zero pos, not -1... maybe its a stick and it is hanging down LOL
Title: Re: getAxisValue prior to events always returns -1
Post by: Sardtok on July 20, 2009, 08:49:00
Yeah, if only the sticks were all sticking to their -1 position.
If I press a button or anything, all the axes become 0.
I'm suspecting this is a bug in jInput, and not really related to LWJGL.