Angle

In the Doom engine, angles are used to describe directions, such as which way a character or object is facing.

Internally, angles are kept as 32-bit unsigned values, with zero representing east (to the right of the map). Increasing values represent angles increasing counterclockwise, using the full range of 32-bit unsigned values to represent a full circle. Thus, north is represented (in hex) by 4000 0000, west by 8000 0000, and south by C000 0000. Northeast (45 degrees) is 2000 0000. Note that angle values can be added and subtracted, and the results will be automatically normalized, that is, they will be between zero and one full circle.

An angle value can be compressed easily, by shifting bits off the right. Thus, angles in WAD files are given as a short (16-bit) values, which are shifted left 16 bits during loading.

The trigonometric functions (sine, cosine and tangent) are implemented using straight table lookups. In effect, the angle value is compressed by shifting right 19 bits, then this value is used to index into a pre-computed table 8192 values long. The accuracy is quite adequate for gameplay and the compute time is nearly negligible. (Note that shifting right 19 bits truncates the angle value by no more than 360/8192 = 0.044 degrees.)