Hello Guest

[SOLVED] [JInput] GamePad, Event & Axis

  • 4 Replies
  • 10365 Views
[SOLVED] [JInput] GamePad, Event & Axis
« on: September 18, 2006, 20:57:58 »
When using GamePad in event mode, how to know which direction the axis was pressed ???

the following code (taken from LWJGL Wiki ) allows to know wich controller and wich axis triggered the last event, but not which amount, so we can't know wether it was positive or negative !

Code: [Select]

while (Controllers.next())
{
    Controller source = Controllers.getEventSource();
 
    if (Controllers.isEventAxis())
    {        
        System.out.println("Event was from "+source.getName()+" and was from axis "
        + Controllers.getEventControlIndex());
    }
}


Is there any way to know it ?
Dark Skull Software
http://www.darkskull.net


[SOLVED] [JInput] GamePad, Event & Axis
« Reply #2 on: September 19, 2006, 08:00:25 »
No, in some cases it's not ok. Imagine you poll your Joystick every 500 ms.
At t1 = 120ms, you press the X axis, direction : left.
At t2 = 230ms, you release the X axis.

When you'll poll the joystick, at t=500ms, you'll get 2 axis events, but when you will want to get the value using getAxisValue, it will return you 0. So you'll lose the information of what appened at t1...
Dark Skull Software
http://www.darkskull.net

hmmmmmm...
« Reply #3 on: September 19, 2006, 13:39:20 »
From the look of the code (someone correct me if I'm wrong :lol: ). It looks like the events are just generated by the state of the controller at the time poll() is called.
In other words, there is no way to get your event at t1=120ms if you only poll every 500ms... The value you get when you call getAxisValue() is the value for the event (it doesn't seem to go to the controller and re-get the value).
Hope that makes sense :D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

[SOLVED] [JInput] GamePad, Event & Axis
« Reply #4 on: September 21, 2006, 14:50:54 »
Ok, I understand, i found another solution : I wrote a Thread wich manages the input polling every 10 milliseconds so that it's not impacted by the rendering frequency ^^
Dark Skull Software
http://www.darkskull.net