Archived

This topic is now archived and is closed to further replies.

fugaziman

simple translation/scaling question

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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 ...

Share this post


Link to post
Share on other sites