CHAPTER 4 Geometric Transformations: The Pipeline Vivian by Richard S. Wright Jr.
Transformation Terminology Viewing Modeling Modelview Projection Viewport
+x +y +z Eye Coordinates -x -y -x -y
Viewing Transformations +x +y +z -x -y (0,0,0)
Translation Rotation Scaling Modeling Transformations
+y +x +y +x +y +x +y +x +y +x +y +x rotation/translation and translation/rotation. θ θ
+x +y +z +x +y +z The Modelview Duality
Projection Transformations OrthographicPerspective
The Matrix: Mathematical Currency for 3D Graphics What is matrix?
The Transformation Pipeline 11 vertexvertex Modelview Matrix Projection Matrix Perspective Division Viewport Transform Modelview Projection object eye clip normalized device window other calculations here –material color –shade model (flat) –polygon rendering mode –polygon culling –clipping
glTranslatef(x, y, z); glRotatef(angle, x, y, z); glScalef(x, y, z); glLoadIdentity(); The Modelview Matrix
Transformation functions - Translate glTranslatef(x, y, z); Ex: glTranslatef(0.0f, 10.0f, 0.0f);
Transformation functions - Rotate glRotatef(angle, x, y, z); Ex: glRotatef(45.0f, 1.0f, 1.0f, 1.0f);
Transformation functions - Scale glScalef(x, y, z); Ex: glScalef(2.0f, 1.0f, 2.0f);
Transformation functions - The Identity Matrix glLoadIdentity();
Matrix Stack glPushMatrixglPopMatrix glGet(GL_MAX_MODELVIEW_STACK_DEPTH) The Matrix Stacks
A Nuclear Example // First Electron Orbit // Save viewing transformation glPushMatrix(); // Rotate by angle of revolution glRotatef(fElect1, 0.0f, 1.0f, 0.0f); // Translate out from origin to orbit distance glTranslatef(90.0f, 0.0f, 0.0f); // Draw the electron glutSolidSphere(6.0f, 15, 15); // Restore the viewing transformation glPopMatrix();
A Nuclear Example(cont.) // Second Electron Orbit glPushMatrix(); glRotatef(45.0f, 0.0f, 0.0f, 1.0f); glRotatef(fElect1, 0.0f, 1.0f, 0.0f); glTranslatef(-70.0f, 0.0f, 0.0f); glutSolidSphere(6.0f, 15, 15); glPopMatrix(); // Third Electron Orbit glPushMatrix(); glRotatef(360.0f, -45.0f, 0.0f, 0.0f, 1.0f); glRotatef(fElect1, 0.0f, 1.0f, 0.0f); glTranslatef(0.0f, 0.0f, 60.0f); glutSolidSphere(6.0f, 15, 15); glPopMatrix();
Using Projections Orthographic Projections Perspective Projections
Frustum nearfar Perspective viewing volume w h
// Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection gluPerspective(60.0f, fAspect, 1.0, 400.0);
Advanced Matrix Manipulation GLfloat matrix[16]; // Nice OpenGL friendly matrix Translation/location
Loading a Matrix glLoadMatrixf(GLfloat m); void glLoadTransposeMatrixf(Glfloat* m); // Load an identity matrix GLfloat m[] = { 1.0f, 0.0f, 0.0f, 0.0f, // X Column 0.0f, 1.0f, 0.0f, 0.0f, // Y Column 0.0f, 0.0f, 1.0f, 0.0f, // Z Column 0.0f, 0.0f, 0.0f, 1.0f }; // Translation glMatrixMode(GL_MODELVIEW); glLoadMatrixf(m);