[osg-users] Correction of wikipage Support/Maths/MatrixTransformations
Matthias Bindernagel
matthias.bindernagel at gmx.de
Thu Sep 4 04:36:54 PDT 2008
Hi Robert,
> I've just quickly gone through the page you mention and it looks fine.
It does? To me it does not, tho maybe I get the intention of the mentioned
paragraph wrong.
On the page is stated that one should load a column-major-matrix with
glLoadMatrixf(). And then there's this example given:
| cosA -sinA 0 0 |
| sinA cosA 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
GLfloat ZrotateMatrix[][4] = {
{ cosA, -sinA, 0, 0 },
{ sinA, cosA, 0, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 }
};
Which is, in fact, a row-major-matrix (to make it column-major one must swap
sinA and -sinA). Afterwards is it argumented that the actual outcome does
not match the desired one - which cannot happen, if you pretend to pass a
column-major-matrix, but actually pass a row-major-matrix.
My problem with this erroneous example is that its assumed correctness is
the foundation for the whole following argumentation.
> As for what convention people use - well it all depends on what your
> background is, as to whether you view a vector as a column or a row,
> as also the pre/post multiplication. With the osg vectors are a row,
> and the matrices are row major - consistent with how data is actually
> stored in OpenGL and OSG.
Little remark regarding this paragraph: Don Burns states on the
wikipage "The books seem to use column major, prefix notation,
including the OpenGL book". glLoadMatrixf() also uses column-major.
Now I'm getting really confused, you state OpenGL uses row major!?
You're definitely right on this one, it is just a matter of convention. My
post should not address the choice of convention, but rather the
argumentation of this choice and its consequences.
The page mixes the following forms of matrix products:
V' = V * M (1)
W' = N * W (2)
where V' and W' are transformed vectors, V and W are original vectors and M
and N are transformation matrices. But these forms are not equal as you
state in the last paragraph of the wikipage: V and V' must be row vectors,
W and W' must be column vectors, that is, V is the transpose of W and V' the
transpose of W' (technically this does not make much of a difference).
Furthermore - and most important - M is the transpose of N (since matrix
products are not commutative, you must transpose both operands first to
swap operands). Taking these assumptions into account (1) and (2) do lead
to the same result.
But, since most books and internet lectures on this topic use the form (2),
one cannot use the usual transformation matrices presented in those
lectures when using form (1), but rather the transpose of such matrices. If
OSG uses original or transposed transformation matrices is not stated - in
my eyes these information are essential for a correct and broad
understanding.
I hope you get my point right, as I am trying to understand the internal
maths of OSG. To me the mentioned example looks just wrong and in my
understanding of the wikipage, the rest of the argumentation on this page
relies on this example. Also, you use prefix notation, which requires the
use of transposed trafo matrices (compared to usual math book notation with
column vectors - the "usual" refers to my personal experience ;)) ...
Failure to apply the transposed matrices could be "corrected" by using the
wrong form of matrices passed to glLoadMatrixf() - so both errors would
cancel themselves out.
I don't know if this is the case, actually I doubt it is. But the wikipage
is not able to convince me in a coherent way. There are information on the
page I can rely on (like your last paragraph on the page), but then there
are these 2 (to me obviously) wrong uses of glLoadMatrixf() and some vague
statements regarding matrix multiplication order, where V' = V * M and V' =
N * V are used interchangeably, tho M and N are definitely not the same. So
I would like to have is some clarity regarding the actually applied
convention and its consequences for the used transformation matrices.
Thanks for reading,
Matthias Bindernagel
>
> On Wed, Sep 3, 2008 at 7:19 PM, Matthias Bindernagel
>
> <matthias.bindernagel at gmx.de> wrote:
> > Hello,
> >
> > on the page
> > http://www.openscenegraph.org/projects/osg/wiki/Support/Maths/MatrixTrans
> >formations is stated that one should
> >
> >>pass this matrix
> >>
> >>GLfloat ZrotateMatrix[][4] = {
> >> { cosA, -sinA, 0, 0 },
> >> { sinA, cosA, 0, 0 },
> >> { 0, 0, 1, 0 },
> >> { 0, 0, 0, 1 }
> >>};
> >>
> >>to glLoadMatrixf(): and see what happens (g'ahead try it, don't take my
> >> word
> >
> > for it).
> >
> >>Your rotations will be the opposite of what you expect.
> >
> > Well, the correctness of the result depends on what you expect: OpenGL's
> > glLoadMatrixf() and its variants expect a column-major-matrix as
> > parameter (see
> > http://www.opengl.org/sdk/docs/man/xhtml/glLoadMatrix.xml); passing a
> > row-major-matrix (like done in this example) to glLoadMatrixf() results
> > in a transformation described by the transposed matrix-argument. Same
> > holds true for the translation described later on the wiki page.
> >
> > So the results of the allegedly erroneous examples are actually correct,
> > regarding the OpenGL documentation and standard maths.
> >
> >
> > Another point I want to mention here is my surprise about the
> > argumentation of the matrix-vector-product in OSG:
> > Almost every book or website I've read about computer graphics in general
> > and some DSL's in particular uses
> > V' = M * V
> > on a broad basis, where V' is the transformed vector, V is the original
> > vector and M descibes the trafo.
> >
> > One could - like the documentation did - replace this commonly used
> > matrix product with W' = W * N, but (at least in my opinion) _must_
> > mention that: 1. W' and W are transposed vectors (that is, they are row
> > vectors, instead of widely used column vectors)
> > 2. N must not be a common transformation matrix (like the ones mentioned
> > on wikipedia or mathworld.wolfram.com), but the transpose of such a
> > matrix.
> >
> >
> > IMHO, the documentation found on that wiki page does need some slight
> > corrections, but also a lot of additions to clearly state when to use
> > original or transposed transformation matrices.
> >
> > Regards, Matthias Bindernagel
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
More information about the osg-users
mailing list