How to Measure Speed in Java?
Greetings, everyone. Before I explain the title, I just want to introduce what I'm trying to do:
I have a series of images. Mostly a body with two arms. It responds to the movement of the mouse. When the mouse moves, I want the arms to rotate backwards, as if dealing with a lot of air resistance. I have no problems with the rotation, the only issue is I want the arms to flail back more and more the faster the mouse is moving.. But then, how do I measure the speed of the mouse? Is there a way to measure how much pixels the mouse is covering when it moves over a certain amount of time? Or is there another method to get different results of an action to occur when dealing with various speeds of MouseMotion movement?
I hope this isn't too vague. If you need any clarifications in order to help me out with this issue, feel free to let me know
Re: How to Measure Speed in Java?
The mouse's position and the time the mouse was at that position should allow you to compute a speed:
change in position/change in time.
The System class has a method that returns the current system time.