/** Interactive ray tracing animation scene * Master's Thesis, Univ of Colo, 2001 * @author: Phil Gage */ public class InteractWorld extends World { static int frames = 30; static boolean doAnimate = false; // Define scene layout InteractWorld (Grid grid) { super(grid); // Define a light source for the sun Light light = new Light( new Vector3(-100.0, -100.0, -50.0), new Color (0.8,0.8,0.8)); Light.ambient = new Color (0.2,0.2,0.2); add(light); add(new Light( new Vector3(100.0, -100.0, 50.0), new Color (0.8,0.8,0.8))); // Checkerboard ground plane double groundY = 100.0; //ground Y coord double groundsize = 800.0; //ground XZ range /* // Round ground disk looks like flat horizon with Cyl camera Ring round = new Ring (new Point(0.0, 100.0, 0.0), //center new Vector3(0.0, -1.0, 0.0), //normal 10.0, 1000.0, // innerRadius, outerRadius, new Color (1.0,1.0,0.0)); round.setMaterial( new CheckerMaterial( new Color (1.0,1.0,1.0), new Color (1.0,0.0,0.0), 100)); // gridSize add(round); */ // Checkerboard ground plane (shows Cyl distortion) 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-1, -groundsize), //min new Point(groundsize, groundY+1, groundsize)), //max new Color (1.0,1.0,1.0)); ground.setMaterial( new CheckerMaterial( new Color (1.0,1.0,1.0), new Color (1.0,0.0,0.0), 100)); // gridSize add(ground); // Define spheres Sphere s = new Sphere(new Point(0.0, 0.0, 500.0), 100.0, new Color (1.0,0.0,0.0)); s.material.ks = 0.99; //mirror s.material.kd = 0.01; add(s); // Snowman /* Color snow = new Color (1.5,1.5,1.5); add(new Sphere(new Point(0.0, 50.0, -500.0), 50.0, snow)); //body add(new Sphere(new Point(0.0, -40.0, -500.0), 40.0, snow)); add(new Sphere(new Point(0.0, -110.0, -500.0), 30.0, snow)); //head add(new Sphere(new Point(20.0,-150.0, -480.0), 10.0, new Color (0.0,0.0,0.0))); //eyes add(new Sphere(new Point(-20.0,-150.0, -480.0), 10.0, new Color (0.0,0.0,0.0))); //eyes */ // Snowman from Movie2 Color snow = new Color (1.5,1.5,1.5); add(new Sphere(new Point( 0.0, 50.0, -500.0), 50.0, snow)); //body add(new Sphere(new Point( 0.0, -20.0, -500.0), 40.0, snow)); add(new Sphere(new Point( 0.0, -80.0, -500.0), 30.0, snow)); //head /* add(new Sphere(new Point( 15.0, -90.0, -520.0), 8.0, new Color (0.0,0.0,0.0))); //eyes add(new Sphere(new Point(-15.0, -90.0, -520.0), 8.0, new Color (0.0,0.0,0.0))); //eyes add(new Sphere(new Point( 0.0, -81.0, -528.0), 6.0, new Color (0.5,0.1,0.0))); //nose add(new Sphere(new Point( 0.0, -70.0, -525.0), 5.0, new Color (0.0,0.0,0.0))); //mouth add(new Sphere(new Point( 10.0, -72.0, -523.0), 5.0, new Color (0.0,0.0,0.0))); //mouth add(new Sphere(new Point(-10.0, -72.0, -523.0), 5.0, new Color (0.0,0.0,0.0))); //mouth */ add(new Sphere(new Point( 15.0, -90.0, -480.0), 8.0, new Color (0.0,0.0,0.0))); //eyes add(new Sphere(new Point(-15.0, -90.0, -480.0), 8.0, new Color (0.0,0.0,0.0))); //eyes add(new Sphere(new Point( 0.0, -81.0, -472.0), 6.0, new Color (0.5,0.1,0.0))); //nose add(new Sphere(new Point( 0.0, -70.0, -475.0), 5.0, new Color (0.0,0.0,0.0))); //mouth add(new Sphere(new Point( 10.0, -72.0, -477.0), 5.0, new Color (0.0,0.0,0.0))); //mouth add(new Sphere(new Point(-10.0, -72.0, -477.0), 5.0, new Color (0.0,0.0,0.0))); //mouth // 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)); add(box); // Define pile of RGB spheres add(new Sphere(new Point(550.0, 0.0, 200.0), 100.0, new Color (1.0,0.0,0.0))); add(new Sphere(new Point(500.0, 0.0, 0.0), 100.0, new Color (0.0,1.0,0.0))); add(new Sphere(new Point(550.0, 0.0, -200.0), 100.0, new Color (0.0,0.0,1.0))); // Define transparent sphere on pile of RGB spheres Sphere st = new Sphere(new Point(530.0, -200.0, 0.0), 100.0, new Color (1.0,1.0,1.0)); st.material.kt = 0.8; //transparent st.material.kd = 0.2; add(st); // Lord of the Rings add( new Ring (new Point(500.0, -200.0, 0.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))); // Define animated sphere class to test temporal coherence // To animate, extend class and override animate() class BouncingSphere extends Sphere { BouncingSphere () { super(new Point(0.0, 80.0, 300.0), 20.0, new Color (1.0,1.0,1.0)); // material.ks = 0.99; //mirror // material.kd = 0.01; // material.specular = 10.0; //Phong } // Override for animation boolean animate (int frame) { frame = frame%frames; if (doAnimate) { //System.out.println("animate!"); // center.y += 100.0*(double)frame; center.y = 4.0*(double)frame*(double)(frames-frame)/(double)(frames*frames); // center.y = -300.0*center.y + 130.0; // center.y = -1.0*center.y + 130.0; //fig center.y = -200.0*center.y + 80.0; return true; } else return false; } } Sphere a = new BouncingSphere (); add(a); } }