Angle

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

Internally, angles are stored as 32-bit unsigned integer values, with zero representing east, or toward the right edge of the map. In this system, commonly referred to as "binary angle measure," increasing values represent angles increasing counterclockwise, using the full range of 32-bit unsigned precision to represent one full circle. Thus, north is represented (in ) by, west by , and south by. Northeast (45 degrees) is. Note that angle values can be added and subtracted, and the results will be automatically normalized; they will be between zero and just less than 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 decimal 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. The value closest to one degree in this system is.

An angle value can be compressed easily by shifting off the least significant bits. Thus, angles in WAD files are given as 16-bit values. These values are expanded (shifted up 16 bits) during loading. The sine, cosine and tangent are implemented using lookup tables. The angle value is compressed into an index for use with these tables by shifting down 19 bits, resulting in a value between 0 and 8191 referred to as a "fine angle." The resulting accuracy is mostly adequate for gameplay and rendering purposes. While computationally cheap in terms of instructions, this method does have an associated cache penalty, however, due to the size of the lookup tables involved.

Note that shifting right 19 bits truncates the angle value by no more than 360/8192 = 0.044 degrees.

Byte angles
In the Hexen map format and in ACS scripts, particularly in the arguments of linedef specials, angles are often stored as a single unsigned byte ranging from 0 to 255. Because this format represents fewer than 360 distinct values, some accuracy is sacrificed. The following formulas can be used to convert between degrees and byte angles for numbers between 0 and 359: Depending on the context, values 0 and 255 may have special meanings. For rotating polyobjects, 0 means to rotate exactly 360 degrees, while 255 means to rotate perpetually.

Flat rotation
ZDoom and compatible source ports such as the Eternity Engine allow flats to be rotated. Following a convention adapted from the, these angles range from 0 to 359, starting with 0 toward the north, and progress in a clockwise direction, contrary to the usual Doom engine coordinate system.