carmineos / rage-toolkit

Other
19 stars 6 forks source link

Numerics: handle both Matrix4x4 in row-major and column-major #12

Closed carmineos closed 3 years ago

carmineos commented 3 years ago

Some blocks seems to store 4x4 matrices in row-major order, some examples seems to be:

TODO: check all the matrices and update DataReader/DataWriter to handle both single matrices and arrays

carmineos commented 3 years ago

System.Numerics.Matrix4x4 is row-major, although DataReader/DataWriter reads/writes the matrix as a colum-major one by reading the floats 1 by 1. In ReadArray/WriteArray this will break because the MemoryMarshal will follow the System.Numerics.Matrix4x4 struct layout instead. Furthermore in dev/performance branch it also breaks reading single matrices.

A temporary solution, to have at least coherent reading/writing of matrices everywhere, could be restoring the using of RAGE_Matrix4x4 wrapper which stores the values as generic four Vector4.

carmineos commented 3 years ago

Fixed in https://github.com/carmineos/gta-toolkit/commit/be460515c51b84b99e29f8d4845e7e88f050bb75