Hello Guest

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

  • 4 Replies
  • 6038 Views
Is there a replacement for Mouse.getDX() and Mouse.getDY() ?

*

Kai

Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
« Reply #1 on: May 05, 2017, 16:19:00 »
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()

Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
« Reply #2 on: May 06, 2017, 01:44:00 »
Quote
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()
After stopping the mouse, the value will not be 0. How do I fix it?

*

Kai

Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
« Reply #3 on: May 06, 2017, 09:47:46 »
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?

Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
« Reply #4 on: May 06, 2017, 14:46:19 »
Quote
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?
Thank you! Figured out.