Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: understanding the OpenGL matrix implementation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: understanding the OpenGL matrix implementation

The easiest way to think about it is that "normal" (my prejudice, sorry)
matrices and standard C 2-d arrays are "row-major", that is, the when
they're enumerated the row index changes _slower_ than the column index.
Open-GL matrices are column-major order. The operation that converts
back and forth between the two is a matrix transpose, which is just
flipping the matrix about its major diagonal.

The rule to remember is that with row-major matrices, points are column
vectors that post-multiply (ie, multiply on the right) matrices, whereas
when using column-major matrices, points are row vectors that
pre-multiply (...on the left) matrices.

That is, to transform a point, these are equivalent:

Row-major-matrix * column-vector
row-vector * column-major-matrix

Unfortunately the blue book shows the right math but writes it out with
a column vector on the right, which is misleading.

As someone else alluded to, the real difference comes when you multiply
a matrix by a matrix. Column-major transformation matrices
post-concatenate, that is, the left-most transform (the one multiplied
first) "happens" first. The opposite is true for row-major matrices. So:

(Row-major) translation * rotation * vector

rotates a vector at the origin, then translates it away, while

(column-major) vector * translation * rotation

translates a vector away from the origin, THEN rotates it, which is very
different. You see it helps to right the vector on the correct side.
This is directly reflect in the order you need to call routines like
glRotate and glMultMatrix. I think this may answer Geoff's earlier "3rd
person perspective" question also.

And finally, the ARB recently saw the light and approved an extension
that is starting to show up on new graphics cards:

"The ARB_transpose_matrix extension allows applications to conveniently
store their matrices in row major order rather than column major order."

> Is this correct? I'm sorry I stink at math, but I really want to understand
> what's happening.

You don't stink at math! This is genuinely confusing. I don't know
anyone who can comfortably make the mental switch back-and-forth between
these two systems. Whatever you're used to, the other way always seems awkard.

But the right way is row-major ;-)

Dan Herman
DigitalFish Films

 >understanding the OpenGL matrix implementation (From: "James Lee" <email@hidden>)

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.