@@ -46,7 +46,9 @@ public class TestJoystick extends SimpleApplication {
4646 public static void main (String [] args ){
4747 TestJoystick app = new TestJoystick ();
4848 AppSettings settings = new AppSettings (true );
49+ settings .setJoysticksMapper (AppSettings .JOYSTICKS_XBOX_MAPPER );
4950 settings .setUseJoysticks (true );
51+ settings .setX11PlatformPreferred (true );
5052 app .setSettings (settings );
5153 app .start ();
5254 }
@@ -155,7 +157,7 @@ protected void setViewedJoystick( Joystick stick ) {
155157
156158 }
157159 }
158-
160+
159161 /**
160162 * Easier to watch for all button and axis events with a raw input listener.
161163 */
@@ -184,13 +186,15 @@ public void onJoyAxisEvent(JoyAxisEvent evt) {
184186 gamepad .setAxisValue ( evt .getAxis (), value );
185187 if ( value != 0 ) {
186188 lastValues .put (evt .getAxis (), value );
189+ evt .getAxis ().getJoystick ().rumble (0.5f );
187190 }
188191 }
189192
190193 @ Override
191194 public void onJoyButtonEvent (JoyButtonEvent evt ) {
192195 setViewedJoystick ( evt .getButton ().getJoystick () );
193196 gamepad .setButtonValue ( evt .getButton (), evt .isPressed () );
197+ evt .getButton ().getJoystick ().rumble (1f );
194198 }
195199
196200 @ Override
@@ -255,35 +259,39 @@ public GamepadView() {
255259 attachChild (rightStick );
256260
257261 // A "standard" mapping... fits a majority of my game pads
258- addButton ( JoystickButton .BUTTON_0 , 371 , 512 - 176 , 42 , 42 );
259- addButton ( JoystickButton .BUTTON_1 , 407 , 512 - 212 , 42 , 42 );
260- addButton ( JoystickButton .BUTTON_2 , 371 , 512 - 248 , 42 , 42 );
261- addButton ( JoystickButton .BUTTON_3 , 334 , 512 - 212 , 42 , 42 );
262+ addButton ( JoystickButton .BUTTON_XBOX_Y , 371 , 512 - 176 , 42 , 42 );
263+ addButton ( JoystickButton .BUTTON_XBOX_B , 407 , 512 - 212 , 42 , 42 );
264+ addButton ( JoystickButton .BUTTON_XBOX_A , 371 , 512 - 248 , 42 , 42 );
265+ addButton ( JoystickButton .BUTTON_XBOX_X , 334 , 512 - 212 , 42 , 42 );
262266
263267 // Front buttons Some of these have the top ones and the bottoms ones flipped.
264- addButton ( JoystickButton .BUTTON_4 , 67 , 512 - 111 , 95 , 21 );
265- addButton ( JoystickButton .BUTTON_5 , 348 , 512 - 111 , 95 , 21 );
266- addButton ( JoystickButton .BUTTON_6 , 67 , 512 - 89 , 95 , 21 );
267- addButton ( JoystickButton .BUTTON_7 , 348 , 512 - 89 , 95 , 21 );
268+ addButton ( JoystickButton .BUTTON_XBOX_LB , 67 , 512 - 111 , 95 , 21 );
269+ addButton ( JoystickButton .BUTTON_XBOX_RB , 348 , 512 - 111 , 95 , 21 );
270+ addButton ( JoystickButton .BUTTON_XBOX_LT , 67 , 512 - 89 , 95 , 21 );
271+ addButton ( JoystickButton .BUTTON_XBOX_RT , 348 , 512 - 89 , 95 , 21 );
268272
269273 // Select and start buttons
270- addButton ( JoystickButton .BUTTON_8 , 206 , 512 - 198 , 48 , 30 );
271- addButton ( JoystickButton .BUTTON_9 , 262 , 512 - 198 , 48 , 30 );
274+ addButton ( JoystickButton .BUTTON_XBOX_BACK , 206 , 512 - 198 , 48 , 30 );
275+ addButton ( JoystickButton .BUTTON_XBOX_START , 262 , 512 - 198 , 48 , 30 );
272276
273277 // Joystick push buttons
274- addButton ( JoystickButton .BUTTON_10 , 147 , 512 - 300 , 75 , 70 );
275- addButton ( JoystickButton .BUTTON_11 , 285 , 512 - 300 , 75 , 70 );
278+ addButton ( JoystickButton .BUTTON_XBOX_L3 , 147 , 512 - 300 , 75 , 70 );
279+ addButton ( JoystickButton .BUTTON_XBOX_R3 , 285 , 512 - 300 , 75 , 70 );
276280
277281 // Fake button highlights for the POV axes
278282 //
279283 // +Y
280284 // -X +X
281285 // -Y
282286 //
283- addButton ( "POV +Y" , 96 , 512 - 174 , 40 , 38 );
284- addButton ( "POV +X" , 128 , 512 - 208 , 40 , 38 );
285- addButton ( "POV -Y" , 96 , 512 - 239 , 40 , 38 );
286- addButton ( "POV -X" , 65 , 512 - 208 , 40 , 38 );
287+ // addButton( "POV +Y", 96, 512 - 174, 40, 38 );
288+ // addButton( "POV +X", 128, 512 - 208, 40, 38 );
289+ // addButton( "POV -Y", 96, 512 - 239, 40, 38 );
290+ // addButton( "POV -X", 65, 512 - 208, 40, 38 );
291+ addButton ( JoystickButton .BUTTON_XBOX_DPAD_UP , 96 , 512 - 174 , 40 , 38 );
292+ addButton ( JoystickButton .BUTTON_XBOX_DPAD_RIGHT , 128 , 512 - 208 , 40 , 38 );
293+ addButton ( JoystickButton .BUTTON_XBOX_DPAD_DOWN , 96 , 512 - 239 , 40 , 38 );
294+ addButton ( JoystickButton .BUTTON_XBOX_DPAD_LEFT , 65 , 512 - 208 , 40 , 38 );
287295
288296 resetPositions ();
289297 }
@@ -295,30 +303,29 @@ private void addButton( String name, float x, float y, float width, float height
295303 }
296304
297305 public void setAxisValue ( JoystickAxis axis , float value ) {
298-
299- System .out .println ( "Axis:" + axis .getName () + "(id:" + axis .getLogicalId () + ")=" + value );
300- if ( axis == axis .getJoystick ().getXAxis () ) {
306+
307+ if ( axis == axis .getJoystick ().getAxis (JoystickAxis .AXIS_XBOX_LEFT_THUMB_STICK_X )){
301308 setXAxis (value );
302- } else if ( axis == axis .getJoystick ().getYAxis () ) {
309+ } else if ( axis == axis .getJoystick ().getAxis ( JoystickAxis . AXIS_XBOX_LEFT_THUMB_STICK_Y )) {
303310 setYAxis (-value );
304- } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .Z_AXIS ) ) {
311+ } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .AXIS_XBOX_RIGHT_THUMB_STICK_X ) ) {
305312 // Note: in the above condition, we could check the axis name, but
306313 // I have at least one joystick that reports 2 "Z Axis" axes.
307314 // In this particular case, the first one is the right one so
308315 // a name based lookup will find the proper one. It's a problem
309316 // because the erroneous axis sends a constant stream of values.
310317 setZAxis (value );
311- } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .Z_ROTATION ) ) {
318+ } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .AXIS_XBOX_RIGHT_THUMB_STICK_Y ) ) {
312319 setZRotation (-value );
313- } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .LEFT_TRIGGER ) ) {
320+ } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .AXIS_XBOX_LEFT_TRIGGER ) ) {
314321 if ( axis .getJoystick ().getButton (JoystickButton .BUTTON_6 ) == null ) {
315322 // left/right triggers sometimes only show up as axes
316323 boolean pressed = value != 0 ;
317324 if ( pressed != buttons .get (JoystickButton .BUTTON_6 ).isDown () ) {
318325 setButtonValue (JoystickButton .BUTTON_6 , pressed );
319326 }
320327 }
321- } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .RIGHT_TRIGGER ) ) {
328+ } else if ( axis == axis .getJoystick ().getAxis (JoystickAxis .AXIS_XBOX_RIGHT_TRIGGER ) ) {
322329 if ( axis .getJoystick ().getButton (JoystickButton .BUTTON_7 ) == null ) {
323330 // left/right triggers sometimes only show up as axes
324331 boolean pressed = value != 0 ;
0 commit comments