Share this post

Link to post

Share on other sites

Well, if you have an object with it's own local coordinate system, you can put it into another coordinate system by translating it. For instance, to get an object into the world's coordinate system, you translate the object's local coordinate system by the object's position in the world. If I misunderstood the question, please clarify.

0

Share this post

Link to post

Share on other sites

I've checked the OpenGL FAQ. If we premultiply the current matrix by a transformation matrix it will transform the object w.r.t the world axis not local space. But gl transformation calls only postmultiply. How can I make a premultiplication ?

1. It gets scaled by 10 in x, y, and z2. It gets rotated around the Y axis, at its center, by 45 degrees3. It gets moved to world position (100, 100, 0)

The reason this is the case is that OpenGL uses column vectors. When transforming a column vector by a matrix, the matrix has to be on the left and the vector on the right. This has the effect that when you post-multiply the transformation matrix, you are actually adding a transformation to be applied earlier than the existing transformations. Hope this makes sense.

Due to OpenGL uses post-multiplication, you simply provide OpenGL with the data from left to right. I.e. you first provide M1, then with M2, ..., and last but not least v. Due to the feature shown above, it is totally okay to provide all transformations before providing the vertices. As an example, the sequenceglLoadIdentity();glRotate(...); // M1glTranslate(...); // M2glScale(...); // M3glVertex(...); // the 1st vglVertex(...); // the 2nd vglVertex(...); // the 3nd v...works likeM := I * M1 * M2 * M3v1' := M * v1v2' := M * v2v3' := M * v3...

Interpreting this one can say that M3 is applied to v, M2 is applied to the result of the former transformation, and M1 is applied to the respective result. This fact is what strtok means with "applied in reverse order" (although I'm not happy with using this term here, since the math shows that OpenGL doesn't revert anything in a closer sense; but that is a matter of taste).

A local co-ordinate frame L can be understood as a transformation that maps geometry given in the (local) frame to the parent frame (i.e. the co-ordinate frame where the local frame is given in). Without loss of generality we assume that L is given in the "world". So geometry in the local frame is transformed into the world byvw := L * vl

A transformation M that should be applied to the geometry is given in a co-ordinate frame. You get the desired effect if and only if you apply the transformation to the geometry in the same co-ordinate frame. This can be reached by transforming the geometry into the frame where M is given in (and normally transforming the result back to the local frame).

Assume e.g. that M is given already in the geometry's local frame: Ml. Then you can apply it directly, yielding in a transformed geometry still given in its local frame:vl' = Ml * vl

The transform M may alternatively be given in "world" frame: Mw. So you have to compute the Ml from Mw first, yielding inMl := L-1 * Mw * L

Why this? Setting in you getvl' = L-1 * Mw * L * vl = L-1 * ( Mw * ( L * vl ) )Here you can see exactly the steps descibed above: The geometry is transformed into the wanted frame (here from its local frame to "world"), the wanted transformation is applied, and the result is transformed back to the local frame. You can drop the back transformation, of course, if you want the result be given in the world frame.

So, for OpenGL in that case, you would have to provide the inverse of the local frame's transformation, followed by the desired transformation, followed by the local frame's transformation.

0

Share this post

Link to post

Share on other sites

Thats ok, suppose I have a sphere sitting on the world coordinate origin, and one box rotating about the world's y-axis and also x-axis. When I write the above code, after some translation in the z-axis, the box rotation behave stranglely i.e it rotates around z-axis instead of y-axis. I think thats because of the postmultiplication

// Draw a sphere at the world originglPushMatrix();DrawSphere();glPopMatrix();