lookup table help

Started by
3 comments, last by Gecko 24 years, 2 months ago
i''m having trouble with a sin lookup table. heres the code: void CreateSineLookup() { float inc = 360/MAX_LOOKUP; float x=0; for(int i=0; i = sin(x*deg2rad); x += inc; } } float l_sin(float num) { int t_num = (int)num; int d_num = num-t_num; double ans; ans = sinlookup[t_num] + ((sinlookup[t_num+1]-sinlookup[t_num]) * d_num); return ans; } MAX_LOOKUP is 360. l_sin() is the new sine function. the problem is that the framerate is actually worse than when i just used sin(), and it produces a screwed up result, too! i''m probably just missing something obvious, and need fresh eyes to peruse the code. thanks
_________________Gecko___

_________________Gecko___Gecko Design
Advertisement
uhh... yeah, i''m an idiot. please forgive my incompetence. d_num should be a float in the l_sin function


_________________Gecko___

_________________Gecko___Gecko Design
Make global arrays for sine and cosine tables, like:
float cos_look[360];float sin_look[360]; 


Then here''s the code I use to make the tables:

for (int ang = 0; ang < 360; ang++){    // convert ang to radians    float theta = (float)ang*3.1415926535/(float)180;    // insert next entry into table    cos_look[ang] = cos(theta);    sin_look[ang] = sin(theta);} 


Good luck!
Al
Alexbigshot@austin.rr.comFoolish man give wife grand piano. Wise man give wife upright organ.
First of all; You''re lookup array doesn''t work...
In CreateSineLookup it''s a float, in l_sin it''s an rray of floats, and then there''s some oother screwed up stuff... This code should not work at all...Here''s how I''d do it...

float sinlookup[MAX_LOOKUP];

void CreateSineLookup()
{
float inc = 360/MAX_LOOKUP;
float x=0;
for(int i=0; i < MAX_LOOKUP; i++)
{
sinlookup = sin(x*deg2rad);
x += inc;
}
}

Then You might just use sinlookup[int something] to get your sine...If that''s too inaccurate for you - well make MAX_LOOKUP equal to 3600 and don''t use degrees to measure your angles but decidegrees = 1/10 of a degree...
So instead of using l_sin(4.6) you''d use sinlookup[46]...
Try it...

Should be fairly to implement...

Your problem is that you are converting floats and ints
back and forth vigorously, that eats up quite a piece of the time pie...


- Sleepwalker
- Sleepwalker
my CreateSineLookup works, the friggin'' board just messed it up, it turned my array thingy into an italic tag. damned message board.


_________________Gecko___

_________________Gecko___Gecko Design

This topic is closed to new replies.

Advertisement