本文整理了Java中org.lwjgl.glfw.GLFW.glfwGetJoystickAxes()
方法的一些代码示例,展示了GLFW.glfwGetJoystickAxes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GLFW.glfwGetJoystickAxes()
方法的具体详情如下:
包路径:org.lwjgl.glfw.GLFW
类名称:GLFW
方法名:glfwGetJoystickAxes
[英]Returns the values of all axes of the specified joystick. Each element in the array is a value between -1.0 and 1.0.
If the specified joystick is not present this function will return NULL but will not generate an error. This can be used instead of first calling #glfwJoystickPresent.
The returned array is allocated and freed by GLFW. You should not free it yourself. It is valid until the specified joystick is disconnected, this function is called again for that joystick or the library is terminated.
This function must only be called from the main thread.
[中]返回指定操纵杆的所有轴的值。数组中的每个元素都是一个介于-1.0和1.0之间的值。
如果指定的操纵杆不存在,此功能将返回NULL,但不会生成错误。这可以用来代替第一次调用#glfwJoystickPresent。
返回的数组由GLFW分配和释放。你不应该自己把它放出来。在断开指定的操纵杆、再次调用该操纵杆的此功能或终止库之前,此功能一直有效。
只能从主线程调用此函数。
代码示例来源:origin: libgdx/libgdx
public Lwjgl3Controller(Lwjgl3ControllerManager manager, int index) {
this.manager = manager;
this.index = index;
this.axisState = new float[GLFW.glfwGetJoystickAxes(index).limit()];
this.buttonState = new boolean[GLFW.glfwGetJoystickButtons(index).limit()];
this.hatState = new byte[GLFW.glfwGetJoystickHats(index).limit()];
this.name = GLFW.glfwGetJoystickName(index);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
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;
if (joyButtonPressed.get(button) != pressed) {
joyButtonPressed.put(button, pressed);
listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
}
}
}
}
代码示例来源:origin: libgdx/libgdx
FloatBuffer axes = GLFW.glfwGetJoystickAxes(index);
if(axes == null) {
manager.disconnected(this);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
@Override
public Joystick[] loadJoysticks(final InputManager inputManager) {
for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) {
if (glfwJoystickPresent(i)) {
final String name = glfwGetJoystickName(i);
final GlfwJoystick joystick = new GlfwJoystick(inputManager, this, i, name);
joysticks.put(i, joystick);
final FloatBuffer floatBuffer = glfwGetJoystickAxes(i);
int axisIndex = 0;
while (floatBuffer.hasRemaining()) {
floatBuffer.get();
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), convertAxisIndex(axisIndex));
final JoystickAxis joystickAxis = new DefaultJoystickAxis(inputManager, joystick, axisIndex, convertAxisIndex(axisIndex), logicalId, true, false, 0.0f);
joystick.addAxis(axisIndex, joystickAxis);
axisIndex++;
}
final ByteBuffer byteBuffer = glfwGetJoystickButtons(i);
int buttonIndex = 0;
while (byteBuffer.hasRemaining()) {
byteBuffer.get();
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex));
final JoystickButton button = new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId);
joystick.addButton(button);
joyButtonPressed.put(button, false);
buttonIndex++;
}
}
}
return joysticks.values().toArray(new GlfwJoystick[joysticks.size()]);
}
代码示例来源:origin: org.jmonkeyengine/jme3-lwjgl3
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));
}
}
}
代码示例来源:origin: sriharshachilakapati/SilenceEngine
static void pollControllers()
{
for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; i++)
{
if (glfwJoystickPresent(i))
{
if (!Controller.states[i].connected)
((LwjglInputDevice) SilenceEngine.input).postControllerConnectionEvent(i, true);
ByteBuffer buttons = glfwGetJoystickButtons(i);
while (buttons.hasRemaining())
{
final boolean down = buttons.get() == 1;
SilenceEngine.input.postControllerButtonEvent(i, buttons.position() - 1, down, down ? 1 : 0);
}
FloatBuffer axes = glfwGetJoystickAxes(i);
while (axes.hasRemaining())
SilenceEngine.input.postControllerAxisEvent(i, axes.position(), axes.get());
}
else
{
if (Controller.states[i].connected)
((LwjglInputDevice) SilenceEngine.input).postControllerConnectionEvent(i, false);
}
}
}
代码示例来源:origin: sriharshachilakapati/SilenceEngine
private void postControllerConnectionEvent(int joystick, boolean connected)
{
ControllerConnectionEvent event = new ControllerConnectionEvent();
event.controllerConnected = connected;
event.isControllerIdeal = false;
event.controllerName = glfwGetJoystickName(joystick);
event.axisMapping = new Controller.Mapping();
event.buttonMapping = new Controller.Mapping();
event.numButtons = connected ? glfwGetJoystickButtons(joystick).capacity() : 0;
event.numAxes = connected ? glfwGetJoystickAxes(joystick).capacity() : 0;
postControllerConnectionEvent(joystick, event);
}
代码示例来源:origin: org.jmonkeyengine/jme3-lwjgl3
@Override
public Joystick[] loadJoysticks(final InputManager inputManager) {
for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) {
if (glfwJoystickPresent(i)) {
final String name = glfwGetJoystickName(i);
final GlfwJoystick joystick = new GlfwJoystick(inputManager, this, i, name);
joysticks.put(i, joystick);
final FloatBuffer floatBuffer = glfwGetJoystickAxes(i);
int axisIndex = 0;
while (floatBuffer.hasRemaining()) {
floatBuffer.get();
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), convertAxisIndex(axisIndex));
final JoystickAxis joystickAxis = new DefaultJoystickAxis(inputManager, joystick, axisIndex, convertAxisIndex(axisIndex), logicalId, true, false, 0.0f);
joystick.addAxis(axisIndex, joystickAxis);
axisIndex++;
}
final ByteBuffer byteBuffer = glfwGetJoystickButtons(i);
int buttonIndex = 0;
while (byteBuffer.hasRemaining()) {
byteBuffer.get();
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex));
joystick.addButton(new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId));
buttonIndex++;
}
}
}
return joysticks.values().toArray(new GlfwJoystick[joysticks.size()]);
}
内容来源于网络,如有侵权,请联系作者删除!