Isn't there a faster way to calculate sine/cosine?
After I included about 60 sine/cosine functions per frame my framerate went down by about 1000(!)%
Printable View
Isn't there a faster way to calculate sine/cosine?
After I included about 60 sine/cosine functions per frame my framerate went down by about 1000(!)%
It's because they use your math processor. You need to setup a trignonometry table by declaring arrays and store the trig functions results in them. Then use these arrays instead of vb's trignonometry functions.
Wouldn't this limit presision depending on how far the function is caried out in the array... if he wants to stay acurate to say 5 or 6 decimal places the vbTrig functions might be the most practical way. ( I think... but I have been wrong in the past)
If you don't have memory problems you can make your table as huge as you want, it depends on what you're doing, you said your having frame rates, i guess youre working on a 3d-engine, i had the same problem solved it this way.
I remember once writing a program to rotate a 3d matrixed box. I just threw in a heap of constants because they compile to just their values.
A better way would be to calculate a whole heap of trigs on form load and write them to an array, then just call them.
Instead of X=Cos(45) (the function)
you have X = MyCos(45) (the array)
where the index was written with the cos of that number
It also means you can work directly in degrees and not radians.
Dim MyCos(360) as single
I = 45
MyCos(I) = COS(I) '(*180/pi) or whatever it is to convert from radians.
so MyCos(i) = 0.70711
Sorry for the math, it's early and I can't be bothered working it out exaclty, you get the idea
The (co)sine table will do fine. I think I won't need much more than 1 value/degree.
Thank you for your replies!
-Musashimaru
Is that MusashiMaru as in the Hawaian Sumo Wrestler?
O yeah!
btw. It's only a nick. I'n not (shock!) the real Musashimaru :-)