Chapter 7. Hidden-Face Elimination

In the previous two chapters we have discussed the wire-frame model and how to remove hidden-lines of 3D objects. For example, a realistic looking cube is displayed by simply drawing all the visible edges of the cube. Instead, we can construct a polygon for each of the six faces. If we display only the visible faces, we obtain a more realistic image of a cube. In Exercise 5.2 this was done by displaying only the top, right and front faces, taking the chosen viewpoint into account. Recall that we used θ = 0.3 and φ = 1.3 (both in radians) at the beginning of class Obj in program CubePers.java. The solution of Exercise 5.2 will fail, for example, if we use θ = −0.3 because then the left instead of the right face of the cube (see Figure 5.10) should be displayed as a filled polygon. In this chapter, the viewpoint will be taken care of automatically, so that the invisible faces of a cube, also known as back faces, are omitted regardless of the chosen viewpoint. Besides, a face may be only partly visible, which is the case, for example, if we have two cubes, with the nearer one partly hiding the farther one. The problem of displaying only the visible portions of faces will also be solved in this chapter. Finally, instead of taking just some colors, we will assume that there is a source of light, such as the sun, to determine the brightness or darkness of a face. Except for Section 7.1, we will display all faces of 3D objects in shades of yellow, against ...

Get Computer Graphics for Java Programmers, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.