Reputation: 1801
I'm studying for an exam, and a previous exam had this question:
1. void drawGLScene(){
2. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3. glLoadIdentity();
4. glTranslatef(0, 1, 0);
5. glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
6. glScalef(.5, 2, 1);
7. drawChevron();
8. glFlush();
9. }
"Write three lines of OpenGL that when inserted in between lines 6 and 7 would reverse (cancel) the effect of the transformations implemented by lines 4 to 6. Do not use glLoadIdentity()."
I'm pretty sure it has to be another Translate, Rotate, Scale. But I know it isn't as simple as just using what I think are the reverse parameters. I'm having a lot of trouble understanding which way the x and y axes are facing, and whether scale effects the translation.
Would anyone be able to explain to me how to correctly do this?
Upvotes: 0
Views: 1815
Reputation: 9062
The three lines would be:
glScalef(1.0/.5, 1.0/2, 1.0/1);
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
glTranslatef(0, -1, 0);
Basically you need to perform inverse transformations in reverse order. You start with scaling. Inverse for scaling would be to scale back but this time with 1/factor. Then you rotate it back by 90 degrees and translate back 1 unit on y axis.
Upvotes: 3