ryupold / raylib.zig

Idiomatic Zig bindings for raylib utilizing raylib_parser
MIT License
222 stars 36 forks source link

Help with matrix api #34

Closed Elyasb14 closed 10 months ago

Elyasb14 commented 11 months ago

Hi, I seem to only see the ability to create a 4x4 matrix in the bindings. What is the best way to create a 3x3 matrix? Thanks!

ryupold commented 11 months ago

There are no functions in raylib that operate on actual 3x3 Matrices. They all use 4x4 affine transformation matrices. But you can always wrap a 3x3 Matrix with a 4x4 Matrix.

// | a b c |
// | d e f |
// | g h i |

// would become

raylib.Matrix{
    .m0 = a, .m4 = b, .m8 = c, .m12 = 0,
    .m1 = d, .m5 = e, .m9 = f, .m13 = 0,
    .m2 = g, .m6 = h, .m10 = i, .m14 = 0,
    .m3 = 0, .m7 = 0, .m11 = 0, .m15 = 1,
}
Elyasb14 commented 11 months ago

Thanks for your response. Knowing that all matrices are affine transformation matrices helps a lot.