com.jme3.input.event.JoyAxisEvent Java Examples

The following examples show how to use com.jme3.input.event.JoyAxisEvent. 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 jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) {
    Float last = lastValues.remove(evt.getAxis());
    float value = evt.getValue();
            
    // Check the axis dead zone.  InputManager normally does this
    // by default but not for raw events like we get here.
    float effectiveDeadZone = Math.max(inputManager.getAxisDeadZone(), evt.getAxis().getDeadZone());
    if( Math.abs(value) < effectiveDeadZone ) {
        if( last == null ) {
            // Just skip the event
            return;
        }
        // Else set the value to 0
        lastValues.remove(evt.getAxis());
        value = 0;
    }         
    setViewedJoystick( evt.getAxis().getJoystick() );            
    gamepad.setAxisValue( evt.getAxis(), value );
    if( value != 0 ) {
        lastValues.put(evt.getAxis(), value);
    } 
}
 
Example #2
Source File: AndroidJoyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update() {
    if (sensorJoyInput != null) {
        sensorJoyInput.update();
    }

    if (listener != null) {
        InputEvent inputEvent;

        while ((inputEvent = eventQueue.poll()) != null) {
            if (inputEvent instanceof JoyAxisEvent) {
                listener.onJoyAxisEvent((JoyAxisEvent)inputEvent);
            } else if (inputEvent instanceof JoyButtonEvent) {
                listener.onJoyButtonEvent((JoyButtonEvent)inputEvent);
            }
        }
    }

}
 
Example #3
Source File: AndroidJoystickJoyInput14.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean onGenericMotion(MotionEvent event) {
        boolean consumed = false;
//        logger.log(Level.INFO, "onGenericMotion event: {0}", event);
        event.getDeviceId();
        event.getSource();
//        logger.log(Level.INFO, "deviceId: {0}, source: {1}", new Object[]{event.getDeviceId(), event.getSource()});
        AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
        if (joystick != null) {
            for (int androidAxis: joystick.getAndroidAxes()) {
                String axisName = MotionEvent.axisToString(androidAxis);
                float value = event.getAxisValue(androidAxis);
                int action = event.getAction();
                if (action == MotionEvent.ACTION_MOVE) {
//                    logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}",
//                            new Object[]{androidAxis, axisName, value});
                    JoystickAxis axis = joystick.getAxis(androidAxis);
                    if (axis != null) {
//                        logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}, deadzone: {3}",
//                                new Object[]{androidAxis, axisName, value, axis.getDeadZone()});
                        JoyAxisEvent axisEvent = new JoyAxisEvent(axis, value);
                        joyInput.addEvent(axisEvent);
                        consumed = true;
                    } else {
//                        logger.log(Level.INFO, "axis was null for axisName: {0}", axisName);
                    }
                } else {
//                    logger.log(Level.INFO, "action: {0}", action);
                }
            }
        }

        return consumed;
    }
 
Example #4
Source File: GlfwJoystickInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void update() {
    for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) {

        // Axes
        final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey());

        // if a joystick is added or removed, the callback reloads the joysticks.
        // when the callback is called and reloads the joystick, this iterator may already have started iterating.
        // To avoid a NullPointerException we null-check the axisValues and bytebuffer objects.
        // If the joystick it's iterating over no-longer exists it will return null.

        if (axisValues != null) {
            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());

        if (byteBuffer != null) {
            for (final JoystickButton button : entry.getValue().getButtons()) {
                final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;

                if (joyButtonPressed.get(button) != pressed) {
                    joyButtonPressed.put(button, pressed);
                    listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
                }
            }
        }
    }
}
 
Example #5
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Callback from RawInputListener. Do not use.
 */
public void onJoyAxisEvent(JoyAxisEvent evt) {
    if (!eventsPermitted) {
        throw new UnsupportedOperationException("JoyInput has raised an event at an illegal time.");
    }

    inputQueue.add(evt);
}
 
Example #6
Source File: DefaultRawInputListener.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void onJoyAxisEvent( JoyAxisEvent evt ) {
}
 
Example #7
Source File: AndroidSensorJoyInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void onSensorChanged(SensorEvent se) {
        if (!loaded) {
            return;
        }
//        logger.log(Level.FINE, "onSensorChanged for {0}: accuracy: {1}, values: {2}",
//                new Object[]{se.sensor.getName(), se.accuracy, se.values});

        int sensorType = se.sensor.getType();

        SensorData sensorData = sensors.get(sensorType);
        if (sensorData != null) {
//            logger.log(Level.FINE, "sensorData name: {0}, enabled: {1}, unreliable: {2}",
//                    new Object[]{sensorData.sensor.getName(), sensorData.enabled, sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE});
        }
        if (sensorData != null && sensorData.sensor.equals(se.sensor) && sensorData.enabled) {

            if (sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
                return;
            }
            synchronized(sensorData.valuesLock) {
                for (int i=0; i<sensorData.lastValues.length; i++) {
                    sensorData.lastValues[i] = se.values[i];
                }
            }

            if (sensorData.axes.size() > 0) {
                AndroidSensorJoystickAxis axis;
                for (int i=0; i<se.values.length; i++) {
                    axis = sensorData.axes.get(i);
                    if (axis != null) {
                        axis.setCurRawValue(se.values[i]);
                        if (!sensorData.haveData) {
                            sensorData.haveData = true;
                        } else {
                            if (axis.isChanged()) {
                                JoyAxisEvent event = new JoyAxisEvent(axis, axis.getJoystickAxisValue());
//                                logger.log(Level.INFO, "adding JoyAxisEvent: {0}", event);
                                joyInput.addEvent(event);
//                                joyHandler.addEvent(new JoyAxisEvent(axis, axis.getJoystickAxisValue()));
                            }
                        }
                    }
                }
            } else {
                if (!sensorData.haveData) {
                    sensorData.haveData = true;
                }
            }

        }
    }
 
Example #8
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onJoyAxisEvent(JoyAxisEvent evt) {
}
 
Example #9
Source File: TestSoftwareMouse.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onJoyAxisEvent(JoyAxisEvent evt) {
}
 
Example #10
Source File: TestBitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) { }
 
Example #11
Source File: AbstractCameraController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onJoyAxisEvent(JoyAxisEvent jae) {
}
 
Example #12
Source File: RawInputListener.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Invoked on joystick axis events.
 * 
 * @param evt 
 */
public void onJoyAxisEvent(JoyAxisEvent evt);