Joystick input remapping

I’m updating the remapinputAppstate of BigBanana, and I want to remap Joypad/Joystick input.

Relevant code here:

I’d like to do something like

        getApplication().getInputManager().addMapping("joy_" + i, new JoyButtonTrigger());

But the javadoc says

Use Joystick.assignButton(java.lang.String, int) instead.

Fine then, I go there but the javadoc of that method says

Deprecated. Use JoystickButton.assignButton() instead.

…which don’t even exist :frowning:

Ok I did

    Joystick joysticks[] = getApplication().getInputManager().getJoysticks();
    //we use only joystick 1 for now!
    Joystick joy = joysticks[0];
    List<JoystickButton> jbuttons = joy.getButtons();

    for (JoystickButton jb : jbuttons) {
        jb.assignButton("joystick_" + jb.getLogicalId());
        getApplication().getInputManager().addListener(al, "joystick_" + jb.getLogicalId());
    }
1 Like

Now I have a com.jme3.inputJoystickAxis, and I need to get the corresponding com.simsilica.lemur.input.Axis… how should I do?

Lemur’s default joystick mapping is a little primitive I guess.

Not sure this helps:

This code is part of the bigbanana library and will hopefully enable input remapping for all jme games that wants to use joystick or joypad input.

I want to provide a gui for axis remapping. So I did:

    Joystick joysticks[] = getApplication().getInputManager().getJoysticks();
    if (joysticks.length > 0) {

        //we use only joystick 1 for now!
        joystick = joysticks[0];
        joydescr.setText("Using device: " + joystick.getName());
        for (JoystickAxis ja : joystick.getAxes()) {
            ja.assignAxis("joy_axis_" + ja.getAxisId(), "joy_axis_" + ja.getAxisId());
            System.out.println(ja.getName() + " - " + ja.getLogicalId() + " - " + ja.getName() + " - " + ja.getAxisId());
            getApplication().getInputManager().addListener(al, "joy_axis_" + ja.getAxisId());
        }

Then, on the listener:

    public void onAction(String name, boolean keyPressed, float tpf) {
        if (!keyPressed) {
            if (selected != null) {
                    if (name.startsWith("joy_axis_")) {
                        int num = Integer.parseInt(name.substring(9));
                        JoystickAxis axis = joystick.getAxes().get(num);
                        System.out.println("pressed " + axis.getName());
                        getState(BigBananaAppState.class).peel.getProperties().setProperty(bind.propertyKey, axis.getName());
                        saveProps();
                        selected.setText(
                                bind.name + ": "
                                        axis.getName()
                        );
                        selected = null;
                        return;
                    }

Basically I write the settings like:

my.axis=Rotazione X

Which is internationalized and super cool. But then on loading the setting I have

private Axis getAxisInput(String key, String deftl) throws IllegalAccessException {
    String val = peel.getProperties().getProperty("pad." + key, deftl);
    Joystick joysticks[] = getApplication().getInputManager().getJoysticks();
    if (joysticks.length > 0) {

        //we use only joystick 1 for now!
        Joystick joystick = joysticks[0];
        for (JoystickAxis axis : joystick.getAxes()) {
            if (axis.getName().equals(val))
                return axis;
        }
    }
    return null;
}

So… incompatible types: JoystickAxis cannot be converted to Axis; as the actual game currently needs an Axis to be bound with.

Am I doing something wrong?

Also: are these and only these the axis supported? No axis is allowed beyond these?

public interface JoystickAxis {

public static final String X_AXIS = "x";
public static final String Y_AXIS = "y";
public static final String Z_AXIS = "z";
public static final String Z_ROTATION = "rz";

public static final String POV_X = "pov_x";
public static final String POV_Y = "pov_y";

If so, I might want to work with these static value and show to the user the i18n version of it…

I have to spend some time going over my notes and seeing what I had planned for axis remapping… especially in the presence of multiple joysticks. It seems likely that I just never finished this piece. I will take a look… maybe this weekend if not sooner.

Lemur’s InputMapper (which will someday be a part of JME), is already supposed to allow remapping of this sort of thing.

Note: the constants in things like JoystickAxis are meant to map to the standard things that the joystick will report. I don’t believe that changes across countries. So I guess you mean mapping them into local-friendly names for display to the user.

You mean that eventually Axis or JoystickAxis will take over and obsolete the other, or are they supposed to coexist?
Also I should wait for your modification?

Yeah, probably coexist.

Even when InputMapper is migrated (remains to be seen when that will be), it would still be a wrapper around the underlying JME structures. I think the separation is good for both at this point. Over time some incestuous blending can happen after that migration… but it would be a long way down a road of already unknown length.

So JoystickAxis is something you (and I) will have to deal with.

JoystickAxis and Lemur’s Axis kind of have two different purposes anyway. The former being “these are the things JME will care about” and the latter being “Here are some useful constants but there may be more… that will all be called Axis, though”

Lemur’s classes are not meant to be presciptivist… even if the joystick mappings might be implemented that way at the moment (I have not confirmed one way or the other). It’s supposed to be that new Axis instances (or Button instances, etc.) would be created on the fly by Lemur if JME reports them. There just may not be handy constants for them.

I no longer have any idea how I planned to handle multiple joysticks but it’s something I want to look into. My notes on this are a bit scattered.

One of the reasons for working on Spacebugs was to have an end-to-end game to get everything like this working. Eventually it will have a display config screen, input remapping, etc… and the support library modifications to support that.

Ok. But, if JME cares only about JoystickAxis, how do I bind a JoystickAxis to a FunctionID?

Currently, only Axis can be bound…

From what I see, until InputMapper adds support to these, I’m forced to use InputManager… :frowning:

Also

It also appears that with Xinput controllers (for example, the xbox controller) the joystick buttons are mixed… what you register with InputManager during remapping is mapped to another button with InputMapper…

Why is that com.jme3.input.JoystickButton ranges from 0 to 11, and lemur.input.Button ranges from “joystick_1” to “joystick_12”?

This explains why when I use the an index for both things I have buttons shifted… please @pspeed help me before I get insane :banana::banana::banana:

Because Lemur opts to be 1-based to match the mouse buttons… which are 1-based to match Java.

a bump for an interesting topic! :slight_smile:

Yeah, sorry… we had the first nice weather over a weekend in like four weeks and I have a party to prep for.

Which reminds me, if anyone is in or near the Reston/Herndon Virginia area this weekend… PM me and I will send you party details. :slight_smile:

Hope you got a very cool party! How’s going with Lemur? :stuck_out_tongue:

Went from party to vacation. Party went well… vacation is also going well so far… we’ll see if we get rained on.

1 Like