Search in sources :

Example 6 with JoystickAxis

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

the class TestJoystick method dumpJoysticks.

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);
        }
    }
}
Also used : JoystickButton(com.jme3.input.JoystickButton) Joystick(com.jme3.input.Joystick) JoystickAxis(com.jme3.input.JoystickAxis)

Example 7 with JoystickAxis

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

the class TestJoystick method setViewedJoystick.

protected void setViewedJoystick(Joystick stick) {
    if (this.viewedJoystick == stick)
        return;
    if (this.viewedJoystick != null) {
        joystickInfo.detachAllChildren();
    }
    this.viewedJoystick = stick;
    if (this.viewedJoystick != null) {
        // Draw the hud
        yInfo = 0;
        addInfo("Joystick:\"" + stick.getName() + "\"  id:" + stick.getJoyId(), 0);
        yInfo -= 5;
        float ySave = yInfo;
        // Column one for the buttons
        addInfo("Buttons:", 0);
        for (JoystickButton b : stick.getButtons()) {
            addInfo(" '" + b.getName() + "' id:'" + b.getLogicalId() + "'", 0);
        }
        yInfo = ySave;
        // Column two for the axes
        addInfo("Axes:", 1);
        for (JoystickAxis a : stick.getAxes()) {
            addInfo(" '" + a.getName() + "' id:'" + a.getLogicalId() + "' analog:" + a.isAnalog(), 1);
        }
    }
}
Also used : JoystickButton(com.jme3.input.JoystickButton) JoystickAxis(com.jme3.input.JoystickAxis)

Example 8 with JoystickAxis

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

the class GlfwJoystickInput method update.

public void update() {
    for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) {
        // Axes
        final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey());
        for (final JoystickAxis axis : entry.getValue().getAxes()) {
            final float value = axisValues.get(axis.getAxisId());
            listener.onJoyAxisEvent(new JoyAxisEvent(axis, value));
        }
        // Buttons
        final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey());
        for (final JoystickButton button : entry.getValue().getButtons()) {
            final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;
            listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
        }
    }
}
Also used : JoyAxisEvent(com.jme3.input.event.JoyAxisEvent) JoyButtonEvent(com.jme3.input.event.JoyButtonEvent) FloatBuffer(java.nio.FloatBuffer) Map(java.util.Map) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer)

Example 9 with JoystickAxis

use of com.jme3.input.JoystickAxis 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

JoystickAxis (com.jme3.input.JoystickAxis)8 Joystick (com.jme3.input.Joystick)5 JoystickButton (com.jme3.input.JoystickButton)4 DefaultJoystickAxis (com.jme3.input.DefaultJoystickAxis)3 SensorJoystickAxis (com.jme3.input.SensorJoystickAxis)3 JoyAxisEvent (com.jme3.input.event.JoyAxisEvent)3 DefaultJoystickButton (com.jme3.input.DefaultJoystickButton)2 JoyButtonEvent (com.jme3.input.event.JoyButtonEvent)2 IntMap (com.jme3.util.IntMap)2 InputDevice (android.view.InputDevice)1 MotionRange (android.view.InputDevice.MotionRange)1 AbstractJoystick (com.jme3.input.AbstractJoystick)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 Material (com.jme3.material.Material)1 Geometry (com.jme3.scene.Geometry)1 Mesh (com.jme3.scene.Mesh)1 Box (com.jme3.scene.shape.Box)1 Line (com.jme3.scene.shape.Line)1 Texture (com.jme3.texture.Texture)1 ByteBuffer (java.nio.ByteBuffer)1