janriemer,

Me, trying to figure out how to implement basic drag functionality in #Bevy #BevyEngine UI without the cursor jumping to the mid-point of the dragged rectangle.😬

My head hurts!🥴 😪

#Struggle #Learning #Math #Geometry #2D #Graphics

mo8it,
@mo8it@fosstodon.org avatar

@janriemer Are you looking for the length of c?

What values are given?

janriemer,

@mo8it Basically yes. I try to calculate CSS relative position from the top-left parent rect for the red inner rect (think of CSS' top and left properties) when you drag the red inner rect.

And with my different calculations I've tried, I always manage it that all values cancel each other out, so when you try to drag the red inner most rectangle...nothing happens (but the code gets executed).😳

mo8it,
@mo8it@fosstodon.org avatar

@janriemer Well, then from what you drew, the length of c is for sure not length of a - length of b. Or are these vectors? In that case, yes, |a - b| = |c|

janriemer,

@mo8it Yes, I've drawn them as vectors, so the formular is correct (validated, because variables have been canceling each other out). 🙂

janriemer,

@mo8it Values that are given:

  • mouse position (dynamic, because when dragged, changes)
  • mid-point of red inner rect (dynamic, because when dragged, changes)
  • point at the top-left of red inner rect (dynamic, because when dragged, changes) <-- this is the thing I need to set, when dragged
  • point at the top-left of parent rect (static)
  • size of each rect (static)

I feel I'm creating an equation, where I have one variable on left side and one on the right side and they cancel each other out.

janriemer,

@mo8it I think I need to focus on the parent rect more and calculate from there and then derive values from this for the inner rect.

Otherwise my "values cancel each other out" will never stop, I fear. 😄

dpom,
@dpom@fosstodon.org avatar

@janriemer @mo8it If you capture the mouse position and center point when the drag is initiated, and calculate the starting position of the upper left corner by subtracting width/2 from x and adding height/2 to y, then after that, the (∆x, ∆y) of the mouse position (relative to its starting position) is also the (∆x, ∆y) for every other point on the rectangle (relative to their respective starting positions).

janriemer,

@dpom YES, thank you, Dusty!❤️🙏

I've come to more or less the same conclusion now (before reading your post). 😄

The crucial missing peace for me has been this: capture the mouse position and center point when the drag is initiated.

For context: I'm using bevy_drag&drop:
https://lib.rs/crates/bevy_dragndrop

but it has a bug in it and I'm trying to fix it. Currently, it doesn't store the starting mouse position and center point at drag-initiation at all, so I thought this shouldn't be necessary

@mo8it

janriemer,

@dpom @mo8it Yaaay, drag&drop works now! :awesome:

Thank you for your help in this! 🙂

Please see the video and screenshot below on how it's solved now.

(Video in the second toot, because apparently you can't attach both video and image in Mastodon).

#Bevy #BevyEngine

janriemer,
  • All
  • Subscribed
  • Moderated
  • Favorites
  • bevy
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines