# Semantic hell: rows and columns.

This topic is 1762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

DirectX uses row-first notation for tables or matrices while OpenGL uses column-first notation.

Why on earth would mathematicians choose the opposite of the Cartesian method of ordering the axis(first x then y) boggles me.

Furthermore, we refer to the x component as the number of columns and the y component as the size of the column

##### Share on other sites

Welcome to reality! It's bitten me more than once!!! the lesson here is that you must read the specs.

http://gamedev.stackexchange.com/questions/16011/direct3d-and-opengl-matrix-representation "In OpenGL, matrix operations are pre-concatenated, which means concatenated transformations are applied from right to left. Direct3D, however, applies concatenated transformations from left to right."

Edited by mark ds

##### Share on other sites
http://gamedev.stackexchange.com/questions/16011/direct3d-and-opengl-matrix-representation
"In OpenGL, matrix operations are pre-concatenated, which means concatenated transformations are applied from right to left. Direct3D, however, applies concatenated transformations from left to right."

This is not a valid statement any more (since shaders became the norm with GL2 / D3D9). I'd go as far as to say that SE page is just wrong.

You can use either column-vectors or row-vectors (pre/post concatenation) in both D3D and GL.

You cal also use column-major or row-major storage in both D3D and GL.

You can also use right-handed or left-handed coordinate systems in both D3D and GL.

The only thing that's fixed is the order that the 16 floats must be given to the constructor of a GLSL mat4x4 or a HLSL float4x4, and their array access syntaxes...

Note that on the C/C++ side, neither D3D or GL define vector or matrix types. If you've got some fixed row-major, post-convatenation (row-vector) matrix classes, those are not a part of D3D, those are an external library. You're free to choose a single math library and use it for both.

Edited by Hodgman

##### Share on other sites

Yeah, you're correct, I just wanted to present the simple case (row vs column  mayor).

But, from a students point of view. it must seem pretty confusing - left or right handed.

Incidentally, we spoke a while ago about landscape shadowing, with a focus on penumbras. I've moved on with that! (I didn't reply because of work commitments!)

Edited by mark ds

##### Share on other sites
Adding to Hodgman's comment about choosing conventions, just pointing you to the /Zpr flag of the HLSL compiler, which will make it use row-major packing. Obviously that's not the only answer you need, but it might save you a minute looking. :)

##### Share on other sites

"In OpenGL, matrix operations are pre-concatenated, which means concatenated transformations are applied from right to left. Direct3D, however, applies concatenated transformations from left to right."

A mnemotechnic verse may be as simple as this: The closer the transformation matrix to the vector in the mathematical formula, the more local is it. In other words: The farer away, the more transformations are between it and the original vector. This works fine for both row and column vectors and eliminates the dependent "left-to-right" vs. "right-to-left".

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 19
• 15
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015512
×