Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First nonzero mouse_delta_ndc() is very large #188

Open
kbarros opened this issue Feb 25, 2018 · 8 comments
Open

First nonzero mouse_delta_ndc() is very large #188

kbarros opened this issue Feb 25, 2018 · 8 comments

Comments

@kbarros
Copy link

kbarros commented Feb 25, 2018

I put the following line of code in my win.update() loop:

println!("{:?}", win.input.mouse_delta_ndc());

At first, the program prints exactly Vector2 [0.0, 0.0]. Once the mouse moves, I first get a single very large delta, of order 0.5. And then after that, mouse motion gives meaningful deltas, of order 0.001 (corresponding to a few pixels of movement).

I would have expected that all return values of mouse_delta_ndc() correspond to actual mouse deltas.

@vitvakatu
Copy link
Member

To fix this, we probably need to store initial mouse position on Input initialization, or (less likely) move pointer in the center of the screen. @kbarros don't you want to try to fix that? I can provide you all the neccessary help.

@kbarros
Copy link
Author

kbarros commented Feb 26, 2018

Yes, I can try to help.

It seems the best way would be to store mouse position on Input initialization, but I can't see how to get this information from glutin. (There are methods like glutin::Window::set_cursor_position but I can't find any get_cursor_position.)

Another option is to store f32::NAN for the initial values of mouse_pos and mouse_ndc. Then we could have logic to drop the first mouse delta.

@vitvakatu
Copy link
Member

Heh, indeed. There's no method to get mouse position (without using event loop). Okay, then we should try approach with setting cursor to the center of the window on start. I don't like idea with NaNs, it seems harder and possibly more dangerous.

@kbarros
Copy link
Author

kbarros commented Feb 26, 2018

It seems unfortunate that we should have to move the cursor to fix a bug that very few people will run into :-) If you don't like NaNs, a semantically equivalent option is to put the mouse_pos and mouse_ndc within Options to indicate that they are not initially valid.

@vitvakatu
Copy link
Member

Well, you can try, but I think the internal structure of our code will be overengineered then. The approach with moving cursor will envolve a very small code injection in one place, while you'll need to change a lot of logic to use Option or NaNs

@kbarros
Copy link
Author

kbarros commented Feb 26, 2018

The necessary changes are actually quite minimal: https://github.com/kbarros/three/commit/faf9e58f8cc685c8f420327e961939d58adfd6e4

Note that we may wish to change Input::mouse_pos() and Input::mouse_pos_ndc() to return an Option, which indicates that three-rs does not necessarily know the mouse position. (Alternatively, we could simply return (0,0) for this case.)

@kbarros
Copy link
Author

kbarros commented Feb 26, 2018

On second thought, maybe this should be closed as "won't fix" until glutin gets the ability to query the mouse position?

@kvark
Copy link
Collaborator

kvark commented Feb 27, 2018

We can keep it for tracking, marking as blocked for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants