#[solved] Matrix Multiplication Order confusion (row major, Y.up/RH)

2 messages · Page 1 of 1 (latest)

nimble raven
#

I'm confused about the order of multiplicatons to create Transformation Matrices:
(the library I use is Row Major and, Y.up/[Lh/Rh])

This below is clear for row major

  • The goal: .scale() -> .rotate() -> .translate() -> .apply() -> final vector
  • Order: M3 * M2 * M1 * vec

BUT... I'm calling functions that take 2x matrices, not a single matrix!

So... if M3 is created by .scale()... then the example M3 is not just one matrix, it is M?? * M???
Which becomes: M3(?? * ???) * M2(?? * ???) * M1(?? * ???) * vec

Hence the question, because:

  • M3 could be either
    1. Identity * New[Scale]
    2. New[Scale] * Identity
  • M2 could be:
    1. New[Rotate] * Old_Scale_Identity
    2. Old_Scale_Identity * New[Rotate]
  • M1 could be:
    1. New[Translate] * Old_Rotate_Scale_Identity
    2. Old_Rotate_Scale_Identity * New[Translate]

Does anyone know what the correct order of arguments would be here? 🤔

nimble raven
#
// AKA needs to be ->   mul(vec3, transform)  !!
const works      = mul(loadArr3w(vector[0..3], 1), matFromArr(transform));
const very_wrong = mul(matFromArr(transform), loadArr4(vector));
const also_wrong = mul(matFromArr(transform), loadArr3w(vector[0..3], 1));
```Solution, for discord search context 👆
More context: https://github.com/zig-gamedev/zmath/issues/28