In this function Center is the center of my veiwscreen, Zoom is how much I am zoomed in, and SetVeiw() resets my veiw to take into account all of my changes. When I set this function at the beginning of my program, everything worked fine. But I wanted to only move the camera when I right-clicked, so I made this function:
void GLFWCALL Ortho::MouseButtonCallback(int Button, int Action)
{
if(Button==GLFW_MOUSE_BUTTON_RIGHT)
{
switch(Action)
{
case GLFW_PRESS:
{
This->CameraMoveOn=true;
glfwDisable(GLFW_MOUSE_CURSOR);
glfwSetMousePosCallback(MousePosCallback);
break;
}
case GLFW_RELEASE:
{
This->CameraMoveOn=false;
glfwEnable(GLFW_MOUSE_CURSOR);
glfwSetMousePosCallback(NULL);
}
}
}
Now, whenever I first right-click, the center of my screen jumps. I tried adding glfwSetMousePos(0,0); In the press case, but it didn’t help.
Anyone have anything? I stopped trying a while ago. Now I’ve come back to it, and I still can’t come up with anything. My solution so far has been to get rid of glfwDisable(GLFW_MOUSE_CURSOR);
case GLFW_PRESS:
{
This->CameraMoveOn=true;
glfwSetMousePos(This->WindowSize.X/2,This->WindowSize.Y/2);
glfwSetMousePosCallback(MousePosCallback);
break;
}
Sorry for not replying. I haven’t had the time to look at this. Here is a hint though: you shouldn’t call GLFW functions from within callback functions, except for glfwGetXYZ (e.g. glfwGetKey, glfwGetMousePos etc).
This is not mentioned in the GLFW 2.4 docs, but I have added a section about it in the GLFW 2.5 reference manual.
Calling glfwSetMousePos from the mouse callback may disorient the internal GLFW mouse handling. You should be able to find another solution for this (e.g. delay the GLFW call(s) to after the event polling call).