persp_project(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– persp_project β€” Allegro manual, bestie edition πŸ’–

okay so this is persp_project(3) from the Allegro manual β€” the game programming library, yes that one β€” and it's here to turn your fancy little 3d point into an actual spot on your 2d screen. it's giving "math but make it wearable". no cap. ✨


🌈 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 for the fixed girlies, one for the float girlies. pick your fighter πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically: you hand over a 3d point (x, y, z), and this function projects it into 2d screen space, dropping the result right into (*xout, *yout). it uses the scaling parameters you already set by calling set_projection_viewport() β€” so like, if you didn't call that first, that's on you bestie, the vibes were established earlier. 🫢

it projects from the normalized viewing pyramid, which is the aesthetic where:

  • the camera sits at the origin, facing along the positive z axis
  • x runs left/right
  • y runs up/down
  • z increases with depth into the screen (deeper = more z, iykyk)

the camera has a 90 degree field of view. literally. which means:

  • points on the planes x=z and -x=z map onto the left and right edges of the screen
  • the planes y=z and -y=z map to the top and bottom of the screen

so if you want a different field of view, or a different camera location, the move is: transform all your objects with an appropriate viewing matrix. iconic behavior. for example β€” to get the effect of panning the camera 10 degrees to the left, you rotate all your objects 10 degrees to the right. same result, different path, that's just how it is. πŸ’…

not me explaining camera panning as a transformation glow-up 😭 it's the same thing, just applied to your objects instead of your camera. periodt.

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie! this beauty comes to you from Allegro, version 4.4.3 β€” go forth and project your little 3d points into the world, you main character πŸŽ€βœ¨πŸ’œ

πŸ“¦ where this page comes from