Sign in to follow this  
kc_0045

SDL/CPP Basic Move Towards Point Help?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this