/** Main program to test ray tracer * Bouncing ball on checkerboard animation * with objs from InteractWorld2 * @author: Phil Gage */ public class Movie2 { 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.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 Vector3(100.0, -300.0, -500.0), // new Color (1.0,1.0,1.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); Light.ambient = new Color (0.05,0.05,0.05); world.add(light); // another light overhead world.add(new Light( new Vector3(200.0, -1000.0, 50.0), new Color (0.2,0.2,0.2))); // Checkerboard ground plane double groundY = 100.0; //ground Y coord double groundsize = 800.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), 200)); // gridSize world.add(ground); // ground.material.ks = 0.2; //mirror // ground.material.kd = 0.8; // 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 super(new Point(0.0, 0.0, 0.0), 200.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; center.y = -300.0*center.y - 50.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); //from interact // Snowman Color snow = new Color (1.5,1.5,1.5); world.add(new Sphere(new Point( 0.0, 50.0, -500.0), 50.0, snow)); //body world.add(new Sphere(new Point( 0.0, -20.0, -500.0), 40.0, snow)); world.add(new Sphere(new Point( 0.0, -80.0, -500.0), 30.0, snow)); //head world.add(new Sphere(new Point( 15.0, -90.0, -520.0), 8.0, new Color (0.0,0.0,0.0))); //eyes world.add(new Sphere(new Point(-15.0, -90.0, -520.0), 8.0, new Color (0.0,0.0,0.0))); //eyes world.add(new Sphere(new Point( 0.0, -81.0, -528.0), 6.0, new Color (0.5,0.1,0.0))); //nose world.add(new Sphere(new Point( 0.0, -70.0, -525.0), 5.0, new Color (0.0,0.0,0.0))); //mouth world.add(new Sphere(new Point( 10.0, -72.0, -523.0), 5.0, new Color (0.0,0.0,0.0))); //mouth world.add(new Sphere(new Point(-10.0, -72.0, -523.0), 5.0, new Color (0.0,0.0,0.0))); //mouth // Hat and brim // world.add(new Sphere(new Point( 0.0, -79.0, -502.0), 29.0, snow)); //head // world.add( // new Ring (new Point(0.0, -60.0, -500.0), //center // new Vector3(0.2, -1.0, 0.4), //normal // 10.0, 25.0, // innerRadius, outerRadius, // new Color (0.0,0.0,0.1))); // Box Box box = new Box ( new Extent (new Point(-600.0, -100.0, -100.0), //min new Point(-400.0, 100.0, 100.0)), //max new Color (1.0,0.0,1.0)); world.add(box); // box.material.ks = 0.7; //mirror // box.material.kd = 0.5; // Define pile of RGB spheres world.add(new Sphere(new Point(550.0, 0.0, 200.0), 100.0, new Color (1.0,0.0,0.0))); world.add(new Sphere(new Point(450.0, 0.0, 0.0), 100.0, new Color (0.0,1.0,0.0))); world.add(new Sphere(new Point(550.0, 0.0, -200.0), 100.0, new Color (0.0,0.0,1.0))); // Define transparent sphere Sphere st = new Sphere(new Point(400.0, 0.0, -400.0), 100.0, new Color (1.0,1.0,0.0)); st.material.kt = 0.6; //transparent st.material.kd = 0.4; world.add(st); // Lord of the Rings world.add( new Ring (new Point(400.0, 0.0, -400.0), //center new Vector3(0.2, -1.0, 0.2), //normal 120.0, 150.0, // innerRadius, outerRadius, new Color (1.0,1.0,0.0))); //end from interact // Define camera class MovieCamera extends CylindricalCamera { double az = 0.0, el = 12.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 - 22.5; // 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(70.0); // field of view in degrees camera.translate(new Point(501.0,-301.0,-1001.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