matrix_mul(3alleg4)

πŸ’– matrix_mul β€” bestie edition πŸ’–

okay so this is a page from the Allegro manual, and today's main character is matrix_mul (and its float-y twin matrix_mul_f). no cap, it does exactly what it says on the tin: it multiplies two matrices. let's get into it 🫢


✨ NAME ✨

matrix_mul, matrix_mul_f β€” Multiplies two matrices. part of the Allegro game programming library, obviously πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

void matrix_mul(const MATRIX *m1, const MATRIX *m2, MATRIX *out);

void matrix_mul_f(const MATRIX_f *m1, const MATRIX_f *m2, MATRIX_f
*out);

πŸŽ€ DESCRIPTION πŸŽ€

so basically, bestie, you hand it two matrices and it multiplies them, and it drops the result into out. that's the whole vibe ✨

quick heads up about out though β€” it's totally allowed to be a duplicate of one of the input matrices, so like, out being the same as m1 or m2? fine, it works, no drama. BUT β€” and this is the tea β€” it's faster when the inputs and the output are all different. so if you're chasing that speed, keep them separate, iykyk πŸ’«

now the actually iconic part: the resulting matrix has the same effect as the combination of m1 and m2. like, when you apply it to a point p:

(p * out) = ((p * m1) * m2)

so it's giving "do m1, then do m2" but squished into one single matrix. which means you can concatenate any number of transformations this way β€” stack them, chain them, layer them, it just keeps working. obsessed πŸ˜­πŸ’–

⚠️ ok important one, don't skip this: matrix multiplication is NOT commutative. that means matrix_mul(m1, m2) != matrix_mul(m2, m1). order matters, bestie. always has, always will. flip the arguments and you get a different result, periodt. πŸ”₯

πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, babe πŸ¦‹ go forth and multiply (matrices). this was brought to you by Allegro, version 4.4.3 β€” mwah, take care of her, she's iconic πŸ‘‘πŸ’…πŸŒΈ