LWJGL Forum

Programming => OpenGL => Topic started by: wartemw on May 05, 2017, 15:27:01

Title: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Post by: wartemw on May 05, 2017, 15:27:01
Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Title: Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Post by: Kai 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()
Title: Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Post by: wartemw on May 06, 2017, 01:44:00
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?
Title: Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Post by: Kai 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?
Title: Re: Is there a replacement for Mouse.getDX() and Mouse.getDY() ?
Post by: wartemw on May 06, 2017, 14:46:19
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.