public class Ray{ Vector v; Vector w; int howManyRefl; double n1;// refraction index int index;// if the ray is inside an object, this is the index of the object public Ray(Vector vs, Vector ws, double r){ v=new Vector(vs); w=new Vector(ws); howManyRefl=2; n1=r; } public Ray(Ray rs){ v=new Vector(rs.v); w=new Vector(rs.w); n1=rs.n1; howManyRefl=rs.howManyRefl; } public void setIndex(int i){ index=i; } public void setRefl(int i){ howManyRefl=i; } public void setN1(double d){ n1=d; } public double[] rayTraceSurf(Surface[] objects, Light[] lights){ 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.v,w.v); 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 // you have to set the index of the objects at some point... res=objects[ind].shade(objects,lights,this,t,0);// add fields in sphere to keep values of the intersection and "prepare" shading if it is indeed shaded //res=objects[ind].shadeSimple(objects,lights,this,t); } return res; } public double[] rayIn(Surface[] objects, Light[] lights){ double t=10000; int ind=-1; double[] res=new double[3]; int flagIn=1; for (int i=0; i< objects.length; i++){ double[] tmptc=objects[i].intersections(v.v,w.v); double tc=tmptc[0]; double tc1=tmptc[1]; if (tc>=tc1) continue; if (tc<=t & tc>=0){ t=tc; ind=i; flagIn=1; } if (i==index & tc1<=t){ t=tc1; ind=i; flagIn=2; } } if (ind>=0){ res=objects[ind].shade(objects,lights,this,t,flagIn);// add fields in sphere to keep values of the intersection and "prepare" shading if it is indeed shaded } return res; } }