From: kyriazis@nova0.rdrc.rpi.edu (George Kyriazis)
Subject: Re: Row major or column major matrices?
Organization: Rensselaer Design Research Center, RPI, Troy, NY
Date: Mon, 25 Jan 1993 01:43:43 GMT

In article <1993Jan22.124249.3817@eye.com> erich@eye.com (Eric Haines) writes:
>I feel vaguely like I'm in a twilight zone episode.  You know, like the ones
>where some guy wakes up and finds that all the lettering is backwards and
>everyone is left-handed.
>
I feel like I am in the same episode whenever I talk about matrix concatenation
and (even worse) PHIGS-like view specification (view mapping and view
orientation).

>Someone was telling me that OpenGL allows only post-concatenation of matrices.
>This seemed bass-ackwards, and after a few minutes reconfirming in my slow
>turtle brain that you'd normally want pre-concatenation of matrices, I read
>over the OpenGL manual page carefully.  Aha, they store matrices in
>column-major form:
>
>	a0   a4   a8   a12	a typical	1  0  0 -2
>	a1   a5   a9   a13	translation	0  1  0  5
>	a2   a6   a10  a14	matrix -->	0  0  1  3
>	a3   a7   a11  a15			0  0  0  1
>
Hmm...  I would feel confortable if your matrix was numbered like:

	a00	a01	a02	a03
	a10	a11	a12	a13
	a20	a21	a22	a23
	a30	a31	a32	a33

Using this numbering, you don't really care if it's row-major and column-major.
Well, knowing the way C implements things, you'll end up with row-major
finally, but who cares...

My point is that using row vectors, your X translation will end up at a30,
while using column vectors it will end up at a03.  You still have one 0 and
one 3.  With your numbering you have a 3 instead of a 12, which is a bigger
difference.  

Row-vectors vs. column vectors really mess you up sometimes though:

"wait!  This is not a perspective divide!  It's a translation!!"

or even worse

"Why on earth IBM GL on the GTO restricts the translation vector to be
a multiple of the 3rd column?  Wait!  That's the perspective calculations!
Duh!"

>If you made it this far, take a minute and hit that "r" key and let me know
>which form (if either) you prefer, where you learned it, and any other
>insights you might have.  I'm interested to see if there's any correlation
>with school, or age, or whatever.  I'll summarize to the net.
>
Well, I wish I remember how I got started into column vectors, but they
always made more sense to me, from algebra's point of view, anyway.
ie. ABx (where x is a vector, and A & B matrices) makes more sense to me
than xBA.  Even in cases that I have to use matrices that correspond to
row-vectors, I do it my own way and transpose in the end.  Ok, so it's
slower..  So, sue me!

Also, I think that if you are using your main processor to do matrix-vector
multiplication, using column vectors is faster (please beat me on the head
if I am wrong).  I bet that's why OpenGL switched to column vectors...
Plain old GL used the hardware to do the multiplications, so it's just a
DMA transfer to graphics pipe, while OpenGL has to provide the same 
functionality, no matter what the hardware is.  So, in order to make the
software mat-vec faster, they use col vectors.

Additionally, if you work with C++ and you use operator overloading,
you have more flexibility in the implementation if the matrix-vector 
multiplication is owned by the matrix class instead of the vector class..  
(which is the case with col vectors).

Hope that gives some insight.

  --george
-- 
----------------------------------------------------------------------------
George Kyriazis       | Visual Technologies Program, Rensselaer Design
kyriazis@rdrc.rpi.edu |  Research Center, CII 7015, RPI, Troy, NY 12180
----------------------------------------------------------------------------
Newsgroups: comp.graphics