al_transform_...3d_projective(3alleg5)
β¨ 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 π
al_use_transform(3alleg5)al_transform_coordinates(3alleg5)al_transform_coordinates_3d(3alleg5)al_use_projection_transform(3alleg5)
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
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms