Original Post
I'm reading Tricks of the 3D Game Programming Gurus at the moment, and LaMothe writes that the trig functions are very slow and that the best thing to do when comuting sin and cos in a game is to use pre-built lookup tables. This is obviously faster, but in this book he creates a function that calculates sin and cos for non-integer values. I performed a small speed test and it turns out that calculating these values from the lookup table was actually *slower*! For your game engines, do you guys just use the sin() and cos() functions, or is there a better way? By the way, the code from the book is something like this:
float Sin(float theta)
{
theta = fmodf(theta,360);
if(theta < 0)
theta += 360;
int iThetaInt = (int)theta;
float fThetaFrac = theta - iThetaInt;
return(fSin[iThetaInt] + fThetaFrac * (fSin[iThetaInt + 1] - fSin[iThetaInt]));
}
Turns out that the fmodf() function seems to take twice as long as just calling sin()!
[edited by - Strayfire on May 29, 2004 12:27:27 AM]