Jump to content
  • Advertisement
Sign in to follow this  
kc_0045

SDL/CPP Basic Move Towards Point Help?

This topic is 3067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So yeah, this should be simple but idk it just isnt working, im stumped. Trying to get LastDrawnx and LastDrawny to smoothly follow Mousex,Mousey so when ondraw is called it draws it smoothly. (for drawing a line) The code below would be in a while loop with something like while(dis>1) so it loops till it gets close(incase of fast mouse movement causing effects to look weird.) mOffsetx=Mousex-LastDrawnx; mOffsety=Mousey-LastDrawny; float fx=(float)mOffsetx; float fy=(float)mOffsety; float legth =sqrt( (fx*fx) + (fy*fx) ); if(((int)legth)!=0) { mOffsetx/=(int)legth; mOffsety/=(int)legth; } LastDrawnx+=mOffsetx; LastDrawny+=mOffsety; CSurface::OnDraw(Surf_Display, Surf_Brush, LastDrawnx,LastDrawny); it sorta gets to the mouse....but it acts all random and doesnt follow a pattern to my mouse.

Share this post


Link to post
Share on other sites
Advertisement
You have a typo where an 'x' should be a 'y'.

Also, to have this line animate you will need to draw each iteration over multiple frames... Unless OnDraw is doing something magical I don't know about.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!