com.jme3.input.JoyInput Java Examples

The following examples show how to use com.jme3.input.JoyInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestJoystick.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Joystick[] joysticks = inputManager.getJoysticks();
    if (joysticks == null)
        throw new IllegalStateException("Cannot find any joysticks!");
        
    for (Joystick joy : joysticks){
        System.out.println(joy.toString());
    }

    inputManager.addMapping("DPAD Left", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, true));
    inputManager.addMapping("DPAD Right", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, false));
    inputManager.addMapping("DPAD Down", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, true));
    inputManager.addMapping("DPAD Up", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, false));
    inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up");

    inputManager.addMapping("Joy Left", new JoyAxisTrigger(0, 0, true));
    inputManager.addMapping("Joy Right", new JoyAxisTrigger(0, 0, false));
    inputManager.addMapping("Joy Down", new JoyAxisTrigger(0, 1, true));
    inputManager.addMapping("Joy Up", new JoyAxisTrigger(0, 1, false));
    inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up");
}
 
Example #2
Source File: JInputJoyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public JInputJoystick( InputManager inputManager, JoyInput joyInput, Controller controller, 
                       int joyId, String name ) {
    super( inputManager, joyInput, joyId, name );
    
    this.controller = controller;
    
    this.nullAxis = new DefaultJoystickAxis( getInputManager(), this, -1, 
                                             "Null", "null", false, false, 0 );
    this.xAxis = nullAxis;                                                     
    this.yAxis = nullAxis;                                                     
    this.povX = nullAxis;
    this.povY = nullAxis;                                                     
}
 
Example #3
Source File: LwjglAbstractDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    if (joyInput == null){
        joyInput = new JInputJoyInput();
    }
    return joyInput;
}
 
Example #4
Source File: AndroidHarnessFragment.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void gainFocus() {
    logger.fine("gainFocus");
    if (view != null) {
        view.onResume();
    }

    if (app != null) {
        //resume the audio
        AudioRenderer audioRenderer = app.getAudioRenderer();
        if (audioRenderer != null) {
            audioRenderer.resumeAll();
        }
        //resume the sensors (aka joysticks)
        if (app.getContext() != null) {
            JoyInput joyInput = app.getContext().getJoyInput();
            if (joyInput != null) {
                if (joyInput instanceof AndroidSensorJoyInput) {
                    AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
                    androidJoyInput.resumeSensors();
                }
            }
        }
    }

    if (app != null) {
        app.gainFocus();
    }
}
 
Example #5
Source File: AndroidHarnessFragment.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void loseFocus() {
    logger.fine("loseFocus");
    if (app != null) {
        app.loseFocus();
    }

    if (view != null) {
        view.onPause();
    }

    if (app != null) {
        //pause the audio
        AudioRenderer audioRenderer = app.getAudioRenderer();
        if (audioRenderer != null) {
            audioRenderer.pauseAll();
        }
        //pause the sensors (aka joysticks)
        if (app.getContext() != null) {
            JoyInput joyInput = app.getContext().getJoyInput();
            if (joyInput != null) {
                if (joyInput instanceof AndroidSensorJoyInput) {
                    AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
                    androidJoyInput.pauseSensors();
                }
            }
        }
    }

}
 
Example #6
Source File: AndroidHarness.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void gainFocus() {
    logger.fine("gainFocus");
    if (view != null) {
        view.onResume();
    }

    if (app != null) {
        //resume the audio
        AudioRenderer audioRenderer = app.getAudioRenderer();
        if (audioRenderer != null) {
            audioRenderer.resumeAll();
        }
        //resume the sensors (aka joysticks)
        if (app.getContext() != null) {
            JoyInput joyInput = app.getContext().getJoyInput();
            if (joyInput != null) {
                if (joyInput instanceof AndroidSensorJoyInput) {
                    AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
                    androidJoyInput.resumeSensors();
                }
            }
        }
    }

    isGLThreadPaused = false;

    if (app != null) {
        app.gainFocus();
    }
}
 
Example #7
Source File: AndroidHarness.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void loseFocus() {
    logger.fine("loseFocus");
    if (app != null) {
        app.loseFocus();
    }

    if (view != null) {
        view.onPause();
    }

    if (app != null) {
        //pause the audio
        AudioRenderer audioRenderer = app.getAudioRenderer();
        if (audioRenderer != null) {
            audioRenderer.pauseAll();
        }
        //pause the sensors (aka joysticks)
        if (app.getContext() != null) {
            JoyInput joyInput = app.getContext().getJoyInput();
            if (joyInput != null) {
                if (joyInput instanceof AndroidSensorJoyInput) {
                    AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
                    androidJoyInput.pauseSensors();
                }
            }
        }
    }
    isGLThreadPaused = true;
}
 
Example #8
Source File: AndroidJoystickJoyInput14.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AndroidJoystick( InputManager inputManager, JoyInput joyInput, InputDevice device,
                       int joyId, String name ) {
    super( inputManager, joyInput, joyId, name );

    this.device = device;

    this.nullAxis = new DefaultJoystickAxis( getInputManager(), this, -1,
                                             "Null", "null", false, false, 0 );
    this.xAxis = nullAxis;
    this.yAxis = nullAxis;
    this.povX = nullAxis;
    this.povY = nullAxis;
}
 
Example #9
Source File: AndroidSensorJoyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AndroidSensorJoystick( InputManager inputManager, JoyInput joyInput,
                        int joyId, String name){

    super( inputManager, joyInput, joyId, name );

    this.nullAxis = new DefaultJoystickAxis( getInputManager(), this, -1,
                                             "Null", "null", false, false, 0 );
    this.xAxis = nullAxis;
    this.yAxis = nullAxis;
    this.povX = nullAxis;
    this.povY = nullAxis;

}
 
Example #10
Source File: IGLESContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JoyInput getJoyInput() {
/*
    if (androidSensorJoyInput == null) {
        androidSensorJoyInput = new AndroidSensorJoyInput();
    }
    return androidSensorJoyInput;
    */
    return null;//  new DummySensorJoyInput();
}
 
Example #11
Source File: LwjglWindowVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    if (joyInput == null) {
        joyInput = new GlfwJoystickInput();
    }
    return joyInput;
}
 
Example #12
Source File: LwjglWindow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    if (joyInput == null) {
        joyInput = new GlfwJoystickInput();
    }
    return joyInput;
}
 
Example #13
Source File: OGLESContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    return null;
}
 
Example #14
Source File: AwtPanelsContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return null;
}
 
Example #15
Source File: JoglContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return null;
}
 
Example #16
Source File: LwjglOffscreenBuffer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return null;
}
 
Example #17
Source File: LwjglAbstractDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    if (joyInput == null){
        joyInput = new JInputJoyInput();
    }
    return joyInput;
}
 
Example #18
Source File: NullContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return null;
}
 
Example #19
Source File: AwtPanelsContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    return null;
}
 
Example #20
Source File: JoglContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return null;
}
 
Example #21
Source File: AzertyFlyByCamera.java    From OpenRTS with MIT License 4 votes vote down vote up
@Override
public void registerWithInput(InputManager inputManager){
       this.inputManager = inputManager;
       
       String[] mappings = new String[]{
           "FLYCAM_Left",
           "FLYCAM_Right",
           "FLYCAM_Up",
           "FLYCAM_Down",

           "FLYCAM_StrafeLeft",
           "FLYCAM_StrafeRight",
           "FLYCAM_Forward",
           "FLYCAM_Backward",

           "FLYCAM_ZoomIn",
           "FLYCAM_ZoomOut",
           "FLYCAM_RotateDrag",

           "FLYCAM_Rise",
           "FLYCAM_Lower"
       };

       // both mouse and button - rotation of cam
       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));

       // mouse only - zoom in/out with wheel, and rotate drag
       inputManager.addMapping("FLYCAM_ZoomIn", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
       inputManager.addMapping("FLYCAM_ZoomOut", new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
       inputManager.addMapping("FLYCAM_RotateDrag", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));

       // keyboard only WASD for movement and WZ for rise/lower height
       inputManager.addMapping("FLYCAM_StrafeLeft", new KeyTrigger(KeyInput.KEY_Q));
       inputManager.addMapping("FLYCAM_StrafeRight", new KeyTrigger(KeyInput.KEY_D));
       inputManager.addMapping("FLYCAM_Forward", new KeyTrigger(KeyInput.KEY_Z));
       inputManager.addMapping("FLYCAM_Backward", new KeyTrigger(KeyInput.KEY_S));
       inputManager.addMapping("FLYCAM_Rise", new KeyTrigger(KeyInput.KEY_R));
       inputManager.addMapping("FLYCAM_Lower", new KeyTrigger(KeyInput.KEY_F));

       inputManager.addListener(this, mappings);
       inputManager.setCursorVisible(dragToRotate);

       Joystick[] joysticks = inputManager.getJoysticks();
       if (joysticks != null && joysticks.length > 0){
           Joystick joystick = joysticks[0];
           joystick.assignAxis("FLYCAM_StrafeRight", "FLYCAM_StrafeLeft", JoyInput.AXIS_POV_X);
           joystick.assignAxis("FLYCAM_Forward", "FLYCAM_Backward", JoyInput.AXIS_POV_Y);
           joystick.assignAxis("FLYCAM_Right", "FLYCAM_Left", joystick.getXAxisIndex());
           joystick.assignAxis("FLYCAM_Down", "FLYCAM_Up", joystick.getYAxisIndex());
       }
   }
 
Example #22
Source File: NullContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    return null;
}
 
Example #23
Source File: AndroidInputHandler.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public JoyInput getJoyInput() {
    return joyInput;
}
 
Example #24
Source File: LwjglOffscreenBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    return null;
}
 
Example #25
Source File: AWTContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JoyInput getJoyInput() {
    return null;
}
 
Example #26
Source File: JmeContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * @return Joystick input implementation. May be null if not available.
 */
public JoyInput getJoyInput();
 
Example #27
Source File: JmeContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * @return Joystick input implementation. May be null if not available.
 */
public JoyInput getJoyInput();