row major vs column major and multiply direction

Started by
2 comments, last by Hodgman 10 years, 11 months ago

When I am using matrices in my opengl program I have been doing multiples left to right.

so say M is my original matrix. if i want to apply a rotation to M i would multiple the rotation matrix R to M in this fation

Mrotated =M*R

does it mater whether I am using a row major system vs column major system when it come to the direction of my multiply? meaning

this, applying a rotation to M: M*R

versus

this, applying a rotation to M: R*M

or are these two separate issues?

J-GREEN

Greenpanoply
Advertisement

It does matter. If you transpose row major matrix you get column major matrix and multiplication order becomes reversed.

http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-4-geometry/conventions-again-row-major-vs-column-major-vector/

The above article will explain it better than I can!

Enjoy.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Row major storage vs column major storage makes absolutely no difference on your maths. The meaning A*B is strictly defined according to mathematical rules. The way that matrices are stored in memory is just an invisible implementation detail.

What does matter though is whether you treat your vectors (vec4, float4, etc) as row-vectors or column-vectors, i.e. is a vec4 a mat1x4 or a mat4x1?

If you write vec * mat, that's the same as mat1x4 * mat4x4.

If you write mat * vec, that's the same as mat4x4 * mat4x1.

These have different mathematical meanings.

Depending on which one of these conventions you use (which is an entirely different issue from column/row-major storage), you will store your values differently inside your matrices.

This topic is closed to new replies.

Advertisement