gpt4 book ai didi

c++ - 使用 GLFW 捕获鼠标拖动? [C++]

转载 作者:太空狗 更新时间:2023-10-29 21:15:38 25 4
gpt4 key购买 nike

所以我试图在我的 OpenGL 应用程序中捕获鼠标拖动。到目前为止,我已经完成了以下工作:

glfwSetMouseButtonCallback(window, mouse_callback);

static void mouse_callback(GLFWwindow* window, int button, int action, int mods)
{
if (button == GLFW_MOUSE_BUTTON_LEFT) {
double x;
double y;
glfwGetCursorPos(window, &x, &y);

if (previous_y_position - y > 0)
{
camera_translation.y -= 1.0f;
previous_y_position = y;
}
else
{
camera_translation.y += 1.0f;
previous_y_position = y;
}
}
}

问题是如果我想放大我需要向上移动我的鼠标然后重复点击。出于某种原因,如果我按下鼠标左键并向上拖动,它什么也不做。

最佳答案

在 cursor_pos_callback 中,只要确认按钮是否被按下,就可以了。

void mouse_cursor_callback( GLFWwindow * window, double xpos, double ypos)  
{

if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_RELEASE)
{
return;
}

// `write your drag code here`
}

关于c++ - 使用 GLFW 捕获鼠标拖动? [C++],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37194845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com