THE GEORGE WASHINGTON UNIVERSITY
School of Engineering and Applied Science
Department of Computer Science

CS 185
Interactive Computer Graphics I
Fall 2003

Professor J. L. Sibert

Assignment 5

Due November 24

Write a program to read in the description of a polygonal object (the house) and display it using a perspective projection. Use the "synthetic camera" viewing method we discussed in class to look at the house from several positions.  Specifically, you must demonstrate at least the following views of the house:

Number 1:  (this is the default view for the demo applet)
camera position (8,8,74)
center of attention (8,8,54)
view up (0,1,0)
width 20
height 20
focal length 20

Number 2:
camera position (8,8,174)
center of attention (8,8,54)
view up (0,1,0)
width 20
height 20
focal length 20

Number 3:
camera position (8,8,74)
center of attention (8,4,47)
view up (1,1,0)
width 20
height 20
focal length 20

Number 4:
camera position (8,50,-74)
center of attention (8,6,47)
view up (1,-1,1)
width 20
height 20
focal length 120

You may read the camera viewing parameters in from a file, you don't need to put a nice gui on the applet.

Hints: (not on handout) Since the camera will need to do a homogenize step, it is probably a good idea to add a homogenize method to your MyPolygon3d class.  If you have not already done so, you should probably add a render method to your MyPolygon3d class as well.  


The following specification for the camera should work with my test applet, if you follow it carefully.

  //Synthetic camera class
import java.awt.*;

public class MyCamera  {

//default constructor

public MyCamera(){

} //constructor

// methods: sets

public void setcp(MyPoint3d p){
//set camera position
} //setcp

public void setcoa(MyPoint3d p){
//set center of attention
} //setcoa

public void setvup(MyPoint3d p){
} //setvup

public void setwidth( double w){
} //setwidth

public void setheight( double h){
} //setheight

public void setfocal( double f){
} //setfocal length

public void setViewport(MyViewport v){}

//set window is not required, recall that the camera computes the window


// methods: gets
public MyPoint3d getcp(){
//get camera position
} //getcp

public MyPoint3d getcoa(){
//get center of attention
} //getcoa

public MyPoint3d getvup(){
} //getvup

public double getwidth(){
} //getwidth

public double getheight(){
} //getheight

public double getfocal(){
} //getfocal length


// methods: transformation
public void transform(){
// this method resets the viewing transformation based on the current values of its parameters
}//transform


   
//methods: display a polygon
public void display (MyPolygon3d p, Graphics g){

}// display
} //MyCamera class

 
 
 
 This is the paint method of my test applet.

public void paint (Graphics g) {
// viewport boundary
 g.setColor(new Color(0.0f,0.0f,1.0f));// blue
 drawViewport();//  just draws 4 lines

 g.setColor(new Color(0.0f,0.0f,0.0f));//black

     for (int i=1; i<npolys; i++){
     cam.display(polys[i], g);}//for  displays each polygon in turn
     
   g.setColor(new Color(1.0f,0.0f,0.0f));
   cam.display(polys[0],g); // draw "front" in red
} //paint


Its init method:

public void init () {

    initComponents();// initializes the GUI
    read();//  reads in house definition  stores in an array of MyPolygon3d
    cam = new MyCamera();
    cam.setwidth(20);
    cam.setheight(20);
    cam.setfocal(20);
    cam.setcoa(new MyPoint3d(8,8,54));
    cam.setcp(new MyPoint3d(8,8,74)); //set up first view
   
    cam.transform(); // cam sets viewing transform

    cam.setViewport(new MyViewport(
            new MyPointNDC( 0.2, 0.1),
            new MyPointNDC(0.8,0.7)));
   
}// init


That's pretty much it, the 400 other lines deal with the GUI.