4. void polygon(int a, int b, int c , int d)
/* draw a polygon via list of vertices */
{
glBegin(GL_POLYGON);
glColor3fv(colors[a]);
glVertex3fv(vertices[a]);
glColor3fv(colors[b]);
glVertex3fv(vertices[b]);
glColor3fv(colors[c]);
glVertex3fv(vertices[c]);
glColor3fv(colors[d]);
glVertex3fv(vertices[d]);
glEnd();
}
5. /* map vertices to faces */
void colorcube()
{
polygon(0,3,2,1); // front face – counter clockwise
polygon(4,5,6,7); // back face – clockwise
polygon(2,3,7,6); // front face – counter clockwise
polygon(1,5,4,0); // back face – clockwise
polygon(1,2,6,5); // front face – counter clockwise
polygon(0,4,7,3); // back face – clockwise
}
0 3
1 2
4 7
5 6
11. View volume - Projections
Two types of Projections:
• Orthographic (parallel) projections :
the view volume is box-shaped
• perspective projections :
have a view volume shaped like a truncated
pyramid.
13. Perspective Projection
• Objects outside the view volume not displayed.
• View volume has two planes.
• The front face is called near plane.
• The back face is called far plane.
• All vertical planes from near plane to far plane define the
clipping area.
16. void glFrustum(GLdoubleleft, GLdoubleright, GLdoublebottom,
GLdoubletop,GLdoublenear, GLdoublefar)
glFrustum computes a viewing frustum in the world coordinates.
• left and right
• Specify the coordinates for the left and right vertical clipping
planes.
• bottom and top
• Specify the coordinates for the bottom and top horizontal
clipping planes.
• near and far
• Specify the distances to the near and far depth clipping planes.
Both distances must be positive.
• Note: “near” and “far” are only clipping planes. Neither of them
have anything to do with the projection plane.
Perspective Projection