Jump to content
IGNORED

Fast Trigonometric Functions?


Cybearg

Recommended Posts

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?

Link to comment
Share on other sites

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 by Rybags
  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...