Skip to content

Clarify ambiguous term "Column-major" #124

Closed
@makuto

Description

Re issue #89: I'm confused. Isn't this true? Or is there something I'm not understanding about row vs. column major?
For example:

#include <stdio.h>
#include "HandmadeMath.h"

typedef hmm_mat4 mat4;
mat4 mat4Identity()
{
	return HMM_Mat4d(1.f);
}

void mat4Print(mat4 mat)
{
	int row = 0;
	while (row < 4)
	{
		printf("%d [%f %f %f %f]\n", row, mat[row][0], mat[row][1], mat[row][2], mat[row][3]);
		++row;
	}
}

int main()
{
	mat4 matA = mat4Identity();
	mat4Print(HMM_MultiplyMat4(matA, HMM_Translate({1.f, 2.f, 3.f})));
	mat4Print(HMM_Rotate(45.f, gUpAxis));
	return 0;
}

outputs:

0 [1.000000 0.000000 0.000000 0.000000]
1 [0.000000 1.000000 0.000000 0.000000]
2 [0.000000 0.000000 1.000000 0.000000]
3 [1.000000 2.000000 3.000000 1.000000]

0 [0.707107 0.000000 -0.707107 0.000000]
1 [0.000000 1.000000 0.000000 0.000000]
2 [0.707107 0.000000 0.707107 0.000000]
3 [0.000000 0.000000 0.000000 1.000000]

Which is what I expect: the translation (1.f, 2.f, 3.f) is properly stored in the 4th row of the matrix, where columns 1, 2, and 3 are contiguous in memory.

I did some more reading, and found this thorough discussion: Column Vectors vs. Row Vectors. I don't fully understand what they were getting at, but I think the terminology really should be clarified in Handmade Math.

Whether it's row-major or column-major depends on how you write it. My mat4Print prints it row-major, as if you were printing a pixel array (and not destroying your cache).

To clarify, the matrices are stored in row-major order, but you can choose to think of them in column-major order, right? I'm used to matrices being both stored and thought-of in row-major order, as if rendering the matrix out as a image stored from the top left corner, row by row.

However, it is row vector, which is what I expected, and what confused me when seeing "column-major". I think the terminology should be updated to say row-vector instead of column-major, because the latter is an ambiguous term.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions