public class hw9 extends MISApplet { Surface[] objects=new Surface[4]; Light L1[]=new Light[2]; double[] orig=new double[] {0.0,0.0,0.0}; double fL=3.0; double[] v=new double[3]; double[] w=new double[3]; double[][][] rgbD; public void initialize(){ // setting the materials material mGris=new material(); mGris.setAmbient(new double[] {0.1,0.1,0.1}); mGris.setDiffuse(new double[] {0.1,0.1,0.1}); material mGris2=new material(); mGris2.copy(mGris); mGris.setSpecular(new double[] {0,0,0}); mGris2.setSpecular(new double[] {0.1,0,0.1}); material mRed=new material(); mRed.setAmbient(new double[] {0.2,0,0}); mRed.setSpecular(new double[] {1,1,1}); mRed.setDiffuse(new double[] {0.5,0,0}); mRed.setRefractive(new double[] {0.5,0,0}); mRed.p=4; material mBlue=new material(); mBlue.copy(mRed); mBlue.setDiffuse(new double[] {0,0,0.5}); mBlue.setAmbient(new double[] {0,0,0.2}); material mOr=new material(); mOr.copy(mRed); mOr.setAmbient(new double[] {0.4,0.4,0}); // building objects Plane[] faces=new Plane[7]; faces[0]=new Plane(new double[] {-1,0,0,-1},mGris); faces[1]=new Plane(new double[] {1,0,0,-1},mGris); faces[2]=new Plane(new double[] {0,-1,0,-1},mGris); faces[3]=new Plane(new double[] {-1,1,0,-2},mRed); faces[4]=new Plane(new double[] {0,0,-1,-1},mBlue); faces[5]=new Plane(new double[] {0,0,1,-1},mBlue); faces[6]=new Plane(new double[] {1,1,0,-2},mRed); objects[0]=new Polyhedron(faces); objects[1]=new Polyhedron(faces); objects[2]=new sphere(0.2, mOr, 0 , 0, 0); Plane[] faces1=new Plane[6]; faces1[0]=new Plane(new double[] {-1,0,0,-1},mGris2); faces1[1]=new Plane(new double[] {1,0,0,-1},mGris2); faces1[2]=new Plane(new double[] {0,-1,0,-1},mGris2); faces1[3]=new Plane(new double[] {0,1,0,-1},mGris2); faces1[4]=new Plane(new double[] {0,0,-1,-1},mGris2); faces1[5]=new Plane(new double[] {0,0,1,-1},mGris2); objects[3]=new Polyhedron(faces1); // objects[3]=new Polyhedron(); // objects[3].cube(mRed); //setting transformations Matrix3D tfHouse1=new Matrix3D(); tfHouse1.scaleMatrix(0.2,0.2,0.3); Matrix3D tfHouse2=new Matrix3D(); tfHouse2.copy(tfHouse1); tfHouse1.rotateY(Math.PI/3); tfHouse1.translate(-0.5,-0.3,-5); tfHouse2.rotateY(-Math.PI/5); tfHouse2.translate(0.4,-0.3, -3); objects[0].setTransfo(tfHouse1); objects[1].setTransfo(tfHouse2); Matrix3D tfSun=new Matrix3D(); tfSun.translationMatrix(1.1,1,-7); objects[2].setTransfo(tfSun); Matrix3D tfGround=new Matrix3D(); tfGround.scaleMatrix(3,3,3); tfGround.translate(0,-3.5,-3); objects[3].setTransfo(tfGround); //setting lights L1[0]=new Light(); L1[0].setDir(new double[] {0.3,0.3,-4}); L1[0].setRgb(new double[] {1,1,0}); L1[1]=new Light(); L1[1].setDir(new double[] {0,0,1}); L1[1].setRgb(new double[] {1,1,1}); v[0]=0; v[1]=0; v[2]=0; rgbD=new double[W][H][3]; } public void initFrame(double time) { // L1[0].setDir(new double[] {0,Math.sin(time),Math.cos(time)}); for (int i=0;i255) rgb[j]=255; } } //--------------------------------------------------------- public double[] rayTraceSurf(double[] v, double[] w, int howManyRefl, double n1){ double t=10000; int ind=-1; double[] res=new double[3]; for (int i=0; i< objects.length; i++){ double[] tmptc=objects[i].intersections(v,w); double tc=tmptc[0]; double tc1=tmptc[1]; if (tc>=tc1) continue; if (tc<=t & tc>=0){ t=tc; ind=i; } } if (ind>=0){ //res=objects[ind].shade(L,v,w,t);// add fields in sphere to keep values of the intersection and "prepare" shading if it is indeed shaded res=objects[ind].shade(objects,L1,v,w,t,howManyRefl,this);// add fields in sphere to keep values of the intersection and "prepare" shading if it is indeed shaded } return res; } public double[] normalize(double[] vs){ int n=vs.length; double norm=0; for (int i=0; i