Applet's init( ) Method (the unusual stuff)
// Initialize more defaults if they weren't specified
if (eye == null) eye = new Vector3D(0, 0, 10);
if (lookat == null) lookat = new Vector3D(0, 0, 0);
if (up == null) up = new Vector3D(0, 1, 0);
if (background == null) background = new Color(0,0,0);
// Compute viewing matrix that maps a
// screen coordinate to a ray direction
Vector3D look = new Vector3D(lookat.x - eye.x,
lookat.y - eye.y,
lookat.z - eye.z);
Du = Vector3D.normalize(look.cross(up));
Dv = Vector3D.normalize(look.cross(Du));
float fl = (float)(width / (2*Math.tan((0.5*fov)*Math.PI/180)));
Vp = Vector3D.normalize(look);
Vp.x = Vp.x*fl - 0.5f*(width*Du.x + height*Dv.x);
Vp.y = Vp.y*fl - 0.5f*(width*Du.y + height*Dv.y);
Vp.z = Vp.z*fl - 0.5f*(width*Du.z + height*Dv.z);
}
|