Search in sources :

Example 6 with JoystickButton

use of com.jme3.input.JoystickButton in project jmonkeyengine by jMonkeyEngine.

the class JInputJoyInput method update.

public void update() {
    ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
    Controller[] cs = ce.getControllers();
    Event e = new Event();
    for (int i = 0; i < cs.length; i++) {
        Controller c = cs[i];
        JInputJoystick stick = joystickIndex.get(c);
        if (stick == null)
            continue;
        if (!c.poll())
            continue;
        int joyId = stick.getJoyId();
        EventQueue q = c.getEventQueue();
        while (q.getNextEvent(e)) {
            Identifier id = e.getComponent().getIdentifier();
            if (id == Identifier.Axis.POV) {
                float x = 0, y = 0;
                float v = e.getValue();
                if (v == POV.CENTER) {
                    x = 0;
                    y = 0;
                } else if (v == POV.DOWN) {
                    x = 0;
                    y = -1f;
                } else if (v == POV.DOWN_LEFT) {
                    x = -1f;
                    y = -1f;
                } else if (v == POV.DOWN_RIGHT) {
                    x = 1f;
                    y = -1f;
                } else if (v == POV.LEFT) {
                    x = -1f;
                    y = 0;
                } else if (v == POV.RIGHT) {
                    x = 1f;
                    y = 0;
                } else if (v == POV.UP) {
                    x = 0;
                    y = 1f;
                } else if (v == POV.UP_LEFT) {
                    x = -1f;
                    y = 1f;
                } else if (v == POV.UP_RIGHT) {
                    x = 1f;
                    y = 1f;
                }
                JoyAxisEvent evt1 = new JoyAxisEvent(stick.povX, x);
                JoyAxisEvent evt2 = new JoyAxisEvent(stick.povY, y);
                listener.onJoyAxisEvent(evt1);
                listener.onJoyAxisEvent(evt2);
            } else if (id instanceof Axis) {
                float value = e.getValue();
                JoystickAxis axis = stick.axisIndex.get(e.getComponent());
                JoyAxisEvent evt = new JoyAxisEvent(axis, value);
                listener.onJoyAxisEvent(evt);
            } else if (id instanceof Button) {
                JoystickButton button = stick.buttonIndex.get(e.getComponent());
                JoyButtonEvent evt = new JoyButtonEvent(button, e.getValue() == 1f);
                listener.onJoyButtonEvent(evt);
            }
        }
    }
}
Also used : DefaultJoystickButton(com.jme3.input.DefaultJoystickButton) JoystickButton(com.jme3.input.JoystickButton) Identifier(net.java.games.input.Component.Identifier) JoyAxisEvent(com.jme3.input.event.JoyAxisEvent) JoyButtonEvent(com.jme3.input.event.JoyButtonEvent) DefaultJoystickButton(com.jme3.input.DefaultJoystickButton) JoystickButton(com.jme3.input.JoystickButton) Button(net.java.games.input.Component.Identifier.Button) JoyAxisEvent(com.jme3.input.event.JoyAxisEvent) JoyButtonEvent(com.jme3.input.event.JoyButtonEvent) JoystickAxis(com.jme3.input.JoystickAxis) DefaultJoystickAxis(com.jme3.input.DefaultJoystickAxis) JoystickAxis(com.jme3.input.JoystickAxis) DefaultJoystickAxis(com.jme3.input.DefaultJoystickAxis) Axis(net.java.games.input.Component.Identifier.Axis)

Aggregations

JoystickButton (com.jme3.input.JoystickButton)5 JoystickAxis (com.jme3.input.JoystickAxis)4 DefaultJoystickButton (com.jme3.input.DefaultJoystickButton)3 JoyButtonEvent (com.jme3.input.event.JoyButtonEvent)3 DefaultJoystickAxis (com.jme3.input.DefaultJoystickAxis)2 Joystick (com.jme3.input.Joystick)2 JoyAxisEvent (com.jme3.input.event.JoyAxisEvent)2 InputDevice (android.view.InputDevice)1 MotionRange (android.view.InputDevice.MotionRange)1 AbstractJoystick (com.jme3.input.AbstractJoystick)1 ByteBuffer (java.nio.ByteBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Identifier (net.java.games.input.Component.Identifier)1 Axis (net.java.games.input.Component.Identifier.Axis)1 Button (net.java.games.input.Component.Identifier.Button)1