org.lwjgl.glfw.GLFW.glfwJoystickPresent()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.lwjgl.glfw.GLFW.glfwJoystickPresent()方法的一些代码示例,展示了GLFW.glfwJoystickPresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GLFW.glfwJoystickPresent()方法的具体详情如下:
包路径:org.lwjgl.glfw.GLFW
类名称:GLFW
方法名:glfwJoystickPresent

GLFW.glfwJoystickPresent介绍

[英]Returns whether the specified joystick is present.

This function must only be called from the main thread.
[中]返回指定的操纵杆是否存在。
只能从主线程调用此函数。

代码示例

代码示例来源:origin: libgdx/libgdx

void pollState() {
  if(!GLFW.glfwJoystickPresent(index)) {
    manager.disconnected(this);
    return;

代码示例来源:origin: libgdx/libgdx

void pollState() {
  for(int i = GLFW.GLFW_JOYSTICK_1; i < GLFW.GLFW_JOYSTICK_LAST; i++) {
    if(GLFW.glfwJoystickPresent(i)) {
      boolean alreadyUsed = false;
      for(int j = 0; j < controllers.size; j++) {
        if(((Lwjgl3Controller)controllers.get(j)).index == i) {
          alreadyUsed = true;
          break;
        }
      }
      if(!alreadyUsed) {
        Lwjgl3Controller controller = new Lwjgl3Controller(this, i);
        connected(controller);
      }
    }
  }
  
  polledControllers.addAll(controllers);
  for(Controller controller: polledControllers) {
    ((Lwjgl3Controller)controller).pollState();
  }
  polledControllers.clear();
}

代码示例来源: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: 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: 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()]);
}

相关文章

GLFW类方法