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;
}
}
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;
}
}
}
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();
}
}
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;
}
}
}
}
Aggregations