Search in sources :

Example 6 with Component

use of net.java.games.input.Component in project j6dof-flight-sim by chris-ali.

the class KeyboardVisitor method handleDeviceInput.

@Override
public void handleDeviceInput(Controller device) {
    if (!device.poll())
        return;
    for (Component component : device.getComponents()) {
        String componentName = component.getIdentifier().getName().toUpperCase();
        KeyCommand command = keyboardAssignments.get(componentName);
        if (command != null)
            actuator.handleParameterChange(command, component.getPollData());
        continue;
    }
}
Also used : Component(net.java.games.input.Component) KeyCommand(com.chrisali.javaflightsim.simulation.setup.KeyCommand)

Example 7 with Component

use of net.java.games.input.Component in project lwjgl by LWJGL.

the class JInputController method poll.

/*
	 * @see org.lwjgl.input.Controller#poll()
	 */
public void poll() {
    target.poll();
    Event event = new Event();
    EventQueue queue = target.getEventQueue();
    while (queue.getNextEvent(event)) {
        // handle button event
        if (buttons.contains(event.getComponent())) {
            Component button = event.getComponent();
            int buttonIndex = buttons.indexOf(button);
            buttonState[buttonIndex] = event.getValue() != 0;
            // fire button pressed event
            Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.BUTTON, buttonIndex, buttonState[buttonIndex], false, false, 0, 0));
        }
        // handle pov events
        if (pov.contains(event.getComponent())) {
            Component povComponent = event.getComponent();
            int povIndex = pov.indexOf(povComponent);
            float prevX = getPovX();
            float prevY = getPovY();
            povValues[povIndex] = event.getValue();
            if (prevX != getPovX()) {
                Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVX, 0, false, false));
            }
            if (prevY != getPovY()) {
                Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.POVY, 0, false, false));
            }
        }
        // handle axis updates
        if (axes.contains(event.getComponent())) {
            Component axis = event.getComponent();
            int axisIndex = axes.indexOf(axis);
            float value = axis.getPollData();
            float xaxisValue = 0;
            float yaxisValue = 0;
            // fixed dead zone since most axis don't report it :(
            if (Math.abs(value) < deadZones[axisIndex]) {
                value = 0;
            }
            if (Math.abs(value) < axis.getDeadZone()) {
                value = 0;
            }
            if (Math.abs(value) > axesMax[axisIndex]) {
                axesMax[axisIndex] = Math.abs(value);
            }
            // normalize the value based on maximum value read in the past
            value /= axesMax[axisIndex];
            if (axisIndex == xaxis) {
                xaxisValue = value;
            }
            if (axisIndex == yaxis) {
                yaxisValue = value;
            }
            // fire event
            Controllers.addEvent(new ControllerEvent(this, event.getNanos(), ControllerEvent.AXIS, axisIndex, false, axisIndex == xaxis, axisIndex == yaxis, xaxisValue, yaxisValue));
            axesValue[axisIndex] = value;
        }
    }
}
Also used : Event(net.java.games.input.Event) Component(net.java.games.input.Component) EventQueue(net.java.games.input.EventQueue)

Example 8 with Component

use of net.java.games.input.Component in project lwjgl by LWJGL.

the class LWJGLKeyboard method pollDevice.

public synchronized void pollDevice() throws IOException {
    if (!org.lwjgl.input.Keyboard.isCreated())
        return;
    org.lwjgl.input.Keyboard.poll();
    for (Component component : getComponents()) {
        Key key = (Key) component;
        key.update();
    }
}
Also used : Component(net.java.games.input.Component) AbstractComponent(net.java.games.input.AbstractComponent)

Example 9 with Component

use of net.java.games.input.Component in project j6dof-flight-sim by chris-ali.

the class MouseVisitor method handleDeviceInput.

@Override
public void handleDeviceInput(Controller device) {
    if (!device.poll())
        return;
    for (Component component : device.getComponents()) {
        Identifier componentIdentifier = component.getIdentifier();
        // Buttons
        if (componentIdentifier.getName().matches("^[0-9]*$")) {
            // Button index (nothing implemented yet)
            continue;
        }
        // to control deflection
        if (component.isRelative()) {
            float axisValue = component.getPollData() / 10;
            // Y axis (Elevator)
            if (componentIdentifier == Axis.Y) {
                if (axisValue != 0) {
                    tempElev += axisValue;
                    actuator.handleParameterChange(FlightControl.ELEVATOR, -(tempElev + trimElevator));
                }
                continue;
            }
            // X axis (Aileron)
            if (componentIdentifier == Axis.X) {
                if (axisValue != 0) {
                    tempAil += axisValue;
                    actuator.handleParameterChange(FlightControl.AILERON, -(tempAil + trimAileron));
                }
                continue;
            }
            // Z axis (Throttle)
            if (componentIdentifier == Axis.Z) {
                if (axisValue != 0) {
                    tempThrot += axisValue;
                    actuator.handleParameterChange(FlightControl.THROTTLE_1, tempThrot * 250);
                    actuator.handleParameterChange(FlightControl.THROTTLE_2, tempThrot * 250);
                }
                continue;
            }
        }
    }
}
Also used : Identifier(net.java.games.input.Component.Identifier) Component(net.java.games.input.Component)

Aggregations

Component (net.java.games.input.Component)9 Identifier (net.java.games.input.Component.Identifier)3 Event (net.java.games.input.Event)3 KeyCommand (com.chrisali.javaflightsim.simulation.setup.KeyCommand)2 AbstractComponent (net.java.games.input.AbstractComponent)2 JoystickAssignments (com.chrisali.javaflightsim.simulation.setup.ControlsConfiguration.JoystickAssignments)1 JoystickAxis (com.chrisali.javaflightsim.simulation.setup.JoystickAxis)1 Button (net.java.games.input.Component.Identifier.Button)1 Controller (net.java.games.input.Controller)1 EventQueue (net.java.games.input.EventQueue)1 ControllerInfo (org.terasology.config.ControllerConfig.ControllerInfo)1 ButtonState (org.terasology.input.ButtonState)1 Input (org.terasology.input.Input)1 ControllerAction (org.terasology.input.device.ControllerAction)1