import java.awt.*; import graphics.*; public class hw7 extends ThreeDApplet { Sphere unitSphere; Sphere s; int[] color = {255, 255, 255}; //place to save light direction b4 transform Vector3 lightdir; public void initialize() { super.initialize(); lights = new Light[4]; lights[0] = new Light(0, 0, 1); lights[0].color[0] = lights[0].color[1] = lights[0].color[2] = 255; lights[1] = new Light(1, 0, 0); //pointing right lights[1].color[0] = lights[1].color[1] = lights[1].color[2] = 255; lights[2] = new Light(-1, 0, 0); //pointing left lights[2].color[0] = lights[2].color[1] = lights[2].color[2] = 255; lights[3] = new Light(0, 1, 0); //pointing down lights[3].color[0] = lights[3].color[1] = lights[3].color[2] = 255; ambient[0] = ambient[1] = ambient[2] = 30; //save original light direction for later lightdir = new Vector3(lights[0].getDirection()); unitSphere = new Sphere(50, 50); //unitSphere.uStart = 0.5; //unitSphere.vStart = 0.25; unitSphere.calculate(); } void draw() { //outlineShape(s, color); //drawNormals(s, color, 0.25); drawShape(s); } void animate(long time) { double theta; //restore original light direction lights[0].setDirection(lightdir); s = (Sphere)unitSphere.clone(); s.setDiffuse(0, 0, 120); //s.setSpecular(30, 120, 120, 120); s.setSpecular(8, 0, 0, 120); //lighting transformations push(); theta = 0.001*time; rotateY(theta); double[] newDir = new double[3]; transform(lights[0].getDirection(), newDir); //normalize and set light vector to result Vector3 v = new Vector3(newDir); //v.normalize(); lights[0].setDirection(v); pop(); push(); //scene //move everything out translate(0,0,-15); push(); theta = 0.0005 * time; //rotateY(theta); rotateX(theta/2); rotateX(Math.PI/4); scale(2, 2, 2); transform(s); pop(); pop(); //scene } }