Advertisement

lookup

Started by February 13, 2000 12:05 PM
12 comments, last by Pseudo_Code 25 years ago
how do you create lookup tables for stuff? Anything, just, how?
Lookup tables are just pre-computed arrays that you use instead of computing everything in real-time. For example, you could create an array of 360 floats and fill it in with sin(0), sin(1), etc. and instead of having to call the sin function when you need it, you just reference this array.

Simple lookup tables like this can be created when your program starts, but more complicated lookup tables are usually stored on a file somewhere and read in.
Advertisement
What type of file could someone use should they need this information. And how would they read it in?
Say you wanted to create a lookup table for sin values from
0 - 360 it would be something like this(BTW this is in java but it's almost the same as C++)..

sinus = new float[360];
deg2rad = Math.PI/180;

for(int i=0; i<360; i++){
Sinus = (float)Math.sin(i*deg2rad);
}

where deg2rad is assinged as a float also.
What this does is fill an array full of cosine values. the only thing you would need to do to find the cos(15) would be to use cos[15]. It's actually pretty slick cause it saves alot of computation time if you are doing a lot of trig.
Anyway I hope this helps.. if you need me to do something like this in C++ I could give you an example too.


Edited by - Wrathnut on 2/13/00 1:24:14 PM
Sorry about that the above:
Sinus = (float)Math.sin(i*deg2rad);

should read
Sinus[j] = (float)Math.sin(i*deg2rad);

where j = i ..
the damn thing here wants to make my source code an html tag... grr

Edited by - Wrathnut on 2/13/00 1:31:36 PM
Use whatever file type is easiest for you. I''ve seen nearly 10,000 normal vectors defined in an array in a header file before.
Advertisement
thanks, that helped. But, if you could, do it in C++. It''s a bit confusing in JAVA. Thanks!
float* sin_table = new float[360];
float deg2rad = 3.1415927/180;

for(int i=0; i<360; i++)
{
sin_table = sin(i*deg2rad);
}

www.gameprojects.com - Share Your Games and Other Projects
Whoa. The thing removed my subscripts in the "for" loop. Should have read Wrathnut''s post

float* sin_table = new float[360];
float deg2rad = 3.1415927/180;

for(int x=0; i<360; i++)
{
sin_table[z] = sin(x*deg2rad);
}
www.gameprojects.com - Share Your Games and Other Projects
Okay, if at first you don''t succeed...this was supposed to be a simple post

float* sin_table = new float[360];
float deg2rad = 3.1415927/180;

for(int z=0; z<360; z++)
{
sin_table[z] = sin(z*deg2rad);
}
www.gameprojects.com - Share Your Games and Other Projects

This topic is closed to new replies.

Advertisement