Pausing when handling mose movement through callback

Trying to implement camera movement by using the mouse movement callback when left click is pressed, but every time nothing happens right when clicking and once i start dragging everything pauses until I release the mouse button. Pertinent code below.

[code]class Camera {
glm::vec3 position;
glm::vec3 facing;
glm::vec3 right;
glm::vec3 up;
glm::mat4 view;
//Viewing angles
float horizontalAngle;
float verticalAngle;
//Movement speeds
float moveSpeed;
float rotateSpeed;
float mouseSpeed;
bool pressA, pressS, pressD, pressQ, pressW, pressE;
double moveByMouseX, moveByMouseY;
bool rMousePressed;

void update(double t);
glm::mat4 render(void);

//Forward callback
void keyEvent(GLFWwindow* window, int key, int scancode, int action, int mods);
void mouseEvent(GLFWwindow* window, double xpos, double ypos);
void buttonEvent(GLFWwindow* window, int button, int action, int mods);


void Camera::mouseEvent(GLFWwindow* window, double xpos, double ypos) {
if (rMousePressed) {
int x, y;
glfwGetWindowSize(window, &x, &y);
moveByMouseX += (x / 2) - xpos;
moveByMouseY += (y / 2) - ypos;
glfwSetCursorPos(window, x / 2, y / 2);

void Camera::buttonEvent(GLFWwindow* window, int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_LEFT) {
rMousePressed = (bool)action;

void Camera::update(double t) {
horizontalAngle += moveByMouseX * mouseSpeed * t;
verticalAngle += moveByMouseY * mouseSpeed * t;
moveByMouseX = 0.0f;
moveByMouseY = 0.0f;
if (verticalAngle > 45.0f)
verticalAngle = 45.05f;
if (verticalAngle < -45.0f)
verticalAngle = -45.0f;
facing = glm::vec3(cos(verticalAngle) * sin(horizontalAngle), sin(verticalAngle), cos(verticalAngle)*cos(horizontalAngle));
right = glm::vec3(sin(horizontalAngle - 3.14f / 2.0f), 0, cos(horizontalAngle - 3.14f / 2.0f));
up = glm::cross(right, facing);
view = glm::lookAt(position, position + facing, up);


See the documentation on glfwSetCursorPos. You should not use this function to implement things like camera controls, but instead use GLFW_CURSOR_DISABLED, see the documentation on glfwSetInputMode for details.

So in the buttonEvent you should do seomthing like:

if (button == GLFW_MOUSE_BUTTON_LEFT) {
    if(GLFW_PRESS == action) {
        rMousePressed  = true;
    } else {
        rMousePressed  = false;

And you need to remove the call to glfwSetCursorPos and keep track of the previous xpos and ypos of the mouse so you can set your moveByMouse variables correctly.

Hope this helps.

Thanks! This gets me a lot closer, though there’s still some odd behavior. I believe it is in how I am setting and tracking the last position along with the amount moved though, so I should be able to track it down.