simple translation/scaling question

Started by
0 comments, last by fugaziman 22 years, 5 months ago
Hi, I would appreciate some help with this problem I can''t figure out. How can you merge multiple glScalef() glTranslatef() function calls into only two. For example, if I am drawing a box and do this: glScalef(x1, y1, z1); glTranslatef(x2, y2, z2); glTranslatef(x3, y3, z3); glScalef(x4, y4, z4); drawBox(); What manipulations can I perform on the variables x1-4, y1-4, z1-4 so that I only have to call glScalef(x1, y1, z1); glTranslatef(x2, y2, z2); drawBox(); and have the box end up at the same exact position?
Advertisement
In the example above you can combine the two glTranslatef calls into on by adding the values for x,y,z translation. But you may not combine the two glScalef calls because the 2nd call of glScalef needs or is affected by the results of the glTranslatef calls.

But you could replace all glScale and glTranslate calls with one glLoadMatrix call ... Everytime x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4 or z4 changes you create a new matrix with
glScalef(x1, y1, z1);
glTranslatef(x2, y2, z2);
glTranslatef(x3, y3, z3);
glScalef(x4, y4, z4);

then you read the Matrix as an double array by calling
glGetFloatv(GL_MODELVIEW_MATRIX, double *YourMatrix);

Then right before you render the object call either
glLoadMatrixd(YourMatrix); , this will overwrite your old matrix
or call
glMultMatrixd(YourMatrix); , this will ''add'' the matrix to your current matrix ...

depends on what you need ...

This topic is closed to new replies.

Advertisement