import java.io.*; import java.lang.*; /** * Material describes the surface properties of an object using * ambient, diffuse and specular components. * * @author Anthony Steed * @version 1.0 */ public class Material { /** * Holds the ambient component of this surface */ public Colour Ambient; /** * Holds the ambient component of this surface */ public Colour Diffuse; /** * Holds the specular component of this surface */ public Colour Specular; /** * Holds the shininess factor this surface */ public double Shininess; /** * Create a default material */ public Material() { Ambient = new Colour(); Diffuse = new Colour(); Specular = new Colour(); Shininess = 0.0; } /** * Create a new material by copying an existing material. * @param m the material to copy */ public Material(Material m) { Ambient = new Colour(m.Ambient); Diffuse = new Colour(m.Diffuse); Specular = new Colour(m.Specular); Shininess = m.Shininess; } /** * Read the material 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 { Ambient.read(is); Diffuse.read(is); Specular.read(is); Shininess = is.readDouble(); } /** * Write the material 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 { Ambient.write(os); Diffuse.write(os); Specular.write(os); os.writeDouble(Shininess); os.writeChar(' '); } /** * Print a human readable version of the material 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("Material: ambient "); Ambient.print(os); os.writeString(" diffuse "); Diffuse.print(os); os.writeString(" specular "); Specular.print(os); os.writeString(" shininess "); os.writeDouble(Shininess); os.writeString("\n"); } }