import graphics.*; import java.awt.Event; public class hw9 extends ThreeDApplet { Quadratic unitSphere; Quadratic unitTube; Shape[] hemisphere; Shape[] cylinder; Animation upDown; public void initialize() { super.initialize(); F = 3; //focal length upDown = new Animation(4); upDown.linear = false; upDown.addKeyFrame(0, -3); upDown.addKeyFrame(8, 5); upDown.addKeyFrame(8, 5); upDown.addKeyFrame(20, -3); shapes = new Shape[3]; unitSphere = new Sphere(new Vector3(0, 0, 0), 1); //x2 + y2 - 1 unitTube = new Quadratic(1, 1, 0, 0,0,0, 0,0,0, -1); Plane top = new Plane(0, 1, 0, -1); //y < 1 Plane bot = new Plane(0, -1, 0, -1); //y > -1 //hemisphere may move, but relationship between elements stay same hemisphere = new Shape[2]; hemisphere[0] = unitSphere.deepCopy(); push(); translate(0, 0, -5); transform(hemisphere[0]); pop(); hemisphere[1] = bot; push(); translate(0, 0.75, 0); transform(hemisphere[1]); pop(); //hemisphere[2] = top; //push(); // translate(0, -0.75, 0); // transform(hemisphere[2]); //pop(); cylinder = new Shape[3]; cylinder[0] = unitTube.deepCopy(); cylinder[1] = new Plane(0, 0, 1, -1); cylinder[2] = new Plane(0, 0, -1, -1); push(); translate(0, 3, -15); rotateX(Math.PI/3); for (int i=0; i< cylinder.length; i++) transform(cylinder[i]); pop(); lights = new Light[3]; //lights[0] = new Light(0, 2, 5); lights[0] = new Light(0, 0, 1); //shining towards camera (illuminates off-camera sphere) lights[0].setColor(100, 100, 100); lights[1] = new Light(0, -1, -1); lights[1].setColor(255, 255, 255); lights[2] = new Light(0, 0, -1); lights[2].setColor(100, 100, 100); ambient[0] = ambient[1] = ambient[2] = 30; } public void animate(long time) { //semicircle shapes[0] = new ConvexIntersection(hemisphere); shapes[0].setDiffuse(25, 25, 175); shapes[0].setSpecular(10, 0, 0, 150); shapes[0].reflectiveness = 0.75; shapes[0].refIndex = 1.1; shapes[0].transparency = 0.5; //egg shape shapes[1] = unitSphere.deepCopy(); shapes[1].setDiffuse(50, 125, 125); shapes[1].setSpecular(30, 100, 100, 100); shapes[1].reflectiveness = 1; //off-camera sphere, but still has a presence shapes[2] = unitSphere.deepCopy(); shapes[2].setDiffuse(0, 255, 255); shapes[2].setSpecular(30, 255, 255, 255); /* shapes[3] = new ConvexIntersection(cylinder); shapes[3].setDiffuse(0, 75, 75); shapes[3].setSpecular(3, 75, 75, 75); */ //egg push(); //translate(0, 0, -0.0001 * time); translate(0, 0, -6); rotateY(Math.PI/4); rotateZ(0.0001 * time); scale(0.6, 0.35, 0.6); transform(shapes[1]); pop(); push(); translate(0, -1.25, 5); translate(0, upDown.get(0.001*time), 0); //move up and down transform(shapes[2]); pop(); } //event handling public boolean keyDown(java.awt.Event evt, int key) { switch (key) { case Event.UP: doReflections = true; break; case Event.DOWN: doReflections = false; break; case Event.RIGHT: doRefraction = true; break; case Event.LEFT: doRefraction = false; break; } return true; } }