Hi guys, I'm making an Etch A Sketch program in C#. I have two buttons for the "knobs". Right now, I'm handling the mousemove event of the button to evaluate if the user is dragging the mouse up or down, and then updating the etch a sketch appropriatly.

This works fine, as long as you drag the mouse vertically. However, in real life, you rotate the knobs clockwise or counter clockwise. Can someone help me to puzzle out the algorithm to determine if they're dragging clockwise or counterclockwise?

I'm thinking something with comparing the current mouse coordinates with a previous "snapshot", but the answer is just beyond my thoughts. Can anyone help?

The problem with recognizing counter-clockwise or clockwise motion of the mouse pointer is that it takes time to recognize, which means that the UI will lag severely behind the user input. You'll find this to be unacceptable.

To be more specific, you'll need to look at the mouse pointer at a certain time, and then look at the mouse pointer at a later time, and then look at the mouse pointer at a time after that, and see that the direction in which the pointer is moving has changed a not-too-big amount to the left or right. The time between the first and last samples needs to be large enough to represent a real user action, and not just some mouse jiggle. But only _after_ the action is complete will you be able to apply the results of what you just saw.

One way to more realistically simulate clockwise or counter-clockwise turning is to see where the user first presses the mouse button. If he mousedowns to the right of the center of the knob, and drags up, he means to turn the knob counter-clockwise. If he mousedowns to the left of the center of the knob and drags up, he means to turn the knob clockwise. Take the vector from the center of the knob to the mousedown point, rotate it by 90 degrees, normalize it, and call it X. The displacement of the pointer in the direction X indicates how much the knob should be turned in a counter-clockwise direction. (You can compute this value by taking the current position of the cursor, subtracting the starting position of the cursor, and computing the dot product with X, then multiplying by a constant that controls how fast the knob should comfortably turn.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.