void ElementStyle::imageMode(bool negative){ if (negative !=isNegativeMode){ StyleColour swapCol=getFgColour(); setFgColour(getBgColour()); setBgColour(swapCol); isNegativeMode=!isNegativeMode; } }
Colour World::spawnrec(const Ray& r,const int& depth) { Point p; Vector normal; Vector incoming; Vector reflective; std::list<Light*> lights(getLightList()); IntersectData data; double lightW; // bool useBG = true; Colour illumination = getBgColour(); double max_w = std::numeric_limits<double>::max(); double least_w = max_w; Object* close_o = intersectWithObjects(r,least_w); // If intersection if (close_o){ // useBG = false; // Initialize things illumination = Colour(); Vector origin = (r.getOrigin()).getVec(); Vector dir = r.getDirection(); p = Point(origin+(dir*least_w)); normal = close_o->getNormal(); data.setPoint(p); data.setNormal(normal.normalize()); data.setViewing((p-Point()).normalize()); Ray lightRay; Ray shadowRay; Ray outShadowRay; Object* blockingObject; least_w = std::numeric_limits<double>::max(); std::list<Light*>::iterator it; Vector lightDir; for(it = lights.begin(); it != lights.end(); it++){ lightDir = (p-((*it)->getPosition())).normalize(); lightRay = Ray(p,lightDir); blockingObject = intersectWithObjects(lightRay,least_w,close_o); incoming = p-((*it)->getPosition()); reflective = ((*it)->getPosition()-p).reflect(normal).normalize(); data.setLight(*(*it)); data.setIncoming(incoming.normalize()); data.setReflective(reflective.normalize()); if (blockingObject){ // In shadow if (blockingObject->getkt()>0){ //shadowRay.setOrigin(Point(origin+(lightDir*least_w))); //shadowRay.setDirection(lightRay.getDirection()); //outShadowRay = calcTrans(shadowRay,(blockingObject->getNormal()).normalize(),blockingObject->getn()); illumination = illumination + model_->illuminate(close_o,data) * blockingObject->getkt(); } } else { // Not in shadow //std::cout<<(blockingObject->toString())<<"\n"; lightW = close_o->intersect(lightRay); if (std::isfinite(lightW) || (lightW>0)){ illumination = illumination + model_->illuminate(close_o,data); } } } if (depth < close_o->getDepth()){ // Reflected Ray if (close_o->getkr()>0){ Ray refRay(p,(Point()-p).reflect(normal).normalize()); illumination = illumination + (spawnrec(refRay,depth+1) * close_o->getkr()); } // Transmission ray if (close_o->getkt()>0){ Ray inRay(p,r.getDirection()); // std::cout<<"In: "<<inRay.toString()<<"\n"; Ray transRay = calcTrans(inRay,normal,close_o->getn()); // std::cout<<"Out: "<<transRay.toString()<<"\n"; illumination = illumination + (spawnrec(transRay,depth+1) * close_o->getkt()); } } /* if (useBG){ illumination = getBgColour(); }*/ } return illumination; }