public class Polyhedron extends Surface{ Plane[] faces; int n;//nb of faces Vector currentNormalIn;//normal of entry for the point being observed Vector currentNormalOut; Polyhedron(){ } Polyhedron(Plane[] s){ n=s.length; faces=new Plane[n]; for (int i=0;itmpt[1]){ tOut=tmpt[1]; indOut=i; } } double[] res=new double[2]; res[0]=tIn; res[1]=tOut; if (tIn>-1){ currentNormalIn=new Vector(faces[indIn].extNormal); m=faces[indIn].m; } if (tOut<=INFTY){ currentNormalOut=new Vector(faces[indOut].extNormal); } return res; } void setTransfo(Matrix3D tfs){ for (int i=0;i=tTmpOut) continue; if (tTmp>0 & tTmp<9995){ shadowed=1; break; } } if (shadowed==1){ continue; } for (int j=0;j<3;j++){ double vald=lights[i].dir.dotP(normV); if (vald>0) res[j]+=lights[i].rgb[j]*m.diffuse[j]*vald;// diffuse tmp=normV.scalMult(2*vald); double vals=e0.dotP(tmp.diff(lights[i].dir)); if (vals>0) res[j]+=lights[i].rgb[j]*m.specular[j]*Math.pow(vals,m.p); } } } //now reflection if (howManyRefl>0){ Vector newW=new Vector(w); newW=newW.diff(normV.scalMult(2*normV.dotP(w))); newW.normalize(); Vector newV=new Vector(currPt); newV=newV.add(newW.scalMult(0.001)); double[] tmpRef=calling.rayTraceSurf(newV.v, newW.v, howManyRefl-1, 1); tmpRef[0]*=m.specular[0]; tmpRef[1]*=m.specular[1]; tmpRef[2]*=m.specular[2]; res[0]+=tmpRef[0]; res[1]+=tmpRef[1]; res[2]+=tmpRef[2]; //res=add(res,calling.rayTrace(newV, newW, howManyRefl-1)); //res=diff(add(res,calling.rayTrace(newV, newW, howManyRefl-1)), m.ambient); } //...and refraction return res; } }