Is there a replacement for Mouse.getDX() and Mouse.getDY() ?

Started by wartemw, May 05, 2017, 15:27:01

Previous topic - Next topic

wartemw

Is there a replacement for Mouse.getDX() and Mouse.getDY() ?

Kai

If you mean:
"Is there a replacement for LWJGL2's Mouse.getDX()/getDY() in LWJGL3 when using GLFW?"

You can very easily emulate it (implement it yourself):
All you need is the following:
- GLFW.glfwSetCursorPosCallback() - to read the current cursor position
- two class fields to store the old cursor position
- two class fields to hold the new cursor position or dx/dy computed in the GFW callback right away
- GLFW.glfwPollEvents()

wartemw

QuoteYou can very easily emulate it (implement it yourself):
All you need is the following:
- GLFW.glfwSetCursorPosCallback() - to read the current cursor position
- two class fields to store the old cursor position
- two class fields to hold the new cursor position or dx/dy computed in the GFW callback right away
- GLFW.glfwPollEvents()
After stopping the mouse, the value will not be 0. How do I fix it?

Kai

Think about it.
You have a loop which polls the mouse events once every iteration.
When there was a mouse movement, you set the "new" mouse coordinates to the corresponding coordinates given by the callback arguments. In addition, you also have "old" mouse coordinates stored in class fields.
What do you need to do in order for the difference between "new" and "old" coordinates to be the delta only in the current loop iteration and zero in the next?

wartemw

QuoteThink about it.
You have a loop which polls the mouse events once every iteration.
When there was a mouse movement, you set the "new" mouse coordinates to the corresponding coordinates given by the callback arguments. In addition, you also have "old" mouse coordinates stored in class fields.
What do you need to do in order for the difference between "new" and "old" coordinates to be the delta only in the current loop iteration and zero in the next?
Thank you! Figured out.