get_camera_matrix(3)

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

get_camera_matrix πŸ’…

okay bestie so this is a page from the Allegro manual β€” section 3, the library calls, the good stuff β€” and it's all about get_camera_matrix, which builds you a camera matrix for perspective projection. game programming realness. let's GO πŸŽ€


✨ NAME ✨

get_camera_matrix β€” constructs a camera matrix for perspective projection. Allegro game programming library. that's the whole vibe, no cap.


🌸 SYNOPSIS 🌸

#include <allegro.h>

void get_camera_matrix(MATRIX *m, fixed x, y, z, xfront, yfront, zfront,
fixed xup, yup, zup, fov, aspect);

like, yes, that's a LOT of fixed args. it's giving "we have options". πŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

So what this bad boy does is construct a camera matrix that translates your world-space objects into a normalised view space, all prepped and ready for the perspective projection. it's the glow-up your 3D coords get before they hit the screen. ✨

Breaking down the parameters, because there are many and we respect them all:

  • x, y, z β€” the camera position. where your little camera guy is standing. πŸ“
  • xfront, yfront, zfront β€” the 'in front' vector, aka which way the camera is facing. and here's the tea: this can be any length! normalisation is not required, so don't stress about making it pretty first. it's lowkey chill like that. 🫢
  • xup, yup, zup β€” the 'up' direction vector. which way is up. crucial. otherwise your whole world is sideways and that's not the vibe. πŸ™ˆ

Then we get to fov, the field of view β€” that's the width of the camera focus, and it's measured in binary, 256 degrees to the circle format (iykyk, Allegro does angles like that). some fov facts for you, bestie:

  • for typical projections, a field of view in the region 32-48 will work well. that's the sweet spot, the main character range. πŸ‘‘
  • 64 (which is 90Β°) applies no extra scaling β€” so something that is one unit away from the viewer will be directly scaled to the viewport. literally one-to-one. slay.
  • a bigger FOV moves you closer to the viewing plane, so more objects will appear. more stuff on screen! πŸŽ‰
  • a smaller FOV moves you away from the viewing plane, which means you see a smaller part of the world. zoomed-in energy. πŸ”

And finally, the aspect ratio. this one is used to scale the Y dimensions of the image relative to the X axis, so you can use it to adjust the proportions of your output image. set it to 1 for no scaling β€” BUT keep in mind that the projection also performs scaling according to the viewport size, so it's not the only thing touching your proportions, okay? don't be surprised. 🫠

typically you'll pass:

(float)w/(float)h

where w and h are the parameters you passed to set_projection_viewport. matching set, matching energy. πŸ’–

⚠️ important history lesson, bestie: versions prior to 4.1.0 multiplied this aspect ratio by 4/3. so if you're on ancient Allegro and your proportions are looking weird, that's why. not you. it's the version. πŸ’€

🌈 SEE ALSO 🌈


and that's the whole page, periodt. πŸŽ€ this was written for Allegro, version 4.4.3, and the page itself is get_camera_matrix(3) β€” so like, go build something gorgeous with it. bye bestie, ily, go rotate a cube for me. πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from