raytracing - C++ Ray Tracing - Plane is always returning true for the whole image -


when attempting render plane in image, whole image being phong shaded. see plane. pass array of primitives checkforintersection function. tmin set 100, if intersection found changes. if intersection found , tmin changes cast shadow rays. works spheres, when try implement plane, whole image/background gets phong shaded.

why whole background being phong shaded. there wrong plane intersection formula?

when tmin line commented: http://imgur.com/k789dp4

when tmin line uncommented: http://imgur.com/sbyxhex

neither show me plane. although when set plane cutting spheres in half, show cut in ambient color.

// ********** global variables ********* rgbimage * myimage; vec3 neye(0.0,0.0,-5.0); vec3 lightsource1(-2.0,-1.5,0.0); vec3 lightsource2(0.0,-2.0,0.0); float tmin=100.0;  struct prim {     vec3 origin;     double radius;     double undersquare;     vec3 ambient;     vec3 diffuse_albedo;     vec3 specular_albedo;     float specular_power;     vec3 light_intensity;     vec3 normal;     vec3 pt1;     vec3 pt2;     vec3 pt3; };   // *****************check intersection************** prim checkforintersection(vec3 point, vec3 directionvector, prim prims[4], bool printit){     prim pickprim;      float d = 0;     float denom = dot(prims[3].normal, directionvector);    //is correct direction vector?     float numer = dot(prims[3].normal, neye) + d;            //vec3 hittemp;     //vec3 hitpoint;     if (denom!=0){         float t= -(numer) / denom;         //cout << t << endl;         if (t <= tmin && t>0.001 && t<6){             //tmin=t;             pickprim = prims[3];         }     }     return pickprim; }   // ***********************calling function********************** prim sphere1; prim sphere2; prim sphere3; prim pickprim; ray shadowray; ray shadowray2; tmin = 100; vec3 pixelcolor(0,0,1);  prim squareplane;     squareplane.ambient=vec3(0.329412, 0.223529, 0.027451);     squareplane.diffuse_albedo=vec3(0.780392, 0.568627, 0.113725);     squareplane.specular_albedo = vec3(0.992157,0.941176,0.807843);     squareplane.specular_power = 27.8974;     squareplane.light_intensity = vec3(1,1,1);     squareplane.normal = normalize(vec3(0,0,-0.1));      prim prims[4] =     {   sphere1,                             sphere2,                             sphere3,                             squareplane                         };      pickprim = checkforintersection(neye, nvecdir, prims, false);  // last parameter print debugging      if (tmin != 100){ //if tmin has changed, found , intersection, send shadow ray         vec3 hittemp(nvecdir.x*tmin, nvecdir.y*tmin, nvecdir.z*tmin);         vec3 hitpoint = (neye + hittemp);         shadowray.vecdir = (normalize(lightsource1 - (hitpoint)));         //shadowray2.vecdir = (normalize(lightsource2 - (hitpoint)));         tmin = 100;  // set tmin new ray trace.         prim tmindummy = checkforintersection(hitpoint, shadowray.vecdir, prims, true);          if (tmin != 100){ //if tmin not equal 100, found intersection, point in shadow, return ambient.             pixelcolor = pickprim.ambient;             return pixelcolor;         }         else{             pickprim.normal = hitpoint - pickprim.origin;             pixelcolor = implementphong(pickprim,neye,hitpoint);             //pixelcolor = vec3(0,1,0);             return pixelcolor;         }     }     else{         return pixelcolor;     } }