How to rotate an image clockwise or anticlockwise with mouse movement???
-
I am able to rotate a medical image individually one by one i.e by commenting the clockwise rotation code it is getting rotated in anticlockwise direction and by commenting the anticlockwise code it is getting rotated in clockwise direction, this much able to achieve, here there is no issue, able to do it.
But now I want it to function like:- Uncommenting both clockwise and anticlockwise codes simultaneously, image should get rotated to clockwise direction if my mouse is moving in clockwise direction and in anticlockwise if my mouse is moving in anticlockwise direction.
I am trying to achieve it using if-else like:-
If (Some condition or equation)
{
Image rotation code Anticlockwise(I have this code already)
}
else
{
Image rotation code Clockwise(I have this code also)
} -
Can anyone please show the way how to go about it???
(Some condition or equation) part is what I want to know about, because the different equations or logic I have applied either let the control only in if loop and if by using other logic it goes to the else part, then the image gets distorted. -
I'm not sure I understand what you want to achieve. You also gave no information how you're painting your image, so it's difficult to suggest something. Is it a paint event on a widget, a graphics scene item, QML element, OpenGL object or something else?
In a general sense though, if it's just painting a rotated image based on mouse move then you can do it like this: instead of a separate code that rotates an image clockwise or anticlockwise make one function that rotates image by an angle given as a parameter. Then have an angle variable somewhere. In mouse event handler you increase the angle variable if mouse moved one way and decrease when mouse moved the other way. After you modify the angle call update() to cause repaint. In paint event you just call your rotation method with the current angle value.
-
itnercept the mouse move event, pull the x,y coordinates, and compare them to the last mouse move coordinates you pulled. That will allow you to calculate the "direction". The implementation is left as an exercise for the OP.
-
@Kent-Dorfman , @Chris-Kawa
For this question see https://forum.qt.io/topic/139937/how-to-detect-whether-mouse-is-moving-in-clockwise-or-anticlockwise-direction-just-through-mouse-movement-or-mouse-draggingThe point is: The current OP here posted exactly the same question under a different username in that topic 14 days ago. There I referred him to several stackoverflow posts which describe algorithms/C++ code for detecting clockwise/anti-clockwise mouse drag rotation detection. He confirmed that he looked at 4 posts there.
However, he announced that all these solutions are "wrong" and "do not work", with no explanation/justification from him. When I pointed out it was "unlikely" all posts were wrong and his code was right, he ceased posting there and stated it was "quarrelling". And has opened this new topic with the same question.
So he is now looking for a solution from someone which somehow does not repeat the correct answers from stackoverflow....