08-12-2013 10:54 AM - edited 08-12-2013 11:01 AM
Hello All,
Anyone who went to NI week and watched the fastest LabVIEW developer championship knows exactly what it is I am referring to when I say Knob Eyeballs. The task was to create a VI that had two Indicator knobs. These knobs were supposed to represent eyballs. Their purpose, to appear as though they are following the mouse cursor's movement. So where the mouse went, the knobs were to appear as though they were looking at and followed it's every movement. Both developers approached this the exact same way (which is probably really the only way) where they created an event structure and the event was mouse movement. From there, the event structure supplies both the vertical and horizontal values. However, the winner (sorry man, I forgot your name so I'll call you Person A) only supplied the horizontal to the knobs and when asked display, naturally he only moved his mouse form left to right. Thus the knobs did indeed follow the mouse, but only left to right. But the knobs can only do that to a small amount of accuracy before they are no longer "looking at the cursor." Say you move your mouse to the edge of the screen where the value will be 0, the knobs will be "looking down." Anyways, I have been putting way too much thought into this and I figured I'd allow the LabVIEW community take a stab it. I say props to the winner, but the other guy (Person B) was trying to incorporate both x and y coordinates into his knobs and may have been unfairly beaten (Person B ended up winning the whole thing anyways, so w/e). Can you do 360 degree knobs? Anyone got a much better and a lot more accurate way to do this?
Solved! Go to Solution.
08-12-2013 12:44 PM
My initial thoughts to all this is to use the x,y coords to calculate circle coords using sin,cos etc. But then it hit me, the problem is that the knobs are single dimension 0-n values. Is it possible to make the knobs dual choord dependent? Operate them on a x-y plane?
08-12-2013 12:46 PM
Adjust range of nobs to [0, 2pi].
Use property nodes to find center of nob (top left corner, control size)
Find position of mouse.
Use center of nob as origin, take screen coordinate system into account and find correct vector.
Find sin or cos of angle, invert for angle (in radians)
Write value to knob with property node.
08-12-2013 12:59 PM
Here you go (2009). I cheated a bit by placing the knob on the origin. If you want it to be in an arbitrary position, you need to get its center and subtract that from the coords.
08-12-2013 02:10 PM
I went ahead and completed the entire thing. Two eyeballs that follow the cursor and a mouth to stop it. 🙂
08-12-2013 02:34 PM
Not sure if it's what you wanted, but I did this in 12 minutes.
Had to fix two bugs: I needed to convert the properties to I32 to better do arithmetic, and had swapped X and Y on one of the SUBTRACT functions.
But it operates as two independent eyeballs.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
08-12-2013 05:40 PM
I was "Person B". 🙂 Multiple people have approached me saying they thought Robert's (Person A) solution wasn't complete. Thankfully, it didn't affect the final result of the contest. In truth, I'm glad he put me out of my misery on that question, since I had absolutely no idea how to solve it with both X/Y coordinates...it never even occurred to me to use trig to solve it. Which is kind of sad, given how much I loved trig in high school.
Kudos to all the math whizzes on this thread. 🙂
08-12-2013 10:57 PM - edited 08-12-2013 11:01 PM
Yes, using complex math is the way to go for a minimalist approach. Here's my quick attempt at all this. 😄
(Of course the FOR loop could be folded into a two-element complex array constant once the FP layout is finalized)
08-13-2013 01:19 AM
@altenbach wrote:
Yes, using complex math is the way to go for a minimalist approach. Here's my quick attempt at all this. 😄
@ Altenbach...
08-13-2013 03:55 AM
Of course, the real question is what would happen if it came to a duel?
Who would be the fastest? Maybe this VI (8.0) helps with that question?