/** * The button index. * * @return button index. * * @see Joystick#assignButton(java.lang.String, int) */ public int getButtonIndex() { return button.getButtonId(); }
private void pickGamePad(Vector2f mouseLoc){ if (lastButton != null) { CollisionResults cresults = pick(cam, mouseLoc, gamepad); for (CollisionResult cr : cresults) { Node n = cr.getGeometry().getParent(); if (n != null && (n instanceof ButtonView)) { String b = ((ButtonView) n).getName().substring("Button:".length()); String name = lastButton.getJoystick().getName().replaceAll(" ", "\\\\ "); String id = lastButton.getLogicalId().replaceAll(" ", "\\\\ "); System.out.println(name + "." + id + "=" + b); return; } } } }
public void setButtonValue( JoystickButton button, boolean isPressed ) { System.out.println( "Button:" + button.getName() + "=" + (isPressed ? "Down" : "Up") ); setButtonValue( button.getLogicalId(), isPressed ); lastButton = button; }
@Override public JoystickButton getButton(String logicalId) { for( JoystickButton b : buttons ) { if( b.getLogicalId().equals(logicalId) ) return b; } return null; }
/** * The joystick index. * * @return joystick index. * * @see com.jme3.input.InputManager#getJoysticks() */ public int getJoyIndex() { return button.getJoystick().getJoyId(); }
protected void mapJoystick( Joystick joystick ) { // Map it differently if there are Z axis if( joystick.getAxis( JoystickAxis.Z_ROTATION ) != null && joystick.getAxis( JoystickAxis.Z_AXIS ) != null ) { // Make the left stick move joystick.getXAxis().assignAxis( CameraInput.FLYCAM_STRAFERIGHT, CameraInput.FLYCAM_STRAFELEFT ); joystick.getYAxis().assignAxis( CameraInput.FLYCAM_BACKWARD, CameraInput.FLYCAM_FORWARD ); // And the right stick control the camera joystick.getAxis( JoystickAxis.Z_ROTATION ).assignAxis( CameraInput.FLYCAM_DOWN, CameraInput.FLYCAM_UP ); joystick.getAxis( JoystickAxis.Z_AXIS ).assignAxis( CameraInput.FLYCAM_RIGHT, CameraInput.FLYCAM_LEFT ); // And let the dpad be up and down joystick.getPovYAxis().assignAxis(CameraInput.FLYCAM_RISE, CameraInput.FLYCAM_LOWER); if( joystick.getButton( "Button 8" ) != null ) { // Let the stanard select button be the y invert toggle joystick.getButton( "Button 8" ).assignButton( CameraInput.FLYCAM_INVERTY ); } } else { joystick.getPovXAxis().assignAxis(CameraInput.FLYCAM_STRAFERIGHT, CameraInput.FLYCAM_STRAFELEFT); joystick.getPovYAxis().assignAxis(CameraInput.FLYCAM_FORWARD, CameraInput.FLYCAM_BACKWARD); joystick.getXAxis().assignAxis(CameraInput.FLYCAM_RIGHT, CameraInput.FLYCAM_LEFT); joystick.getYAxis().assignAxis(CameraInput.FLYCAM_DOWN, CameraInput.FLYCAM_UP); } }
@Override public JoystickButton getButton(String logicalId) { for( JoystickButton b : buttons ) { if( b.getLogicalId().equals(logicalId) ) return b; } return null; }
public void onJoyButtonEvent(JoyButtonEvent evt) { setViewedJoystick( evt.getButton().getJoystick() ); gamepad.setButtonValue( evt.getButton(), evt.isPressed() ); }
protected void mapJoystick( Joystick joystick ) { // Map it differently if there are Z axis if( joystick.getAxis( JoystickAxis.Z_ROTATION ) != null && joystick.getAxis( JoystickAxis.Z_AXIS ) != null ) { // Make the left stick move joystick.getXAxis().assignAxis( CameraInput.FLYCAM_STRAFERIGHT, CameraInput.FLYCAM_STRAFELEFT ); joystick.getYAxis().assignAxis( CameraInput.FLYCAM_BACKWARD, CameraInput.FLYCAM_FORWARD ); // And the right stick control the camera joystick.getAxis( JoystickAxis.Z_ROTATION ).assignAxis( CameraInput.FLYCAM_DOWN, CameraInput.FLYCAM_UP ); joystick.getAxis( JoystickAxis.Z_AXIS ).assignAxis( CameraInput.FLYCAM_RIGHT, CameraInput.FLYCAM_LEFT ); // And let the dpad be up and down joystick.getPovYAxis().assignAxis(CameraInput.FLYCAM_RISE, CameraInput.FLYCAM_LOWER); if( joystick.getButton( "Button 8" ) != null ) { // Let the stanard select button be the y invert toggle joystick.getButton( "Button 8" ).assignButton( CameraInput.FLYCAM_INVERTY ); } } else { joystick.getPovXAxis().assignAxis(CameraInput.FLYCAM_STRAFERIGHT, CameraInput.FLYCAM_STRAFELEFT); joystick.getPovYAxis().assignAxis(CameraInput.FLYCAM_FORWARD, CameraInput.FLYCAM_BACKWARD); joystick.getXAxis().assignAxis(CameraInput.FLYCAM_RIGHT, CameraInput.FLYCAM_LEFT); joystick.getYAxis().assignAxis(CameraInput.FLYCAM_DOWN, CameraInput.FLYCAM_UP); } }
@Override public void update() { for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) { // Axes final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey()); for (final JoystickAxis axis : entry.getValue().getAxes()) { final float value = axisValues.get(axis.getAxisId()); listener.onJoyAxisEvent(new JoyAxisEvent(axis, value)); } // Buttons final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey()); for (final JoystickButton button : entry.getValue().getButtons()) { final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS; if (joyButtonPressed.get(button) != pressed) { joyButtonPressed.put(button, pressed); listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); } } } }
addInfo( " '" + b.getName() + "' id:'" + b.getLogicalId() + "'", 0 );
protected void mapJoystick( Joystick j ) { // We attempt to determine what kind of stick it is so // that we can provide more intelligent button and axis mappings if( j.getAxis(JoystickAxis.Z_ROTATION) != null && j.getAxis(JoystickAxis.Z_AXIS) != null ) { mapGamepad(j); return; } // Else it's a generic one joystickAxisMap.put(j.getXAxis(), Axis.JOYSTICK_X); joystickAxisMap.put(j.getYAxis(), Axis.JOYSTICK_Y); joystickAxisMap.put(j.getPovXAxis(), Axis.JOYSTICK_HAT_X); joystickAxisMap.put(j.getPovYAxis(), Axis.JOYSTICK_HAT_Y); for( JoystickButton b : j.getButtons() ) { String id = b.getLogicalId(); if( !Character.isDigit(id.charAt(0)) ) continue; int idVal = Integer.parseInt(id) + 1; joystickButtonMap.put(b, new Button("joystick_" + idVal, "Button " + idVal)); } }
/** * The joystick index. * * @return joystick index. * * @see com.jme3.input.InputManager#getJoysticks() */ public int getJoyIndex() { return button.getJoystick().getJoyId(); }
/** * The button index. * * @return button index. * * @see Joystick#assignButton(java.lang.String, int) */ public int getButtonIndex() { return button.getButtonId(); }
public void update() { for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) { // Axes final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey()); for (final JoystickAxis axis : entry.getValue().getAxes()) { final float value = axisValues.get(axis.getAxisId()); listener.onJoyAxisEvent(new JoyAxisEvent(axis, value)); } // Buttons final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey()); for (final JoystickButton button : entry.getValue().getButtons()) { final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS; listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); } } }