al_fixatan2(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

al_fixatan2 β€” literally the Allegro 5 API bestie, coming through πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

al_fixed al_fixatan2(al_fixed y, al_fixed x)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: it's the fixed point version of libc's atan2() routine. iconic behavior fr fr. πŸŽ€

What it does is compute the arc tangent of y / x, but β€” and this is the part that's giving main character energy β€” the signs of both arguments get used to figure out which quadrant the result lands in. and yes, x is allowed to be zero, she's flexible like that πŸ’…

This one is super useful when you wanna convert Cartesian coordinates to polar coordinates. no cap, that's the whole vibe. 🌈

Example time, bestie:

al_fixed result;

/* Sets `result' to binary angle 64. */
result = al_fixatan2(al_itofix(1), 0);

/* Sets `result' to binary angle -109. */
result = al_fixatan2(al_itofix(-1), al_itofix(-2));

/* Fails the assert. */
result = al_fixatan2(0, 0);
assert(!al_get_errno());

πŸ‘‘ RETURN VALUE πŸ‘‘

So it hands you back the arc tangent of y / x in fixed point binary format angle, ranging from -128 to 128. periodt. ✨

but listen β€” if both x and y are zero, she returns zero and sets Allegro's errno to EDOM. so like, don't be shocked when that happens πŸ™ˆ

that's the whole page, bestie! this little gem lives in the Allegro reference manual, filed under al_fixatan2(3alleg5) β€” go forth and slay those polar coordinates πŸ«ΆπŸ’œβ­

πŸ“¦ where this page comes from