I’m facing some problem using sin/cos Look Up Table from fixmath.h
Here my code:
#include "Pokitto.h"
#include "fixmath.h"
Pokitto::Core g;
Pokitto::Display d;
int main ()
{
g.begin();
while (g.isRunning())
{
if (g.update())
{
Fix16 toRad=fix16_from_float(PI/180.0);
Fix16 radius=fix16_from_int(30);
for(int a=0; a<360; a+=15)
{
Fix16 angle=fix16_from_int(a);
Fix16 angleRad=angle * toRad;
Fix16 xtf=fix16_mul(fix16_sin(angleRad),radius);
Fix16 ytf=fix16_mul(fix16_cos(angleRad),radius);
int xt=55+fix16_to_int(xtf);
int yt=44+fix16_to_int(ytf);
d.drawLine(55,44,xt,yt);
}
}
}
}
And here the result:
It should draw a line starting from the center of the screen every 15 degrees with a radius of 30 pixel.
From my test sin cos output are wrong.
Does anyone use sin cos from fixmath.h before?
Don’t you think the fix is suspicious?
From the code it seems fix16_sin is expecting inAngle to be radians, in fact it apply modulo of 2PI at the begin.
But then you have to normalized the tempAngle to 0-255 value, to correctly access the look up array.
The exactly original same code is all scattered in the web if you make a search, how is it possible nobody fix it?
It could be that it’s been reported but not acted upon.
It could be that the version bundled with the PokittoLib is out of date.
It could be that hardly anyone is actually using the library.
I have no clue about that Tau thingy But I made a PR of the fix. This time I tried to make it on-the-go, using only the GitHub web interface: created a branch, edited a file, committed, created a PR. Very handy for small, pre-tested, changes like this!