# OpenGL glScaled

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

## Recommended Posts

glLoadIdentity();// while loopingglScaled($x,$y, $z);//draw a shapeglScaled(1.0/$x, 1.0/$y, 1.0/$z);glTranslatef($xdir,$ydir, $zdir); ...or use the gl matrix stack: glLoadIdentity();// while loopingglPushMatrix();glScaled($x, $y,$z);//draw a shapeglPopMatrix();glTranslatef($xdir,$ydir, $zdir); #### Share this post ##### Link to post ##### Share on other sites You really need to get to know the mathematical effect of the different transformation commands-- that is, the ramifications of the fact that they cause an internal matrix to be postmultiplied by a different matrix, and what the effect of different orders of operations is. The OpenGL redbook has a great description of this stuff, but unfortunately only in the 3rd and later editions (opengl 1.3 and later, so it's not in the online version. You should also get to know the matrix stack (glPushMatrix and glPopMatrix), although this is somewhat a different thing. #### Share this post ##### Link to post ##### Share on other sites You have two choices, either: a) scale by the reciprocal value after drawing each object (which will reset the scale) or, b) glPushMatrix() before scaling, and glPopMatrix() after drawing (which will save and restore the matrix before the scale) #### Share this post ##### Link to post ##### Share on other sites I'd recommend option b) the matrix stack. Lots of multiplications (adding transformations and their inverse to cancel them out) will slowly introduce errors due to numerical instability/floating point precision issues. #### Share this post ##### Link to post ##### Share on other sites I was trying to rescale the scales back to its original value as you said, I will also try what you have recommended. I am quite aware of linear algebra as I had to really use construct amount of transformation operators (like those that would take an ellipsoid into unit circle and those that would rotate vectors around arbitrary axis). I am not however aware of the internal workings of openGL, and I dont think I will have enough time soon to see through it. However I will look through the book you mentioned. The graphics extension I am planning for now is very simple (I could write in matlab like in a day but I want it to be a part of my own program not a side script). I will update this topic if I am stuck anywhere else, thanks alot for the help, #### Share this post ##### Link to post ##### Share on other sites I am trying to use push and pop matrix way in this manner (I just put in 1.1 instead of varying scale amounts). So the size of the sphere should remain the same right? But its size increases and infact after the second sphere, it takes the form of an ellipsoid although the scaling is homogenous...(there is a picture after the code) sub DrawGLScene { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5, 0.0, -6.0); for (1..5){ glPushMatrix(); glScaled(1.1,1.1,1.1); glBegin (GL_QUADS); my$newQuad = gluNewQuadric ();
glEnd ;

glPopMatrix();
glTranslatef(3.0, 0.0, 0.0);

}

glutSwapBuffers;
}

http://img136.imageshack.us/img136/2268/spheredq6.jpg

##### Share on other sites
It's also the order of the calls that matter. Your translation inside the loop influences the scaling. Put it inside the glPushMatrix/glPopMatrix pair and use glTranslatef(i * 3.0, 0.0, 0.0f) instead.

##### Share on other sites
When I put translation between push and pop, only a single sphere appears (they are not translated but all are put on top of each other) I suppose the translation goes wrong? And also what is the purpose of i* and f, they are not defined on perl like that I think because it gives an error..

##### Share on other sites
Ah sorry, the f comes from my habit on using float literals which are declared as 0.0f (instead 0.0 which would be double).

The i was meant to be the counter variable of the loop, didn't pay attention to the fact that you don't declare it. What I meant is that you could increase the translation distance by 3 every time you loop, i.e. in C++
for(int i = 0; i < 5; i++){ ... glTranslatef(i * 3.0, 0.0, 0.0); //i.e. first iteration translate by 0, second by 3 etc. ...}

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999965
×