Jump to content
  • Advertisement

Archived

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

fugaziman

simple translation/scaling question

This topic is 6166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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 ...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!