import java.util.Vector; /** * 3D world scene model, including objects, lights and camera. * Defines everything needed for ray tracer to generate image. * @author: Phil Gage */ class World { /** Animation frame number (time index) incremented each frame */ int frame = 0; /** Default background color (sky blue) */ Color background = new Color(0.0,0.0,0.5); /** List of objects in scene */ Vector objects = new Vector(); /** List of lights illuminating scene */ Vector lights = new Vector(); /** List of cameras at observer viewpoints */ Vector cameras = new Vector(); /** List of viewports that sample cameras */ Vector viewports = new Vector(); /** Optional uniform spatial grid for acceleration */ Grid grid = null; /** Create world without uniform spatial grid */ World () { } /** Create world with uniform spatial grid */ World (Grid grid) { this.grid = grid; } /** Add an object to world */ void add (AbstractObject obj) { objects.addElement(obj); if (grid != null) grid.addObject (obj, obj.getExtent()); } /** Delete an object from world */ void delete (AbstractObject obj) { objects.removeElement(obj); if (grid != null) grid.deleteObject (obj, obj.getExtent()); } /** Add a light to scene */ void add (Light light) { //AbstractLight? lights.addElement(light); } /** Delete a light from scene */ void delete (Light light) { //AbstractLight? lights.removeElement(light); } /** Add a camera to scene */ void add (AbstractCamera camera) { cameras.addElement(camera); } /** Delete a camera from scene */ void delete (AbstractCamera camera) { cameras.removeElement(camera); } /** Add a viewport to scene */ void add (Viewport viewport) { viewports.addElement(viewport); } /** Delete a viewport from scene */ void delete (Viewport viewport) { viewports.removeElement(viewport); } /** Return background color if no intersections (can override to do clouds, stars, etc) */ Color getBackground (Vector3 direction) { return background; } /** Top method to render next animation frame */ void animate() { Light light; AbstractObject obj; AbstractCamera camera; Viewport viewport; Extent oldExtent, newExtent; boolean objectChanged = false; boolean changed; // Start collecting stats on this frame Statistics.beginFrame (frame); // Tell all lights, objects and cameras to update themselves // for the next animation frame (lights, cameras, action!) // Update lights to current frame time // This package does not support fast redraw after light changes // The Jevans coherence method supports this, but not too well // (could save ray trees or light shading factors, but beyond // the scope of this package...) for (int i=0; i