# Pausing when handling mose movement through callback

**URL:** <https://discourse.glfw.org/t/pausing-when-handling-mose-movement-through-callback/638>\
**Category:** support\
**Created:** [April 19, 2016, 6:57pm UTC](https://discourse.glfw.org/t/pausing-when-handling-mose-movement-through-callback/638 "2016-04-19T18:57:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveG](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@SteveG](https://discourse.glfw.org/u/SteveG)\
**Post date:** [April 19, 2016, 6:57pm UTC](https://discourse.glfw.org/t/pausing-when-handling-mose-movement-through-callback/638/1 "2016-04-19T18:57:49Z")

</div>

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 {  
private:  
//Vectors  
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;  
//Status  
bool pressA, pressS, pressD, pressQ, pressW, pressE;  
double moveByMouseX, moveByMouseY;  
bool rMousePressed;

public:  
Camera(void);  
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);  
}  
[/code]

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 19, 2016, 9:31pm UTC](https://discourse.glfw.org/t/pausing-when-handling-mose-movement-through-callback/638/2 "2016-04-19T21:31:17Z")

</div>

Hi,

See the documentation on [glfwSetCursorPos](http://www.glfw.org/docs/latest/group__input.html#ga04b03af936d906ca123c8f4ee08b39e7). You should not use this function to implement things like camera controls, but instead use GLFW\_CURSOR\_DISABLED, see the documentation on [glfwSetInputMode](http://www.glfw.org/docs/latest/group__input.html#gaa92336e173da9c8834558b54ee80563b) for details.

So in the buttonEvent you should do seomthing like:

```
if (button == GLFW_MOUSE_BUTTON_LEFT) {
    if(GLFW_PRESS == action) {
        glfwSetInputMode(GLFW_CURSOR_DISABLED);
        rMousePressed = true;
    } else {
        glfwSetInputMode(GLFW_CURSOR_NORMAL);
        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.

---

<div class="post-metadata">

**Author:** ![SteveG](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@SteveG](https://discourse.glfw.org/u/SteveG)\
**Post date:** [April 20, 2016, 4:50pm UTC](https://discourse.glfw.org/t/pausing-when-handling-mose-movement-through-callback/638/3 "2016-04-20T16:50:19Z")

</div>

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.
