Sin/Cos-Tables faster? How..
Hello!
At first, I dont know in wich forum i should post it, so if it is here worng, sorry!
What are the advantages of some kind of "tabel" that hold many sin/cos values?
How can i make such a thing? Beause I dont know how many values I must use.
e.g.
namespace XX
{
class CMath
{
private:
float *sinTable;
..
public:
void Generate_Table();
inline float sin(float value)
{
return ....
}
..
}
}
sin & cos array tables are so much faster than actully calling sin & cos in the rendering loop infact anything that stays const and used in rendering engine should be put into an array !
The reason its faster is cause memory is just being move to processor and thats it when you call the array but when you call the function many lines of code are excuted which will slow down your engine a hell of alot cause finding sine & cosine is quite a long process.
hope this helps WizHarD
The reason its faster is cause memory is just being move to processor and thats it when you call the array but when you call the function many lines of code are excuted which will slow down your engine a hell of alot cause finding sine & cosine is quite a long process.
hope this helps WizHarD
Ah... that sounds great...
for(float x=0.0f; x<360; x+=Value)
{
sinTable[x] = sin(x);
}
But should i make it so... when yes: which values should i choose?
for(float x=0.0f; x<360; x+=Value)
{
sinTable[x] = sin(x);
}
But should i make it so... when yes: which values should i choose?
class TSinTable {float sine[36000];public:TSinTable {for(int i = 0;i < 36000;i++)this -> sine[i] = sin(i/100);}float GetSin(float inc) {inc *= 100;inc %= 360;if(inc == (int)inc)return this -> sine[(int)inc];float diff = inc - (int)inc;return ((this -> sine[(int)inc] + this -> sine[(int)inc+1])*diff)}}TSinTable SinTable;
EDIT: Normalize to 360... increased storage to 36000 (foolish me)..
will be 100% correct if you value is two or less decimals...
if it's more, it'll interpolate the values...
I'm positive the interpolate stuff isn't right, I don't remember how it's done, sorry!
I don't know anything about speedup, it should be faster though..
[edited by - Coward on June 26, 2002 5:04:59 PM]
That''s generally how it is done. You seem to have found the draw back though. If you want better precision you have to have a bigger table so you kinda need to know what kind of precision you need before making the table.
as far as i know it is an old story .
nowdays the bottleneck is the memory not the cpu.
it is faster to calculate sin\cos
nowdays the bottleneck is the memory not the cpu.
it is faster to calculate sin\cos
Alberto''s right. If you think long and hard about it (or just use a Taylor Series), you can make much more accurate (and probably faster) trig functions. In fact, I''ll time-trial my custom sin function against a 3-decimal look-up table function. I''m posting this before I do the test, and I''ll post the unbiased results in a few minutes, regardless of outcome.
Peace,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
Peace,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
To say nothing of the accuracy of lookup tables (okay, it's plain atrocious), lookups are 150% faster than my fastest Taylor Series function. So take your pick: accuracy or speed.
EDIT: or size. You could always make the lookup table 100 times the current size and get 5 decimals of accuracy (or 10000 times larger and it'll be as accurate as mine...)
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[edited by - zealouselixir on June 26, 2002 6:29:22 PM]
EDIT: or size. You could always make the lookup table 100 times the current size and get 5 decimals of accuracy (or 10000 times larger and it'll be as accurate as mine...)
Later,
ZE.
//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[edited by - zealouselixir on June 26, 2002 6:29:22 PM]
Well, could anyone help me out on the interpolation?
I''m realy embarrassed that I can''t remember it, or even figure it out...
I''m realy embarrassed that I can''t remember it, or even figure it out...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement