OpenGL transforms (glScale, glTranslate, etc.)

I am learning openGL and how to do transformations such as translation and scaling. I know that you usually have to translate to the origin, and then do whatever you want (say, scale), and then translate back. In my opinion, this is done manually, but you can do the same with glScale ().

My question is: do I still need to go to the beginning and back if I use the glScale function?

+4
source share
3 answers

You probably don't need to do a translation to the beginning and back, just do the conversions in the required order. Remember that the last applied conversion takes place in the converted space of the previous ones. For instance:

// draw object centred on (1,2,3) and ten times bigger glTranslatef(1,2,3); glScalef(10,10,10); drawObject(); 

vs

 // draw object centred on (10,20,30) and ten times bigger glScalef(10,10,10); glTranslatef(1,2,3); drawObject(); 
+14
source

All glScale it multiplies the current matrix by the scale matrix. So yes, for what it seems to you, you want to apply the scale matrix before applying the translation.

See also glScale link .

+3
source

You should think about the transformations taking place on the stack. In other words, the last conversion you specify takes place first. In this way,

 glTranslatef(1,2,3); glScalef(10,10,10); glRotatef(45,1,0,0); drawObject(); 

first rotates 45 degrees around the x axis, then scales the object to (10,10,10), and then translates to (1,2,3). However, you should also remember that any transformation you apply affects subsequent transformations. If we change the order of the above transformations, the rotation will rotate around another point.

+3
source

Source: https://habr.com/ru/post/1344351/


All Articles