persp_project(3alleg4)
π persp_project β the Allegro manual, but make it cute β¨
okay bestie, so this is a page from the Allegro manual (yes, that Allegro β the game programming library π). And it's about one specific little function that does one very specific little thing, and honestly? it eats. let's get into it π«Ά
β¨ NAME β¨
persp_project, persp_project_f β takes a 3d point and yeets it into 2d screen space π¦
(also: Allegro game programming library, hi hello, that's the whole vibe)
πΈ SYNOPSIS πΈ
#include <allegro.h>
void persp_project(fixed x, fixed y, fixed z, fixed *xout, fixed *yout);
void persp_project_f(float x, float y, float z, float *xout, float *yout);
two flavors, same energy: one takes fixed, one takes float. pick your fighter π
π DESCRIPTION π
so what it does: it projects the 3d point (x, y, z) into 2d screen space, drops the result into (*xout, *yout), and it uses whatever scaling parameters you already set up when you called set_projection_viewport(). no cap, that's the whole trick β you gotta set the viewport first, this function just does the math with it β¨
and the math is coming from the normalized viewing pyramid, which sounds intimidating but is literally just:
- the camera sits at the origin π₯
- the camera faces along the positive z axis
xruns left β rightyruns up β downzincreases as you go deeper into the screen (depth, bestie, it's giving perspective π)
the camera has a 90 degree field of view, meaning: points sitting on the planes x=z and -x=z land on the left and right edges of the screen, and the planes y=z and -y=z land on the top and bottom of the screen. iconic geometry, honestly π
now, if you want a different field of view, or you want the camera somewhere else? that's not this function's job, bestie. you gotta transform all your objects with an appropriate viewing matrix. for example β and this is the classic one β to get the effect of panning the camera 10 degrees to the left, you rotate all your objects 10 degrees to the right. yes, it's backwards on purpose. that's just how it is π
π¦ SEE ALSO π¦
go read those next, they're the supporting cast and they also serve π
and that's the page!! written against Allegro version 4.4.3, manual page persp_project(3alleg4) β mwah, love that for us πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms