datenwolf / linmath.h

a lean linear math library, aimed at graphics programming. Supports vec3, vec4, mat4x4 and quaternions
Do What The F*ck You Want To Public License
922 stars 134 forks source link

Ability to set row major computations order. #25

Closed BlackDoomer closed 4 years ago

BlackDoomer commented 8 years ago

This PR adds ability to set row major computations order for matrices by definition of MAT4X4_ROW_MAJOR before inclusion of the library. It also fixes some implicit typecasts (includes PRs #8 and #10 as well) and adds two functions: mat4x4_set_row() and mat4x4_set_col() that were necessary for row major support. See commits for details.

datenwolf commented 8 years ago

Hmm, I've to give this some thought. Column major makes more sense, you need the columns more often than the rows for geometrical computations (they form the base of the local coordinate system). Also on many architectures it's more cache friendly, memory locations running with different stride will prevent matrix rows from competing for the same cache lines as vectors when doing the dot products of matrix-matrix multiplication.

BlackDoomer commented 8 years ago

Yes, you're right – and that's the reason why row-major mode is optional and non-default. But it's more convenient in some cases and more traditional - from point of view of linear algebra. So, I see no reason to reject this additional functionality. :)

BTW, I've made commit history more clear.