al_transform_...3d_projective(3alleg5)

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

✨ al_transform_coordinates_3d_projective ✨

okay bestie, welcome to the Allegro 5 API reference manual πŸ’– (yes, that's the whole manual, we're fancy like that). Sit down, grab a strawberry πŸ“, and let's talk about the most underrated little math goblin in the whole graphics stack.


🌸 NAME 🌸

al_transform_coordinates_3d_projective β€” Allegro 5 API, and it does exactly what the name screams at you. periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro5/allegro.h>

void al_transform_coordinates_3d_projective(const ALLEGRO_TRANSFORM *trans,
   float *x, float *y, float *z)

πŸ‘‘ DESCRIPTION πŸ‘‘

so what does this icon actually do?? It transforms x, y, z as homogeneous coordinates. no cap.

It's literally the same as calling al_transform_coordinates_4d(3alleg5) with the w coordinate set to 1, and then dividing x, y, z by the resulting w. That's it, that's the whole trick. πŸ’…

And why do we care?? Because this gives you the same normalized coordinates Allegro will actually draw to when a projective transform is in effect β€” the kind you set with al_use_projection_transform(3alleg5). So you get to peek at what Allegro is about to do before it does it. main character energy honestly.

Now β€” those normalized coordinates are cute and all, but they're not pixels yet. To get the actual pixel coordinates, you translate and scale like so (w and h are the pixel dimensions of the target bitmap):

x = w / 2 + x * w / 2
y = h / 2 - y * h / 2

(yeah the y one is minus, because screen space y goes down, we don't make the rules 😭)

Parameters:

  • trans β€” the transformation you wanna use πŸŽ€
  • x, y, z β€” pointers to the coordinates. pointers!! not values!! don't forget the & or the compiler will simply end you 🫢

Example:

ALLEGRO_TRANSFORM t2;
al_copy_transform(&t2, al_get_current_transform());
al_compose_transform(&t2, al_get_current_projection_transform());

ALLEGRO_TRANSFORM t3;
al_identity_transform(&t3);
al_scale_transform(&t3, 0.5, -0.5);
al_translate_transform(&t3, 0.5, 0.5);
al_scale_transform(&t3, al_get_bitmap_width(al_get_target_bitmap()),
                   al_get_bitmap_height(al_get_target_bitmap()));

al_transform_coordinates_3d_projective(&t2, &x, &y, &z);
// x, y now contain normalized coordinates
al_transform_coordinates(&t3, &x, &y);
// x, y now contain pixel coordinates

look at that. normalized first, pixel second. the two-step glow-up. ✨

Since 5.2.4 β€” so she's been around a minute, but she still ate. πŸ’…

πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page bestie!! 🌈 straight from the Allegro reference manual, filed under the very cursed-looking name al_transform_...3d_projective(3alleg5) (the ellipsis is doing a lot of heavy lifting, iykyk πŸ’€). go forth, transform some projective coordinates, and slay. πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from