by CARPEDIEM » Feb 5, 2001 @ 7:56pm
First of all, if you need trigonometric functions, for games, then BY NO MEANS you need to use fixed point math, or even a taylor polinomial.<br><br>What you have to do for the sin function por example, is generate an int array of 720 components, and in each of them, place the corresponding value for sin(i - 360). Because <br>sin[0] will mean sin(-360).<br>But of course, these values vary between -1 and 1, and if you cast the double to an int, you'll always get a 1 or a 0.<br>The solution is to multiply sin(i)* 10000, so that you don't loose the valuable info.<br><br>And whenever you want to use this sin table, you can use it normally on any expression, and divide everything for 10000. And voila, you get what you want at a cheap cpu price.<br><br>Using integer math i get like 200-300% speed increase. Pretty damn neat, i can't belive you get 10 fps on pocket quake even using floating point math. When you leave this damned data type, i assure you, quake will FLY.<br><br>So, Basically you can use these multiplications for 10000 to simulate a decimal point in any operation, you loose range of course, but there are larger data types than just ints so who cares, they sure as hell are faster than integers.<br><br>I hope i was of some help.<br>