Page 1 of 1

Why does this knob wobble?

Posted: Mon May 20, 2013 2:48 pm
by MouseUp
Can someone tell me why this knob wobbles slightly when I turn it? Does the graphic frame need to be round (not square)?

Re: Why does this knob wobble?

Posted: Mon May 20, 2013 3:43 pm
by dunbarx
Hi..
I tried this:

on mouseMove x,y
if the mouse is down then
set the angle of me to 200 + y
put the loc of me
end if
end mouseMove

The loc shifts slightly, as you can see. I suspect that your image is not symmetrical.

Craig Newman

Re: Why does this knob wobble?

Posted: Mon May 20, 2013 3:53 pm
by Randy Hengst
Have you tried a png file with transparent background?

Re: Why does this knob wobble?

Posted: Mon May 20, 2013 6:56 pm
by sturgis
Might be easier to do this with graphic objects and groups.

Here is an example using 2 graphics grouped together. https://dl.dropboxusercontent.com/u/119 ... t.livecode

If you use are using a graphic, if I recall correctly, the original graphic needs to have odd dimensions rather than even, and should be the same size as the final solution if possible (to minimize any weird rounding errors that might occur)

You can also get a slight improvement with your current graphic if you set the quality to best, and always reset the "loc" to the starting point. There is still some wobble due to the dimensioning and that the exact center point of the knob is also not the exact center point of the image object.

This is the "always set the loc.." method.

Code: Select all

on mouseMove x,y
   lock screen
   put the loc of me into tLoc
   if the mouse is down then set the angle of me to 200 + y
   set the loc of me to tLoc
   unlock screen
end mouseMove

Re: Why does this knob wobble?

Posted: Mon May 20, 2013 11:48 pm
by dunbarx
I tried the odd dimension thing, since we want to have an equal extent of the graphic about a central point in both axes. But this did not help.

This works, though:

on mouseMove x,y
if the mouse is down then
lock screen
get the loc of me
set the angle of me to 200 + y
set the loc of me to it
unlock screen
end if
end mouseMove

Craig Newman

EDIT:

Sorry Sturgis, I did not read through your latest. I am chagrined.

Re: Why does this knob wobble?

Posted: Tue May 21, 2013 12:05 am
by sturgis
Consensus is a good thing. Chagrinning not allowed.

Re: Why does this knob wobble?

Posted: Tue May 21, 2013 2:03 pm
by MouseUp
Craig, thanks. That seems to work well, though I must admit I don't know why! Any explanation?

Re: Why does this knob wobble?

Posted: Tue May 21, 2013 2:18 pm
by sturgis
When setting the angle, you're rotating a square object in a linear grid, and points will not always match up. The engine does its best to keep things in perspective, but due to rounding/truncating there is some imperfection involved and the dimensions of the image change very slightly due to all of this. Setting the center point of the image back to the place it started before the adjustments helps keep any right/left/up/down shift in the image due to rounding from being as noticeable.

If you are curious and want to see the cumulative effects of these rounding errors, try the same thing using rotate (with an image you don't mind getting toasted inside of rev, keep original safe)

Rotate has to do the same type of point to point mapping for each pixel, but unlike setting the angle (which always uses the original data as the starting point) rotate actually changes the imagedata itself on each rotate. So rotate it once, the image itself changes (rather than just being temporarily mapped like angle) rotate it again and it uses the current slightly distorted image data. Each "rotate" will cause further distortion. Sometimes you end up with a really interesting looking mess, sometimes it is just a mess.

Re: Why does this knob wobble?

Posted: Tue May 21, 2013 2:38 pm
by dunbarx
Hi.

I came in second (after Sturgis) for essentially the same script.

Try this. Make a rectangular graphic named "r1". Put both of these into the image script:

on mouseMove x,y --wobbles
if the mouse is down then
set the angle of me to 200 + y
set the rect of grc "r1" to the rect of me
put the loc of me & return & the rect of me & return & the loc of grc "r1"
end if
end mouseMove

on mouseMove x,y --fixed
if the mouse is down then
lock screen
get the loc of me
set the angle of me to 200 + y
set the loc of me to it
set the rect of grc "r1" to the rect of me
put the loc of me & return & the rect of me & return & the loc of grc "r1"
unlock screen
end if
end mouseMove

If you move the mouse very slowly in the uncorrected handler, you will see that every few pixels the image jumps, and it shifts in relation to its rect.

That is why if you explicitly reset the loc each time you change the angle, the visual aspect of the image stays put. The screen has to be locked so that you do not notice the one pixel correection.

I think...

Craig

Re: Why does this knob wobble?

Posted: Tue May 21, 2013 3:00 pm
by MouseUp
I guess it's cool when Weebles Wobble but not knobs. Thanks all.