Commits

jfinkels  committed 0d0a304

added HasViewingSystem interface

  • Participants
  • Parent commits 641b534

Comments (0)

Files changed (5)

File assignment4/src/main/java/edu/bu/cs/cs480/HasViewingSystem.java

+/**
+ * HasViewingSystem.java -
+ */
+package edu.bu.cs.cs480;
+
+import edu.bu.cs.cs480.camera.Camera;
+import edu.bu.cs.cs480.camera.Resolution;
+import edu.bu.cs.cs480.camera.Viewport;
+
+/**
+ * @author Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>
+ * @since Spring 2011
+ */
+public interface HasViewingSystem {
+
+  /**
+   * Sets the virtual camera through which the scene is viewed.
+   * 
+   * @param camera
+   *          The virtual camera through which the scene is viewed.
+   */
+  void setCamera(final Camera camera);
+
+  /**
+   * Sets the resolution of the scene when displayed in the viewport.
+   * 
+   * @param resolution
+   *          The resolution of the scene when displayed in the viewport.
+   */
+  void setResolution(final Resolution resolution);
+
+  /**
+   * Sets the dimensions of the viewport in which the scene is displayed.
+   * 
+   * @param viewport
+   *          The dimensions of the viewport in which the scene is displayed.
+   */
+  void setViewport(final Viewport viewport);
+  
+
+  /**
+   * Gets the virtual camera through which the scene is viewed.
+   * 
+   * @return The virtual camera through which the scene is viewed.
+   */
+  Camera camera();
+
+  /**
+   * Gets the resolution of the scene when displayed in the viewport.
+   * 
+   * @return The resolution of the scene when displayed in the viewport.
+   */
+  Resolution resolution();
+
+  /**
+   * Gets the dimensions of the viewport in which the scene is displayed.
+   * 
+   * @return The dimensions of the viewport in which the scene is displayed.
+   */
+  Viewport viewport();
+}

File assignment4/src/main/java/edu/bu/cs/cs480/ViewingSystemSupport.java

+/**
+ * ViewingSystemSupport.java -
+ */
+package edu.bu.cs.cs480;
+
+import edu.bu.cs.cs480.camera.Camera;
+import edu.bu.cs.cs480.camera.Resolution;
+import edu.bu.cs.cs480.camera.Viewport;
+
+/**
+ * @author Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>
+ * @since Spring 2011
+ */
+public class ViewingSystemSupport implements HasViewingSystem {
+
+  /** The virtual camera through which the scene is viewed. */
+  private Camera camera = null;
+  /** The resolution of the scene when displayed in the viewport. */
+  private Resolution resolution = null;
+  /** The dimensions of the viewport in which the scene is displayed. */
+  private Viewport viewport = null;
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @return {@inheritDoc}
+   */
+  @Override
+  public Viewport viewport() {
+    return this.viewport;
+  }
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @return {@inheritDoc}
+   */
+  @Override
+  public Camera camera() {
+    return this.camera;
+  }
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @return {@inheritDoc}
+   */
+  @Override
+  public Resolution resolution() {
+    return this.resolution;
+  }
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @param camera
+   *          {@inheritDoc}
+   */
+  @Override
+  public void setCamera(final Camera camera) {
+    this.camera = camera;
+  }
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @param resolution
+   *          {@inheritDoc}
+   */
+  @Override
+  public void setResolution(final Resolution resolution) {
+    this.resolution = resolution;
+  }
+
+  /**
+   * {@inheritDoc}
+   * 
+   * @param viewport
+   *          {@inheritDoc}
+   */
+  @Override
+  public void setViewport(final Viewport viewport) {
+    this.viewport = viewport;
+  }
+}

File assignment4/src/main/java/edu/bu/cs/cs480/camera/RayGenerator.java

 
 import edu.bu.cs.cs480.Ray;
 import edu.bu.cs.cs480.Vector3D;
+import edu.bu.cs.cs480.ViewingSystemSupport;
 
 /**
  * Generates rays at a specified position with respect to a given camera,
  * @author Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>
  * @since Spring 2011
  */
-public class RayGenerator {
-
-  /** The virtual camera through which the scene is viewed. */
-  private Camera camera = null;
-  /** The resolution of the scene when displayed in the viewport. */
-  private Resolution resolution = null;
-  /** The dimensions of the viewport in which the scene is displayed. */
-  private Viewport viewport = null;
+public class RayGenerator extends ViewingSystemSupport {
 
   /** Instantiates this class without setting any properties. */
   public RayGenerator() {
    */
   public Ray generateRay(final int row, final int column) {
     // compute location of pixel on view plane
-    final double du = (column - (this.viewport.width() / 2.0) + 1)
-        * this.resolution.xResolution();
-    final double dv = -(row - (this.viewport.height() / 2.0) + 1)
-        * this.resolution.yResolution();
+    final double du = (column - (this.viewport().width() / 2.0) + 1)
+        * this.resolution().xResolution();
+    final double dv = -(row - (this.viewport().height() / 2.0) + 1)
+        * this.resolution().yResolution();
 
     // get the vectors which define the camera's basis
-    final Vector3D c = this.camera.position();
-    final Vector3D n = this.camera.direction();
-    final Vector3D v = this.camera.up();
+    final Vector3D c = this.camera().position();
+    final Vector3D n = this.camera().direction();
+    final Vector3D v = this.camera().up();
     final Vector3D u = v.crossProduct(n);
 
     // convert (du, dv) to location in scene coordinates using the camera's
     // basis vectors
-    final Vector3D temp1 = n.scaledBy(this.camera.focalLength());
+    final Vector3D temp1 = n.scaledBy(this.camera().focalLength());
     final Vector3D temp2 = u.scaledBy(du);
     final Vector3D temp3 = v.scaledBy(dv);
     final Vector3D origin = c.sumWith(temp1).sumWith(temp2).sumWith(temp3);
 
     // compute the direction of the ray with respect to the camera and position
-    final Vector3D direction = this.camera.rayDirection(origin);
+    final Vector3D direction = this.camera().rayDirection(origin);
 
     final Ray result = new Ray();
     result.setPosition(origin);
     return result;
   }
 
-  /**
-   * Sets the virtual camera through which the scene is viewed.
-   * 
-   * @param camera
-   *          The virtual camera through which the scene is viewed.
-   */
-  public void setCamera(final Camera camera) {
-    this.camera = camera;
-  }
-
-  /**
-   * Sets the resolution of the scene when displayed in the viewport.
-   * 
-   * @param resolution
-   *          The resolution of the scene when displayed in the viewport.
-   */
-  public void setResolution(final Resolution resolution) {
-    this.resolution = resolution;
-  }
-
-  /**
-   * Sets the dimensions of the viewport in which the scene is displayed.
-   * 
-   * @param viewport
-   *          The dimensions of the viewport in which the scene is displayed.
-   */
-  public void setViewport(final Viewport viewport) {
-    this.viewport = viewport;
-  }
 }

File assignment4/src/main/java/edu/bu/cs/cs480/rendering/DefaultRenderingEnvironment.java

 import java.util.ArrayList;
 import java.util.List;
 
-import edu.bu.cs.cs480.camera.Camera;
-import edu.bu.cs.cs480.camera.Resolution;
-import edu.bu.cs.cs480.camera.Viewport;
+import edu.bu.cs.cs480.ViewingSystemSupport;
 import edu.bu.cs.cs480.lights.AmbientLight;
 import edu.bu.cs.cs480.lights.Light;
 import edu.bu.cs.cs480.surfaces.SurfaceObject;
  * @author Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>
  * @since Spring 2011
  */
-public class DefaultRenderingEnvironment implements RenderingEnvironment {
+public class DefaultRenderingEnvironment extends ViewingSystemSupport
+    implements RenderingEnvironment {
   /** The list of all lights in the scene which are ambient lights. */
   private List<AmbientLight> ambientLights = new ArrayList<AmbientLight>();
-  /** The virtual camera through which the scene is viewed. */
-  private Camera camera = null;
   /** The list of light sources for the scene. */
   private List<Light> lights = new ArrayList<Light>();
-  /** The resolution of the scene when displayed in the viewport. */
-  private Resolution resolution = null;
   /** The list of surface objects to be rendered. */
   private List<SurfaceObject> surfaceObjects = new ArrayList<SurfaceObject>();
-  /** The dimensions of the viewport in which the scene is displayed. */
-  private Viewport viewport = null;
 
   /**
    * {@inheritDoc}
    * {@inheritDoc}
    * 
    * @return {@inheritDoc}
-   */
-  @Override
-  public Viewport viewport() {
-    return this.viewport;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @return {@inheritDoc}
-   */
-  @Override
-  public Camera camera() {
-    return this.camera;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @return {@inheritDoc}
-   */
-  @Override
-  public Resolution resolution() {
-    return this.resolution;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @param camera
-   *          {@inheritDoc}
-   */
-  @Override
-  public void setCamera(final Camera camera) {
-    this.camera = camera;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @param resolution
-   *          {@inheritDoc}
-   */
-  @Override
-  public void setResolution(final Resolution resolution) {
-    this.resolution = resolution;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @param viewport
-   *          {@inheritDoc}
-   */
-  @Override
-  public void setViewport(final Viewport viewport) {
-    this.viewport = viewport;
-  }
-
-  /**
-   * {@inheritDoc}
-   * 
-   * @return {@inheritDoc}
    * 
    * @see edu.bu.cs.cs480.rendering.RenderingEnvironment#lights()
    */

File assignment4/src/main/java/edu/bu/cs/cs480/rendering/RenderingEnvironment.java

 
 import java.util.List;
 
-import edu.bu.cs.cs480.camera.Camera;
-import edu.bu.cs.cs480.camera.Resolution;
-import edu.bu.cs.cs480.camera.Viewport;
+import edu.bu.cs.cs480.HasViewingSystem;
 import edu.bu.cs.cs480.lights.AmbientLight;
 import edu.bu.cs.cs480.lights.Light;
 import edu.bu.cs.cs480.surfaces.SurfaceObject;
  * @author Jeffrey Finkelstein <jeffrey.finkelstein@gmail.com>
  * @since Spring 2011
  */
-public interface RenderingEnvironment {
+public interface RenderingEnvironment extends HasViewingSystem {
   /**
    * Adds the specified light to the scene.
    * 
   void addSurfaceObject(final SurfaceObject surfaceObject);
 
   /**
-   * Sets the virtual camera through which the scene is viewed.
-   * 
-   * @param camera
-   *          The virtual camera through which the scene is viewed.
-   */
-  void setCamera(final Camera camera);
-
-  /**
-   * Sets the resolution of the scene when displayed in the viewport.
-   * 
-   * @param resolution
-   *          The resolution of the scene when displayed in the viewport.
-   */
-  void setResolution(final Resolution resolution);
-
-  /**
-   * Sets the dimensions of the viewport in which the scene is displayed.
-   * 
-   * @param viewport
-   *          The dimensions of the viewport in which the scene is displayed.
-   */
-  void setViewport(final Viewport viewport);
-
-  /**
    * Gets the list of lights in the scene.
    * 
    * @return The list of lights in the scene.
    */
   List<SurfaceObject> surfaceObjects();
 
-  /**
-   * Gets the virtual camera through which the scene is viewed.
-   * 
-   * @return The virtual camera through which the scene is viewed.
-   */
-  Camera camera();
-
-  /**
-   * Gets the resolution of the scene when displayed in the viewport.
-   * 
-   * @return The resolution of the scene when displayed in the viewport.
-   */
-  Resolution resolution();
-
-  /**
-   * Gets the dimensions of the viewport in which the scene is displayed.
-   * 
-   * @return The dimensions of the viewport in which the scene is displayed.
-   */
-  Viewport viewport();
 }