/** Main program to test ray tracer * Bouncing ball on checkerboard animation * @author: Phil Gage */ public class Movie1 { static int width = 320, height = 200; // image size // static int width = 640, height = 480; // image size // static int frames = 1; static int frames = 20; // Define scene layout static World buildWorld () { // Must add grid first Grid grid = new Grid ( new Extent ( new Point(-1000.0, -1000.0, -1000.0), //min new Point( 1000.0, 1000.0, 1000.0)), //max new VoxelIndex (10,10,10)); World world = new World(); // no grid // World world = new World(grid); // use grid // world.camera.pan(0.0,0.0); //azimuth, elevation in degrees // world.camera.zoom(90.0); // field of view in degrees // world.camera.translate(new Point(0.0, 0.0, 0.0)); // eye // Camera cam = new Camera(world); //default camera // AbstractCamera cam = new CylindricalCamera (world); //default camera // AbstractCamera cam = new CylindricalCamera (world,320,200); // AbstractCamera cam = new StandardCamera (world,320,200); // world.add(cam); // cam.zoom(90.0); // field of view in degrees // cam.zoom(20.0); // field of view in degrees // cam.translate(new Point(0.0,0.0,-3000.0)); // eye // world.add(cam); world.background.set(new Color (0.0,0.0,0.3)); // Define a light source for the sun Light light = new Light( new Vector3(-100.0, -100.0, -50.0), new Color (1.5,1.5,1.5)); // Light.ambient = new Color (0.15,0.15,0.15); Light.ambient = new Color (0.2,0.2,0.2); // Light.ambient = new Color (0.1,0.1,0.1); // Light.ambient = new Color (0.7,0.7,0.7); world.add(light); // another light world.add(new Light( new Vector3(100.0, -100.0, 50.0), new Color (1.0,1.0,1.0))); // Checkerboard ground plane double groundY = 150.0; //ground Y coord double groundsize = 400.0; //ground XZ range BoundedPlane ground = new BoundedPlane ( new Point(0.0, groundY, 0.0), //point on plane new Vector3(0.0, -1.0, 0.0), //normal new Extent (new Point(-groundsize, groundY-10, -groundsize), //min new Point(groundsize, groundY+10, groundsize)), //max new Color (1.0,1.0,1.0)); ground.setMaterial( new CheckerMaterial( // new Color (1.0,1.0,1.0), new Color (0.0,0.0,0.0), new Color (1.0,0.0,0.0), 100)); // gridSize world.add(ground); // Define spheres class BouncingSphere extends Sphere { BouncingSphere () { // super(new Point(0.0, 0.0, 500.0), 300.0, new Color (1.0,0.0,0.0)); //temp super(new Point(0.0, 0.0, 0.0), 150.0, new Color (1.0,1.0,1.0)); //temp material.ks = 0.99; //mirror material.kd = 0.01; // material.specular = 10.0; //Fake Phong } boolean animate (int frame) { // center.y += 100.0*(double)frame; center.y = 4.0*(double)frame*(double)(frames-frame)/(double)(frames*frames); center.y = -300.0*center.y + 0.0; return true; // return false; } } // Sphere a = new AnimSphere(new Point(0.0, 0.0, 500.0), 200.0, new Color (1.0,0.0,0.0)); Sphere a = new BouncingSphere (); world.add(a); // Define camera class MovieCamera extends CylindricalCamera { double az = 0.0, el = 0.0; double fov = 90.0; MovieCamera (World world, int width, int height) { super (world, width, height); } /** Override for animation */ void animate (int frame) { // az = 10.0*Math.sin(2.0*Math.PI*(double)frame/(double)frames); az = Math.sin(360.0*(double)frame/(double)frames); az = 1.0*az - 45.0; // az = 10.0*(double)frame; // el = 10.0*(double)frame; pan(az,el); // zoom(fov); // field of view in degrees // cam.translate(new Point(0.0,0.0,-3000.0)); // eye } } AbstractCamera camera = new MovieCamera (world,width,height); world.add(camera); // camera.zoom(90.0); // field of view in degrees camera.zoom(40.0); // field of view in degrees camera.translate(new Point(1000.0,0.0,-1000.0)); // move eye back // Add temporal coherence acceleration // world.enableTemporalCoherence (16,16); // camera.enableTemporalCoherence (2,2); return world; } /** * Main program for command line application. * @param argv command line argument strings */ public static void main (String[] argv) { System.out.println ("Ray tracing..."); long msec = System.currentTimeMillis(); // Define scene and perform raytracing World world = buildWorld (); for (int frame=0; frame