use of com.jme3.input.event.JoyButtonEvent in project jmonkeyengine by jMonkeyEngine.
the class AndroidJoystickJoyInput14 method onKey.
public boolean onKey(KeyEvent event) {
boolean consumed = false;
// logger.log(Level.INFO, "onKey event: {0}", event);
event.getDeviceId();
event.getSource();
AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
if (joystick != null) {
JoystickButton button = joystick.getButton(event.getKeyCode());
boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
if (button != null) {
JoyButtonEvent buttonEvent = new JoyButtonEvent(button, pressed);
joyInput.addEvent(buttonEvent);
consumed = true;
} else {
JoystickButton newButton = joystick.addButton(event.getKeyCode());
JoyButtonEvent buttonEvent = new JoyButtonEvent(newButton, pressed);
joyInput.addEvent(buttonEvent);
consumed = true;
}
}
return consumed;
}
use of com.jme3.input.event.JoyButtonEvent 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));
}
}
}
use of com.jme3.input.event.JoyButtonEvent 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);
}
}
}
}
Aggregations