import java.io.*; import java.lang.*; /** * DirectionalLight represents a light source that illuminates along * parallel rays. * * @author Anthony Steed * @version 1.0 */ public class DirectionalLight extends Light { /** * Stores the direction the light travels in. */ public Vector Direction; /** * Create a default light. */ public DirectionalLight() { Intensity = new Colour(1.0,1.0,1.0); Direction = new Vector(1.0,1.0,1.0); } /** * Create a new directional light that shines along given * direction vector. * @param v the direction of the light rays */ public DirectionalLight(Vector v) { Intensity = new Colour(1.0,1.0,1.0); Direction = v; } /** * Read the light from the given source. * @param is the source to read from. * @exception java.io.IOException * if the light can not be read. * @exception java.io.NumberFormatException * if there a number format error is encountered. */ public void read(SceneReader is) throws IOException, NumberFormatException { Intensity.read(is); Direction.read(is); } /** * Write the light to the given destination * @param os The destination to write to * @exception java.io.IOException * if the write fails. */ public void write(SceneWriter os) throws IOException { Intensity.write(os); os.writeChar(' '); Direction.write(os); } /** * Print a human readable version of the light definition to the * given destination * @param os The destination to write to * @exception java.io.IOException * if the write fails. */ public void print(SceneWriter os) throws IOException { os.writeString("Directional light with colour: "); Intensity.print(os); os.writeString(" and direction: "); Direction.print(os); os.writeString("\n"); } }