[SOLVED] [JInput] GamePad, Event & Axis

Started by MarneusCalgarXP, September 18, 2006, 20:57:58

Previous topic - Next topic

MarneusCalgarXP

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 !

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


MarneusCalgarXP

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

Fool Running

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

MarneusCalgarXP

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