Inaccurate trigonometry table

From DoomWiki.org

Revision as of 06:52, 21 July 2014 by Kyano (talk | contribs) (Use {{c}})


The vanilla Doom engine uses pre-built lookup tables for fixed point trigonometry. In the earliest alpha versions of the code, the tables were generated on the fly at start-up by the functions R_InitTables and R_InitPointToAngle in r_main.c. In the final game engine, the tables are precomputed and stored in the tables.c file.

The Doom engine represents an angle as a 32-bit value, giving it 232 (4294967296) possible angle values. There cannot be that many values in a table, so the precision is first reduced to 213 (8192) possible values (the "fine angles") for the sine and cosine lookup table. Therefore, each entry corresponds to 219 (524288) different angles. The tangent table is even smaller, with only 2048 unique values.

For all of these ranges, the precise value that was used to generate the entry in the table is the middle one corresponding to the one in the middle of the range. The result is that there is a 0.02197265625° difference (one half of 360/8192) between the "rounded" angle value and the angle used to compute the result.

One of the outcomes of this inaccuracy is that orthogonal movement is not possible. This contributes to the ability to perform glides.

External links