Cybearg Posted April 27, 2014 Share Posted April 27, 2014 So say I want to calculate the distance between x1,y1 and x2,y2, or determine what angle sprite0 is in relation to sprite1 and then start moving sprite0 toward sprite1 as the crow flies. Are there any 6502 functions that exist (or could be written) to perform these maths quickly and efficiently? Quote Link to comment Share on other sites More sharing options...
Rybags Posted April 27, 2014 Share Posted April 27, 2014 (edited) Various things can be done/used. Lookup tables. Algorithms for fast (but not real accurate) square-root. For setting an object trajectory to move towards another, the Bresenham algorithm (used for line draw) could be employed. http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm In the line-draw, either X or Y is always inc/decremented by 1 each iteration, the other axis is fractional, and the movement decision is made by a simple add or subtract then compare operation. As an alternative, you could use the delta component from initial line-draw calculation as a table lookup value, have a table with 4, 8, 16, <whatever> sets of H/V velocity values per quadrant. It wouldn't be an exact path but close. On-the-fly updates would increase accuracy, plus once two objects are fairly close, the accuracy becomes much less important. Edited April 27, 2014 by Rybags 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.