Link to home
Start Free TrialLog in
Avatar of Snapples
Snapples

asked on

Converting mouse x,y to a speed

I making a non MFC application in VC++ involving some physics. I want to click my mouse somewhere in the window, drag it to some place and release my mousebutton. How would I be able to calculate the speed of that mousemovement?
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> How would I be able to calculate the speed of that mousemovement?
Speed == distance/time so I guess you take a time reference when the mouse is clicked, take another when the mouse button is released, figure out how far it's traveled and then do the math to get the speed. Are you are after a code sample?
The other thing, of course, is that speed is relative to direction, so the speed in direction x is not necessarily the same as that in direction y so are you after an average or 2 separate values?
Avatar of Snapples
Snapples

ASKER

Well, the point is that I have a paddle, which I can drag by moving the mouse. When it hits a ball, I need to pass a speed value to that ball, depending on the speed of the paddle.
I thought about using time references, but then when I hold the mouse button without moving the mouse, and move it after say 10 seconds, the speed won't be correct because the time reference has started 10 seconds before the actual movement did.
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial