al_build_camera_transform(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

al_build_camera_transform β€” Allegro 5 API πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <allegro5/allegro.h>

void al_build_camera_transform(ALLEGRO_TRANSFORM *trans,
   float position_x, float position_y, float position_z,
   float look_x, float look_y, float look_z,
   float up_x, float up_y, float up_z)

πŸ¦‹ DESCRIPTION πŸ¦‹

okay bestie listen up, this one is literally the glow-up your 3D world coords need ✨ It builds a transformation you can use to take 3D coordinates in world space and turn them into camera space β€” like, from "where things are in the universe" to "how they look from the camera's little POV". It's giving translation and rotation, both, together, no cap.

The function wants three coordinate triplets, and it's not shy about it:

  • the camera's position (where the camera is standing)
  • the position the camera is looking at (where it's aiming its little eyes)
  • an up vector (which way is "up" for the camera)

Now the up vector? It does not need to be of unit length, and it also does not need to be perpendicular to the view direction. That's so forgiving of it honestly. Usually you can just hand it the world up direction, which is most commonly 0/1/0. Iconic. Simple. We love a low-maintenance parameter. πŸ’…

For example:

al_build_camera_transform(&t,
    1, 1, 1,
    5, 5, 5,
    0, 1, 0);

This creates a transformation for a camera standing at 1/1/1 and looking towards 5/5/5. Main character camera behavior, fr fr. πŸ“Έ

Note: If the position and look parameters are identical, or if the up direction is parallel to the view direction, an identity matrix is created. So if your camera is looking at itself or your up is pointing the same way you're looking β€” yeah, you get the identity matrix, that's just the deal, no drama. 🫢

Another example, and this one will simply re-create the identity matrix:

al_build_camera_transform(&t,
    0, 0, 0,
    0, 0, -1,
    0, 1, 0);

And here's an example where the up vector will cause the camera to lean (roll) by 45 degrees β€” a little tilt, a little drama, a little je ne sais quoi 😭πŸ”₯:

al_build_camera_transform(&t,
    1, 1, 1,
    5, 5, 5,
    1, 1, 0);

Since 5.1.9 ⭐


πŸ‘‘ SEE ALSO πŸ‘‘

go read those next bestie, they're all part of the same transform squad 🌈


and that's a wrap on al_build_camera_transform(3alleg5) from the Allegro reference manual πŸ’œ thanks for reading the whole thing, you ate that, periodt πŸŽ€βœ¨

πŸ“¦ where this page comes from