/** Main program to test ray tracer grid * @author: Phil Gage */ public class GridTest { static int width = 320, height = 200; // image size // static int width = 640, height = 480; // image size // static int width = 10, height = 10; // image size // static int width = 1, height = 1; // image size static int frames = 2; // Define scene layout static World buildWorld () { // World world = new World(); // Must add grid first /* Grid grid = new Grid ( new Extent ( // new Point( 0.0, 0.0, 0.0), //min new Point( -100.0, -100.0, -100.0), //min new Point(100.0, 100.0, 100.0)), //max new VoxelIndex (10,10,10)); */ Grid grid = new Grid ( new Extent ( // new Point( 0.0, 0.0, 0.0), //min new Point(-1000.0, -1000.0, -1000.0), //min new Point( 1000.0, 1000.0, 1000.0)), //max new VoxelIndex (10,10,10)); // world.add(grid); // World world = new World(); World world = new World(grid); // Define a light source for the sun Light light = new Light( new Vector3(-100.0, -100.0, -50.0), new Color (1.0,1.0,1.0)); world.add(light); // Define spheres // Sphere s = new Sphere(new Point(50.0, 50.0, 50.0), 1.0, new Color (1.0,0.0,0.0)); // Sphere s = new Sphere(new Point(-50.0, -50.0, -50.0), 1.0, new Color (1.0,0.0,0.0)); Sphere s = new Sphere(new Point(0.0, 0.0, 500.0), 200.0, new Color (1.0,0.0,0.0)); // world.add(s); class AnimSphere extends Sphere { AnimSphere () { // super(new Point(0.0, 0.0, 500.0), 300.0, new Color (1.0,0.0,0.0)); //temp super(new Point(500.0, -500.0, 500.0), 200.0, new Color (1.0,0.0,0.0)); //temp } boolean animate (int frame) { center.y += 100.0*(double)frame; 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 AnimSphere(); world.add(a); // AbstractCamera cam = new CylindricalCamera (world,width,height); 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 = 40.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 cam = new MovieCamera (world,320,200); world.add(cam); cam.zoom(90.0); // field of view in degrees // Add temporal coherence acceleration // world.enableTemporalCoherence (16,16); cam.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 (); /* // test ray // Vector3 v = new Vector3(100.0, 100.0, 100.0); Vector3 v = new Vector3(-100.0, -100.0, -100.0); // Vector3 v = new Vector3(1.0, 0.0, 0.0); // Vector3 v = new Vector3(1.0, 2.0, 3.0); // Vector3 v = new Vector3(-1.0, -2.0, -3.0); v.normalize(); world.grid.traverse ( new Ray ( new Point( 0.0, 0.0, 0.0), // new Point( 99.0, 99.0, 99.0), // new Vector3(100.0, 100.0, 100.0)), v), false, null, new Intersection() ); */ for (int frame=0; frame