al_transfo...projective(3)
πΈ NAME πΈ
al_transform_coordinates_3d_projective β Allegro 5 API
okay bestie, this is the al_transfo...projective(3) page from the Library Functions Manual (aka the Allegro reference manual), and it's literally here to make your 3D projective-transform math make sense. no cap π
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
void al_transform_coordinates_3d_projective(const ALLEGRO_TRANSFORM *trans,
float *x, float *y, float *z)
π DESCRIPTION π
So here's the vibe: this function transforms x, y, and z as homogeneous coordinates. It's the same as using al_transform_coordinates_4d(3) with the w coordinate set to 1, and then dividing x, y, and z by the resulting w. That gives you the same normalized coordinates Allegro will draw to when a projective transform is in effect β the one set with al_use_projection_transform(3). iconic behavior, honestly β¨
Now, to get the actual pixel coordinates from those normalized coordinates, you translate and scale like this β and w and h would be the pixel dimensions of the target bitmap:
x = w / 2 + x * w / 2
y = h / 2 - y * h / 2
Not me handing you the pixel glow-up formula, but here we are π«Ά
Parameters:
transβ Transformation to use.x,y,zβ Pointers to the coordinates.
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
Since 5.2.4 β yes bestie, this one has been around since 5.2.4 π
π¦ SEE ALSO π¦
Go peek at these too, iykyk:
al_use_transform(3)al_transform_coordinates(3)al_transform_coordinates_3d(3)al_use_projection_transform(3)
kisses and confetti ππ β source/version: the Allegro reference manual; page: al_transfo...projective(3); date: not shown on this footer, so no invented date here, bestie π«Ά
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms