home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!ames!sgi!fido!spud.asd.sgi.com!segal
- From: segal@spud.asd.sgi.com (Mark Segal)
- Newsgroups: comp.graphics.opengl
- Subject: Re: Row major or column major matrices?
- Date: 26 Jan 1993 03:35:10 GMT
- Organization: Silicon Graphics, Inc.
- Lines: 54
- Distribution: world
- Message-ID: <1k2bheINNd2v@fido.asd.sgi.com>
- References: <1993Jan22.124249.3817@eye.com> <1993Jan23.000930.26869@kpc.com> <1993Jan26.002210.18638@mapsut.einstein.com>
- NNTP-Posting-Host: spud.asd.sgi.com
-
- I'm surprised that this simple topic has generated so many posts.
- I'm the one responsible for the 'column-major ordering' used in
- OpenGL, so I'll try to explain what's going on to try to put this
- discussion to rest.
-
- First, there are two issues that seem to be confused. One issue
- is how matrices are stored in memory, and the other is whether one
- treats vectors as rows of coordinates or as columns.
-
- I'll dispense with the second issue first. Recent mathematical
- treatments of linear algebra and related fields invariably treat
- vectors as columns (there are some technical reasons for this).
- For some reason, this has not been the case in computer graphics,
- where vectors were written as rows, thus transposing everything
- from standard mathematical usage. When I wrote the OpenGL spec,
- I decided to do my part to right this heinous inconsistency. Thus
- the spec is written with vectors treated as columns, with a matrix
- correspondingly applied on the left of a column.
-
- The one difficulty was compatibility with the current GL, where
- vectors had been written as rows. So I come up with this
- subterfuge: say that matrices in OpenGL are stored in column major
- order. The point is that you could rewrite the spec with everything
- transposed (with vectors written as rows), and everything would be
- exactly the same as it was, including the row major ordering of
- matrices.
-
- So we've come to the second issue: how matrices are stored in memory.
- If you treat vectors as columns, then in OpenGL matrices are stored
- column major. If you treat vectors as rows, then matrices are stored (as
- they are in the current GL) row major. That's all there is to it.
- OpenGL documentation treats vectors as columns, so it will be simplest
- for most people who use it to adopt this convention. But it won't
- affect any code you may have written to calculate matrices for the
- current GL in any way.
-
- To say without qualification that 'OpenGL stores matrices this way'
- is technically nonsense. OpenGL does nothing. OpenGL DOCUMENTATION
- assumes that vectors are columns therefore implying that matrices are
- given column major, but you are free to take the alternate interpretation
- if you wish. It is also nonsense to say that the hardware (or an OpenGL
- implementation) 'premultiples' or 'postmultiplies' (I could never remember
- which was which anyway). OpenGL applies a matrix (representing a
- transformation) to a series of coordinates (representing a vector) using
- the rules of matrix multiplication. You may view this as performing the
- multiplication c' = Mc, where c and c' are columns, or as r' = rM(transpose)
- where r and r' are rows (and r=c(transpose) and r'=c'(transpose) ).
- The two formulas represent the same calculation.
-
- So, in spite of this lengthy explanation, I don't think that there is
- actually any issue here, since there is no change from the current GL,
- and since a programmer is free to view matrices and vectors as she pleases.
-
- Mark
-