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?
Game ProgrammingEditors IDEsC++

Avatar of undefined
Last Comment
jkr

8/22/2022 - Mon
evilrix

>> 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?
evilrix

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?
ASKER
Snapples

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
evilrix

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.