Vector math

Since some functions need to return a vector or a pair of angles, they use the ACSUtils multiple return values convention.

ZDoom GetActorPitch returns actor pitch with the wrong sign (multiplied by -1). Make sure to fix the sign before using actor pitch in the below vector functions.

Functions returning one value:

Functions returning two values:

Functions returning three values:

Other useful functions

mod

num mod(num x, num period) – just like x % period, but performs “true” modulo division, without negative results or mirrorings. It's as if you began at 0 in space [0, period) with wraparound, and moved X steps to the right.

Example of practical use of mod that wouldn't work with %:

int NUM_MENU_ITEMS = 10;
int selected_item = 0;

if (KeyPressed(BT_FORWARD))
    selected_item--;
if (KeyPressed(BT_BACK))
    selected_item++;
    
// wrap around
selected_item = mod(selected_item, NUM_MENU_ITEMS);