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

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

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

GLFW.glfwSetCursorPos介绍

[英]Sets the position, in screen coordinates, of the cursor relative to the upper-left corner of the client area of the specified window. The window must have input focus. If the window does not have input focus when this function is called, it fails silently.

Do not use this function to implement things like camera controls. GLFW already provides the #GLFW_CURSOR_DISABLED cursor mode that hides the cursor, transparently re-centers it and provides unconstrained cursor motion. See #glfwSetInputMode for more information.

If the cursor mode is #GLFW_CURSOR_DISABLED then the cursor position is unconstrained and limited only by the minimum and maximum values of double.

Notes:

  • This function must only be called from the main thread.
  • Wayland: This function will only work when the cursor mode is #GLFW_CURSOR_DISABLED, otherwise it will do nothing.
    [中]设置光标相对于指定窗口的工作区左上角的位置(以屏幕坐标为单位)。窗口必须具有输入焦点。如果调用此函数时窗口没有输入焦点,则它会以静默方式失败。
    不要使用此功能来实现相机控制之类的功能。GLFW已经提供了#GLFW_CURSOR_DISABLED CURSOR mode(禁用光标模式),该模式隐藏光标,透明地将其重新居中,并提供无约束的光标运动。有关更多信息,请参见#glfwSetInputMode。
    如果光标模式为#GLFW_cursor_DISABLED,则光标位置不受约束,仅受double的最小值和最大值限制。
    笔记:
    *只能从主线程调用此函数。
    *Wayland:此功能仅在光标模式为#GLFW_cursor_禁用时工作,否则将不起任何作用。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Set the position of the cursor on the display.
 * @param x the x position of the cursor (pixel).
 * @param y the y position of the cursor (pixel).
 */
public void setCursorPosition(int x, int y) {
  if (!context.isRenderable()) {
    return;
  }
  
  glfwSetCursorPos(context.getWindowHandle(), x, y);	
}

代码示例来源:origin: FedUni/caliko

glfwSetCursorPos(windowId, ((double)mWindowWidth / 2), ((double)mWindowHeight / 2) );

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

@Override
public void setCursorPosition(int x, int y) {
  if(window.getConfig().hdpiMode == HdpiMode.Pixels) {
    float xScale = window.getGraphics().getLogicalWidth() / (float)window.getGraphics().getBackBufferWidth();
    float yScale = window.getGraphics().getLogicalHeight() / (float)window.getGraphics().getBackBufferHeight();
    x = (int)(x * xScale);
    y = (int)(y * yScale);
  }
  GLFW.glfwSetCursorPos(window.getWindowHandle(), x, y);		
}

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

@Override
public void setCursorPosition(int x, int y) {
  if(window.getConfig().hdpiMode == HdpiMode.Pixels) {
    float xScale = window.getGraphics().getLogicalWidth() / (float)window.getGraphics().getBackBufferWidth();
    float yScale = window.getGraphics().getLogicalHeight() / (float)window.getGraphics().getBackBufferHeight();
    x = (int)(x * xScale);
    y = (int)(y * yScale);
  }
  GLFW.glfwSetCursorPos(window.getWindowHandle(), x, y);		
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);

代码示例来源:origin: sriharshachilakapati/SilenceEngine

/**
 * <p> This method sets the position, in screen coordinates, of the cursor relative to the upper-left corner of the
 * client area of the window. The window must have input focus. If the window does not have input focus when this
 * method is called, it fails silently.</p>
 *
 * <p> <b>Do not use this method</b> to implement things like camera controls. GLFW already provides the
 * {@code GLFW_CURSOR_DISABLED} cursor mode that hides the cursor, transparently re-centers it and provides
 * unconstrained cursor motion. See {@link Window#setInputMode(int, int)} for more information.</p>
 *
 * <p> If the cursor mode is {@code GLFW_CURSOR_DISABLED} then the cursor position is unconstrained and limited
 * only by the minimum and maximum values of a double.</p>
 *
 * @param xPos The desired x-coordinate, relative to the left edge of the client area.
 * @param yPos The desired y-coordinate, relative to the top edge of the client area.
 */
public void setCursorPos(double xPos, double yPos)
{
  glfwSetCursorPos(handle, xPos, yPos);
}

代码示例来源:origin: Renanse/Ardor3D

@Override
public void setPosition(final int x, final int y) {
  GLFW.glfwSetCursorPos(_canvas.getWindowId(), x, y);
}

代码示例来源:origin: nifty-gui/nifty-gui

@Override
public void setMousePosition(final int x, final int y) {
 final IntBuffer xpos = IntBuffer.allocate(1);
 final IntBuffer ypos = IntBuffer.allocate(1);
 glfwGetWindowPos(glfwWindow, xpos, ypos);
 glfwSetCursorPos(glfwWindow, x - xpos.get(0), y - ypos.get(0));
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-backend-lwjgl3

@Override
public void setCursorPosition(int x, int y) {
  if(window.getConfig().hdpiMode == HdpiMode.Pixels) {
    float xScale = window.getGraphics().getLogicalWidth() / (float)window.getGraphics().getBackBufferWidth();
    float yScale = window.getGraphics().getLogicalHeight() / (float)window.getGraphics().getBackBufferHeight();
    x = (int)(x * xScale);
    y = (int)(y * yScale);
  }
  GLFW.glfwSetCursorPos(window.getWindowHandle(), x, y);		
}

相关文章

GLFW类方法