Applet's init( ) Method
public void init( )
{
// initialize the off-screen rendering buffer
width = size().width;
height = size().height;
screen = createImage(width, height);
gc = screen.getGraphics();
gc.setColor(getBackground());
gc.fillRect(0, 0, width, height);
fov = 30; // default horizonal field of view
// Initialize various lists
objectList = new Vector(CHUNKSIZE, CHUNKSIZE);
lightList = new Vector(CHUNKSIZE, CHUNKSIZE);
currentSurface = new Surface(0.8f, 0.2f, 0.9f, 0.2f, 0.4f, 0.4f, 10.0f, 0f, 0f, 1f);
// Parse the scene file
String filename = getParameter("datafile");
showStatus("Parsing " + filename);
InputStream is = null;
try {
is = new URL(getDocumentBase(), filename).openStream();
ReadInput(is);
is.close();
} catch (IOException e) {
showStatus("Error reading "+filename);
System.err.println("Error reading "+filename);
System.exit(-1);
}
// 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);
}
|