better rad-to-theta angle conversion impl
This commit is contained in:
parent
d74916f4c8
commit
7b1bf06223
|
@ -21,6 +21,7 @@ extern FIXED HALF;
|
|||
extern FIXED ONE;
|
||||
extern FIXED TWO;
|
||||
|
||||
#define SIN_LUT_MAX ((512 << 6) * 2) // 65536, FFFFh range
|
||||
#define FIX12_SHIFT 12
|
||||
#define FIX12_SCALE ( 1<<FIX12_SHIFT )
|
||||
|
||||
|
@ -53,7 +54,7 @@ INLINE float gr2rad(uint grad) {
|
|||
}
|
||||
|
||||
INLINE FIXED gr2lut(uint grad) {
|
||||
return 65535 / (360 / (grad % 360));
|
||||
return SIN_LUT_MAX / (360 / (grad % 360));
|
||||
}
|
||||
|
||||
INLINE FIXED rad2lut(float rad) {
|
||||
|
@ -61,8 +62,9 @@ INLINE FIXED rad2lut(float rad) {
|
|||
}
|
||||
|
||||
INLINE FIXED fxrad2lut(FIXED rad) {
|
||||
// TODO NOT good; too much divisions, but hey, fuck it
|
||||
return rad2lut(fx2float(rad));
|
||||
// TODO could be better without fx2float() ?
|
||||
int scale = fx2float(rad) / (2*M_PI / 512);
|
||||
return (scale << 6) * 2;
|
||||
}
|
||||
|
||||
INLINE float fx12ToFloat(FIXED fx) {
|
||||
|
|
|
@ -40,6 +40,23 @@ TEST_F(FpSuite, LUTValueTests) {
|
|||
ASSERT_EQ(rnd(sinLutConv8), 0.995f);
|
||||
}
|
||||
|
||||
TEST_F(FpSuite, SinLookupTests) {
|
||||
int degrees = 360;
|
||||
float radians = gr2rad(degrees);
|
||||
std::cout << degrees << " in rad " << radians << std::endl;
|
||||
|
||||
float sinhalf = sin(radians);
|
||||
ASSERT_FLOAT_EQ(rnd(sinhalf), 0.0049999999);
|
||||
|
||||
float sinlumax = fx2float(fx12Tofx8(lu_sin(SIN_LUT_MAX)));
|
||||
ASSERT_FLOAT_EQ(rnd(sinlumax), 0.0049999999);
|
||||
|
||||
int scale = radians / (2*M_PI / 512);
|
||||
FIXED theta = (scale << 6) * 2;
|
||||
float sinlu = fx2float(fx12Tofx8(lu_sin(theta)));
|
||||
ASSERT_FLOAT_EQ(rnd(sinlu), 0.0049999999);
|
||||
}
|
||||
|
||||
TEST_F(FpSuite, TanFromFixedPointRadian) {
|
||||
// 20 degrees is 0.34906577777777775 rad
|
||||
// will be stored as .8f as input val
|
||||
|
|
Loading…
Reference in New Issue