home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / graphics / opengl / 279 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  3.4 KB

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