Doom Wiki

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 one 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—they will be between zero and one full circle because unsigned arithmetic is performed modulo the 32-bit word size.

The 32 bits can be considered as a fraction of a circle, that is, as a binary fraction with an implied binary point at the far left. Also, if an angle value is considered as a signed quantity, then negative values represent rotation in the opposite (clockwise) direction.

An angle value can be compressed easily, by shifting bits off the right. Thus, angles in WAD files are given as short (16-bit) values (byte-swapped due to the little endian format). These values are expanded (shifted left 16 bits) during loading.

The trigonometric functions (sine, cosine and tangent) are implemented using straight table lookups. The angle value is compressed by shifting right 19 bits (resulting in a value between zero and 8191), and then this value is used to index into a pre-computed table that is 8192 values long. (The details for tangent are slightly different.) 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.