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

Mouse move DPI on Input Events? (please change it to a better name!) #40579

Closed
renatodex opened this issue Jul 21, 2020 · 6 comments · Fixed by #40590
Closed

Mouse move DPI on Input Events? (please change it to a better name!) #40579

renatodex opened this issue Jul 21, 2020 · 6 comments · Fixed by #40590

Comments

@renatodex
Copy link

renatodex commented Jul 21, 2020

Godot version:
v.3.2.1 Stable

OS/device including version:
Macbook Pro 2017 13'' default model (macOS Mojave)

Issue description:
I have configured a mouse event to paint a Tilemap.
However, depending on the speed of your mouse movement, you can see several gaps between the painted tiles.
The greater is the speed, the greater is the number of Gaps.
Here's a video showcasing the issue:
https://share.getcloudapp.com/P8ueB6Qg

Steps to reproduce:

  1. Execute the project.
  2. Try to draw a slow line with your left mouse button.
  3. Now try to draw a very fast line.
  4. You should gap between the draw event.

Minimal reproduction project:
camera_drag_plus_set_tile.zip

Obs
Initially, I thought it was some issue with my mouse precision or something, but then I've noticed that when I'm painting in Tilemap with the Godot editor, I don't have this problem:
https://share.getcloudapp.com/mXuAePGZ

@renatodex
Copy link
Author

renatodex commented Jul 21, 2020

Hey, I was looking to other examples of people implementing "draw" events, and I found a Demo with the same problem in the Templates tab of Godot window. The demo implements a simple paint editor, you can find it searching for GD Paint.
The screenshot below is me trying to draw horizontal lines with different mouse speeds (by speed I mean manual velocity with my hand)

image

Notice how the number of empty gaps increases as long as you increase the drag speed.

@TheDuriel
Copy link
Contributor

TheDuriel commented Jul 22, 2020

Entirely expected, Godot does not simulate the traversal of the mouse from one point to another, as that would have undesired consequences for many applications.

The solution, is to do it yourself. Remember the position of the mouse of the previous frame, then draw a line from there to its current position. Instead of only at its current positions. Mice teleport, they don't move gradually.

This is caused by the speed at which the OS provides mouse information to Godot. Not necessarily related to frames rendered, but a faster system with unlocked main loop tick rate will perform better.

@renatodex
Copy link
Author

Hey @TheDuriel !
Thanks for the quick response!

So do you mean Godot editor actually implements this system you are talking when we draw in the editor?
https://share.getcloudapp.com/mXuAePGZ

As I shared in my initial post, I don't have this problem when I'm drawing in the Godot editor.

To be honest, I didn't quite get your idea of the algorithm, so I wanted to ask you if you could point me to some examples. Don't need to be in GDScript, any language would suffice, I just wasn't to understand the idea.

@TheDuriel
Copy link
Contributor

The editor will likely be implementing it.

In rough:

Every Frame:
if the button is held
get the mouse position
create an imaginary line from the current to the previous position
place tiles on every cell this line crosses
replace the previous mouse position with the current position

@Calinou
Copy link
Member

Calinou commented Jul 22, 2020

What @TheDuriel describes is called Bresenham's line algorithm. It's already implemented in the TileMap editor but not in the GridMap editor yet.

The current behavior works as designed, but we should find a place to document it. (None of this is specific to Godot, but it can still confuse people less familiar with input methods.)

@renatodex
Copy link
Author

Thanks so much for the explanations @Calinou and @TheDuriel , you guys are doing an amazing work!

akien-mga pushed a commit to akien-mga/godot that referenced this issue Jul 24, 2020
MarcusElg pushed a commit to MarcusElg/godot that referenced this issue Oct 19, 2020
huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants