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); } }
protected void dumpJoysticks( Joystick[] joysticks, PrintWriter out ) { for( Joystick j : joysticks ) { out.println( "Joystick[" + j.getJoyId() + "]:" + j.getName() ); out.println( " buttons:" + j.getButtonCount() ); for( JoystickButton b : j.getButtons() ) { out.println( " " + b ); } out.println( " axes:" + j.getAxisCount() ); for( JoystickAxis axis : j.getAxes() ) { out.println( " " + axis ); } } }
addInfo( "Joystick:\"" + stick.getName() + "\" id:" + stick.getJoyId(), 0 ); for( JoystickButton b : stick.getButtons() ) { addInfo( " '" + b.getName() + "' id:'" + b.getLogicalId() + "'", 0 ); for( JoystickAxis a : stick.getAxes() ) { addInfo( " '" + a.getName() + "' id:'" + a.getLogicalId() + "' analog:" + a.isAnalog(), 1 );
/** * The joystick index. * * @return joystick index. * * @see InputManager#getJoysticks() */ public int getJoyIndex() { return axis.getJoystick().getJoyId(); }
@Override public String toString(){ return "JoystickAxis[name=" + name + ", parent=" + parent.getName() + ", id=" + axisIndex + ", logicalId=" + logicalId + ", isAnalog=" + isAnalog + ", isRelative=" + isRelative + ", deadZone=" + deadZone + "]"; } }
/** * The joystick index. * * @return joystick index. * * @see com.jme3.input.InputManager#getJoysticks() */ public int getJoyIndex() { return button.getJoystick().getJoyId(); }
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 setAxisValue( JoystickAxis axis, float value ) { System.out.println( "Axis:" + axis.getName() + "=" + value ); if( axis == axis.getJoystick().getXAxis() ) { setXAxis(value); } else if( axis == axis.getJoystick().getYAxis() ) { setYAxis(-value); } else if( axis == axis.getJoystick().getAxis(JoystickAxis.Z_AXIS) ) { } else if( axis == axis.getJoystick().getAxis(JoystickAxis.Z_ROTATION) ) { setZRotation(-value); } else if( axis == axis.getJoystick().getPovXAxis() ) { if( lastPovX < 0 ) { setButtonValue( "POV -X", false ); } else if( axis == axis.getJoystick().getPovYAxis() ) { if( lastPovY < 0 ) { setButtonValue( "POV -Y", false );
/** * Assign the mappings to receive events from the given joystick axis. * * @param positiveMapping The mapping to receive events when the axis is negative * @param negativeMapping The mapping to receive events when the axis is positive */ public void assignAxis(String positiveMapping, String negativeMapping){ if (axisIndex != -1) { inputManager.addMapping(positiveMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, false)); inputManager.addMapping(negativeMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, true)); } }
@Override public String toString(){ return "JoystickButton[name=" + getName() + ", parent=" + parent.getName() + ", id=" + getButtonId() + ", logicalId=" + getLogicalId() + "]"; } }
protected void mapGamepad( Joystick j ) { joystickAxisMap.put(j.getXAxis(), Axis.JOYSTICK_LEFT_X); joystickAxisMap.put(j.getYAxis(), Axis.JOYSTICK_LEFT_Y); joystickAxisMap.put(j.getAxis(JoystickAxis.Z_AXIS), Axis.JOYSTICK_RIGHT_X); joystickAxisMap.put(j.getAxis(JoystickAxis.Z_ROTATION), Axis.JOYSTICK_RIGHT_Y); joystickAxisMap.put(j.getPovXAxis(), Axis.JOYSTICK_HAT_X); joystickAxisMap.put(j.getPovYAxis(), Axis.JOYSTICK_HAT_Y); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_0), Button.JOYSTICK_BUTTON1); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_1), Button.JOYSTICK_BUTTON2); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_2), Button.JOYSTICK_BUTTON3); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_3), Button.JOYSTICK_BUTTON4); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_4), Button.JOYSTICK_LEFT1); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_5), Button.JOYSTICK_RIGHT1); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_6), Button.JOYSTICK_LEFT2); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_7), Button.JOYSTICK_RIGHT2); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_8), Button.JOYSTICK_SELECT); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_9), Button.JOYSTICK_START); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_10), Button.JOYSTICK_LEFT3); joystickButtonMap.put(j.getButton(JoystickButton.BUTTON_11), Button.JOYSTICK_RIGHT3); }
/** * Assign the mapping name to receive events from the given button index * on the joystick. * * @param mappingName The mapping to receive joystick button events. */ public void assignButton(String mappingName) { inputManager.addMapping(mappingName, new JoyButtonTrigger(parent.getJoyId(), buttonIndex)); }
@Override public String toString(){ return "JoystickAxis[name=" + name + ", parent=" + parent.getName() + ", id=" + axisIndex + ", logicalId=" + logicalId + ", isAnalog=" + isAnalog + ", isRelative=" + isRelative + ", deadZone=" + deadZone + "]"; } }
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 InputManager#getJoysticks() */ public int getJoyIndex() { return axis.getJoystick().getJoyId(); }
@Override public String toString(){ return "JoystickButton[name=" + getName() + ", parent=" + parent.getName() + ", id=" + getButtonId() + ", logicalId=" + getLogicalId() + "]"; } }
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); } }
/** * The joystick index. * * @return joystick index. * * @see com.jme3.input.InputManager#getJoysticks() */ public int getJoyIndex() { return button.getJoystick().getJoyId(); }
/** * Assign the mapping name to receive events from the given button index * on the joystick. * * @param mappingName The mapping to receive joystick button events. */ public void assignButton(String mappingName) { inputManager.addMapping(mappingName, new JoyButtonTrigger(parent.getJoyId(), buttonIndex)); }
/** * Assign the mappings to receive events from the given joystick axis. * * @param positiveMapping The mapping to receive events when the axis is negative * @param negativeMapping The mapping to receive events when the axis is positive */ public void assignAxis(String positiveMapping, String negativeMapping){ if (axisIndex != -1) { inputManager.addMapping(positiveMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, false)); inputManager.addMapping(negativeMapping, new JoyAxisTrigger(parent.getJoyId(), axisIndex, true)); } }