Howto reconfigure the flyByCam inputMappings?

Hi,

how can I reconfigure the flyByCam inputMappings?

For example, I set dragToRotate to true

app.getFlyByCamera.setDragToRotate(true)

but I want to rotate via the right mouseButton, not the left. So I tried to delete the mapping in the inputManager in simpleInitApp().
Turns out that doesn’t work, because the mappings of the flyByCam are not yet initialized when simpleInitApp() is called.
Next I tried to extend the FlyByCam and change the mapping in the new class. But that’s not possible either, because I can’t set the cam in FlyCamAppState, since the setCamera method in there isn’t public.

I’m sure there’s an obvious solution to this, but how? Do I have to implement my own cam with its own appState?

And bonus question: do you use the default FlyByCam in your project? Or do you implement your own?

Thank for your help,
Stefan?

This doesn’t deserve any code nobel prize, but does the trick :D:

[java]
private void dealWithPresetKeys() {
InputManager inputManager = application.getInputManager();
inputManager.deleteMapping(“FLYCAM_Forward”);
inputManager.deleteMapping(“FLYCAM_Backward”);
inputManager.deleteMapping(“FLYCAM_StrafeLeft”);
inputManager.deleteMapping(“FLYCAM_StrafeRight”);
inputManager.deleteMapping(“FLYCAM_Lower”);
inputManager.deleteMapping(“FLYCAM_Rise”);
inputManager.deleteMapping(“FLYCAM_Left”);
inputManager.deleteMapping(“FLYCAM_Right”);
inputManager.deleteMapping(“FLYCAM_Up”);
inputManager.deleteMapping(“FLYCAM_Down”);
inputManager.deleteMapping(“FLYCAM_ZoomIn”);
inputManager.deleteMapping(“FLYCAM_ZoomOut”);

    inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_NUMPAD8));
    inputManager.addMapping("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_NUMPAD5));
    inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_NUMPAD4));
    inputManager.addMapping("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_NUMPAD6));
    inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_NUMPAD7));
    inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_NUMPAD9));
    inputManager.addMapping("FLYCAM_Left", new MouseAxisTrigger(MouseInput.AXIS_X, true), new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("FLYCAM_Right", new MouseAxisTrigger(MouseInput.AXIS_X, false), new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("FLYCAM_Up", new MouseAxisTrigger(MouseInput.AXIS_Y, false), new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("FLYCAM_Down", new MouseAxisTrigger(MouseInput.AXIS_Y, true), new KeyTrigger(KeyInput.KEY_DOWN));

    inputManager.addListener(application.getFlyByCamera(), new String[]{
                "FLYCAM_Forward", "FLYCAM_Backward", "FLYCAM_StrafeLeft", "FLYCAM_StrafeRight",
                "FLYCAM_Lower", "FLYCAM_Rise", "FLYCAM_Left", "FLYCAM_Right", "FLYCAM_Up", "FLYCAM_Down"});
}

[/java]

Also since very recently in nightly you now have constants for each “FLYCAM-blah”
see jmonkeyengine/CameraInput.java at master · jMonkeyEngine/jmonkeyengine · GitHub

Not saying it should be there, since I really couldn’t know, but wondering why there isn’t a getMappings method to return all current mappings?

loopies, thanks. But when (from which method) do you call this code? The mappings for the flyByCam are not registered when initSimpleApp() is called, so the deleteMapping-calls do not work then.

You welcome.

Call it from the main loop (or loop of an appState) once.

A tongue-in-cheek solution:
Step 1: Open FlyBycam.java
Step 2: Ctrl-A
Step 3: Ctrl-C
Step 4: Open a new file MyFlyCam.java
Step 5: Ctrl-V
Step 6: Change class name to MyFlyCam.java and constructor
Step 7: Change mappings as needed.

…or whatever… (Actually, the SDK will let you copy and rename at the same time I think in the refactor menu.)

FlyByCam is only useful for demos and tests as it rapidly becomes unuseful for games where you are more likely to want to control a player object instead of the players eyeball. Any real game will eventually need its own camera implementation. Might as well start early, I say.

@pspeed said: A tongue-in-cheek solution: Step 1: Open FlyBycam.java Step 2: Ctrl-A Step 3: Ctrl-C Step 4: Open a new file MyFlyCam.java Step 5: Ctrl-V Step 6: Change class name to MyFlyCam.java and constructor Step 7: Change mappings as needed.

…or whatever… (Actually, the SDK will let you copy and rename at the same time I think in the refactor menu.)

FlyByCam is only useful for demos and tests as it rapidly becomes unuseful for games where you are more likely to want to control a player object instead of the players eyeball. Any real game will eventually need its own camera implementation. Might as well start early, I say.

Yeah, just Ctrl-C FlyCam.java itself, then Ctrl-P it to the package you want it in, then press “OK” to refactor.

Ok, will do. Thanks!