Appendix C. File Obj3D.java

The following file is not a complete program. It is the code for a single class, Obj3D, which is discussed in Section 5.5 and used in the programs Wireframe.java of Chapter 5, HLines.java of Chapter 6, Painter.java of Section 7.3, and ZBuf.java of Section 7.4.

// Obj3D.java: A 3D object and its 2D representation.
// Uses: Point2D (Section 1.5), Point3D (Section 3.9),
//       Polygon3D, Input (Section 5.5).
import java.awt.*;
import java.util.*;

class Obj3D
{  private float rho, d, theta=0.30F, phi=1.3F, rhoMin, rhoMax,
      xMin, xMax, yMin, yMax, zMin, zMax, v11, v12, v13, v21,
      v22, v23, v32, v33, v43, xe, ye, ze, objSize;
   private Point2D imgCenter;
   private double sunZ = 1/Math.sqrt (3) , sunY = sunZ, sunX = -sunZ,
      inprodMin = 1e30, inprodMax = −1e30, inprodRange;
   private Vector w = new Vector();         // World coordinates
   private Point3D[] e;                     // Eye coordinates
   private Point2D[] vScr;                  // Screen coordinates
   private Vector polyList = new Vector();  // Polygon3D objects
private String fName = " "; // File name boolean read(String fName) { Input inp = new Input(fName); if (inp.fails())return failing(); this.fName = fName; xMin = yMin = zMin = +1e30F; xMax = yMax = zMax = −1e30F; return readObject(inp); // Read from inp into obj } Vector getPolyList(){return polyList;} String getFName(){return fName;} Point3D[] getE(){return e;} Point2D[] getVScr(){return vScr;} Point2D getImgCenter(){return imgCenter;} float getRho(){return rho;} float getD(){return d;} private boolean failing() ...

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.