Mathematical Question about Irrlicht internals

Discussion about everything. New games, 3d math, development tips...
Post Reply
geminius
Posts: 2
Joined: Wed Sep 22, 2010 10:11 pm

Mathematical Question about Irrlicht internals

Post by geminius »

Hi Folks,

just searched the whole board, but didn't find a suitable answer. So, heres my problem:

I've looked at the matrix4 class and saw that there is a 16 field array storing the matrix data. As mentioned by Mark Segal from OpenGL, there is no difference between row-major and column-major in memory-layout.

So far now. If i get it right, D3D uses row-vectors and row-major layout while OpenGL uses column-vectors and column-major layout.

In COpenGLDriver the transformation is passed to opengl as a pointer to the array with the matrix data but without transposing. So you put a row-major matrix to a function which implies a column-major layout.

I really don't get the clue why the matrix is not transposed before passing it to glLoadMatrix. Is it possible to pass both layouts to the function and if yes, why does the OpenGL spec says you have to use column-major matrices?

Any help would be very nice!


Thanks in advance,

-Yannick

[edit]
Some browsing later, i found the description of a function glLoadMatrixTranspose. Seems the main difference between normal and transposed matrices in this case is the possibility to use two-dimensional arrays in c-style. If i use just an array of 16 floats, there is technically no difference between a d3d style matrix and an opengl matrix. correct me if im wrong. ;-)
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Re: Mathematical Question about Irrlicht internals

Post by Luben »

geminius wrote: As mentioned by Mark Segal from OpenGL, there is no difference between row-major and column-major in memory-layout.
You've got your answer right here. what is important is how it is laid out in memory. I mean, any column-major matrix could just as well be written as a row-major matrix, as long as the data is stored the same way. Which it is.

Image
from http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html shows how opengl chooses to visualize matrix data. Dx matrices are the same in memory, but with the indexes transponated when visualized. Same same.

Hope this helps at least a little =d

(also no guarantee that i'm not wrong :))
geminius
Posts: 2
Joined: Wed Sep 22, 2010 10:11 pm

Post by geminius »

I see.

So all the discussion about different matrices was just about the use in the code respectively the "Visualization". Though it's layout in memory is always the same, if your program uses two-dimensional arrays or a struct of floats, you have to make sure its properly aligned for opengl respectively directx. But if you use an 1d-array of floats, you may just don't care if d3d or opengl. In both cases for example the translation is set in m13, m14, m15. So the opengl matrix uses translation in the right column BECAUSE it is column-major and directx uses translation in the bottom row BECAUSE it is row-major.

I think i get it now. Although i still not understand why this discussion about column-major and row-major was that heated up through the web if the solution is that simple. Just use 1d-arrays. :-)
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Yep, those discussions are stupid and silly. :)
Kinda like when you ask a blender-fanatic why positive Z is used to represent the up-vector; They go all fanatic about that being the true open source opengl-defined way of doing it, and that all other ways are evil because those ways follow the wicked standard enforced by microsoft and directx :roll:
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

To be fair, I've been taught in every math class I've ever taken that z is the vertical axis. Not that it stops me from ignoring them when it comes to programming a game.
Post Reply