Slide the mouse events GLFW

Slide the mouse events GLFW

The following is a glfw3.hmethod of sliding the mouse on the callback function provided:

/*! @brief Sets the scroll callback.
 *
 *  This function sets the scroll callback of the specified window, which is
 *  called when a scrolling device is used, such as a mouse wheel or scrolling
 *  area of a touchpad.
 *
 *  The scroll callback receives all scrolling input, like that from a mouse
 *  wheel or a touchpad scrolling area.
 *
 *  @param[in] window The window whose callback to set.
 *  @param[in] cbfun The new scroll callback, or `NULL` to remove the currently
 *  set callback.
 *  @return The previously set callback, or `NULL` if no callback was set or an
 *  error occurred.
 *
 *  @ingroup input
 */
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);

/*! @brief The function signature for scroll callbacks.
 *
 *  This is the function signature for scroll callback functions.
 *
 *  @param[in] window The window that received the event.
 *  @param[in] xoffset The scroll offset along the x-axis.
 *  @param[in] yoffset The scroll offset along the y-axis.
 *
 *  @sa glfwSetScrollCallback
 *
 *  @ingroup input
 */
typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);

Actual use, just call this method, you can receive a callback event to generate an event after sliding the mouse or touch pad.
Note that: the y-direction sliding the mouse only produce, xoffset always 0.

...
void GLFWBackendInit(int argc, char** argv, bool WithDepth, bool WithStencil)
{
    GLFWmonitor* pMonitor = isFullScreen ? glfwGetPrimaryMonitor() : NULL;

    s_pWindow = glfwCreateWindow(Width, Height, pTitle, pMonitor, NULL);

    if (!s_pWindow) {
        OGLDEV_ERROR0("error creating window");
        exit(1);
    }
    
    glfwMakeContextCurrent(s_pWindow);
    
    if (glfwInit() != 1) {
        OGLDEV_ERROR0("Error initializing GLFW");
        exit(1);
    }
    
	glfwSetScrollCallback(s_pWindow,ScrollCallback);
	
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glFrontFace(GL_CW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    
    while (!glfwWindowShouldClose(s_pWindow)) {
        s_pCallbacks->RenderSceneCB();        
        glfwSwapBuffers(s_pWindow);
        glfwPollEvents();
    }
}
...

static void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) {
   	m_pGameCamera->m_pos.z += yoffset;
	m_pGameCamera->m_pos.x += xoffset;
	cout << "Scroll: (" << xoffset << "," << yoffset << ")" << endl;
}

Output:
Output
Found effect: a sliding unit for each wheel (mouse wheel one mechanical tactile feedback generation) to produce a slip event yoffset = 1.0.

Published 23 original articles · won praise 5 · Views 1843

Guess you like

Origin blog.csdn.net/QQ275176629/article/details/104197440