The Second Rule of Program Optimization (for experts only!) Don't do it yet. -- Michael Jackson Concept 1.4: Push & Pop - Controlling Transformations ==================================================== Idea ==== In the previous examples by issuing translation commands we have been creating, loading and multiplying the modelview matrices. OpenGL provides two matrix stacks. The modelview matrix stack and the projection matrix stack. Commands used for translation, rotation, scaling and looking at the object affect the modelview matrix stack. Commands for specifying viewing volumes affect the projection matrix stack. A stack of matrices is useful for constructing hierarchical models, which complicated objects are constructed from simpler ones. All matrix operations in OpenGL deal with the current matrix or the top matrix on the stack. OpenGL provides two functions to control what is on top of the stack. glPushMatrix() and glPopMatrix() allow us to isolate transformations. glPushMatrix() copies the current matrix and aadds the copy to the top of the stack, and glPopMatrix() which discards the top matrix on the stack. In effect, glPushMatrix() means, "remember where you are" and glPopMatrix() means "go back to where you were." Experiment ========== Try different values for both the cube and sphere. Notice how by the introduction of glPushMatrix() before each translation call, and glPopMatrix() after rendering the objects, results in independent translations for the cube and the sphere. This should answer the questions posed in Concept1b and Concept1c.