/** Main program to test ray tracer * Bouncing random balls on checkerboard animation * @author: Phil Gage */ public class Movie3 { 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 Point(-1101.0, -800.0, -2101.0), //min new Point( 1101.0, 10.0, 1101.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); world.add(new Sphere(new Point(-10000.0, -6000.0, -1000.0), 1000.0, new Color (2.0,2.0,0.0)));//sun // 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 = 0.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-100, -groundsize), //min new Point(groundsize, groundY+100, 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 RGB spheres world.add(new Sphere(new Point(500.0, -1000.0, 0.0), 100.0, new Color (1.0,0.0,0.0))); world.add(new Sphere(new Point(-500.0, -1000.0, 0.0), 100.0, new Color (0.0,1.0,0.0))); world.add(new Sphere(new Point(500.0, -1000.0, -1000.0), 100.0, new Color (0.0,0.0,1.0))); // Define spheres class BouncingSphere extends Sphere { // final double radius = 150; // Color color = new Color (1.0,1.0,1.0); int frameoffset = (int)((double)frames*Math.random()); // BouncingSphere () { BouncingSphere (double x, double z, double radius) { // 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 // super(new Point(x, -radius, z), radius, color); //temp super(new Point(x+100.0, -radius, z+100.0), radius, 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) { frame = (frame + frameoffset) % frames; // 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 = -700.0*center.y - radius; 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)); for (double x=-800.0; x<799.0; x+=200.0) { for (double z=-800.0; z<799.0; z+=200.0) { // Sphere a = new BouncingSphere (); Sphere a = new BouncingSphere (x,z,50.0); world.add(a); } } // world.add(a); // Define camera class MovieCamera extends CylindricalCamera { double az = 0.0, el = 8.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 - 30.0; az = - 30.0; //temp no pan // 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(50.0); // field of view in degrees camera.translate(new Point(1000.0,-500.0,-2000.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