Closed alfanhui closed 1 year ago
I think this is a good change, if only for that it is directly using fixed-point maths, and is an alternative method to SGL sine and cosine.
That said, it is using a lot of divisions. Sinus and co-sinus are not used often, so that is okay. All the same, having a fast approximate version would be a good idea.
Also, a VERY important note: REMOVE the use of the toFIXED macro. This multiplies by a floating point. That is VERY bad for performance. When converting an integer to a fixed-point, shift left by 16 (<<16). To convert a fixed to an integer, shift right by 16 (>>16).
Changelog:
Description: Here is a few math calculations to prove new cos(45degree) function accuracy:![image](https://user-images.githubusercontent.com/2172019/173664855-ec4b5494-0f48-49a8-b81e-2703953aed92.png)
You can compare sin/cos/tan values with this table at the 45 degrees mark: https://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1011&context=mathclass
I noticed this cos issue as I am creating a right-angle turn movement along a grid. In this gif, you can see when I turn right (EAST), the grid starts trailing off the screen, and then the other gif is with the fix:
Original cos():![old_cos](https://user-images.githubusercontent.com/2172019/173665853-5fa12e5d-02fc-4948-9779-7ce3cd25adcf.gif)
Fixed cos():![new_cos](https://user-images.githubusercontent.com/2172019/173665882-11709a76-fa3b-44e5-94ee-22003539481e.gif)
Interesting, sglCos is showing an inaccuracy as well.. i'll leave that for someone else to look into!