Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::shared_ptr<CRDS> const Scene::getNearestIntersection(Ray const& ray) const
- {
- int hit = 0;
- std::shared_ptr<Shape> shape;
- double t = 1000000.;
- std::pair<int,double> pair;
- for(std::vector<std::shared_ptr<Shape>>::const_iterator iter = shapes_.begin(); iter!=shapes_.end(); ++iter)
- {
- pair = (*iter)->getIntersection(ray, false);
- if(std::get<0>(pair)==1 && std::get<1>(pair) < t)
- {
- shape = *iter;
- t = std::get<1>(pair);
- hit = 1;
- }
- }
- if(hit==0)
- {
- std::shared_ptr<Sphere> shape = std::make_shared<Sphere>();
- }
- std::shared_ptr<CRDS> data = std::make_shared<CRDS> (hit,t,shape);
- return data;
- }
- int Scene::getFirstIntersection(Ray const& ray) const
- {
- int delta = 1;
- std::pair<int,double> pair;
- for(std::vector<std::shared_ptr<Shape>>::const_iterator iter = shapes_.begin(); iter!=shapes_.end(); ++iter)
- {
- pair = (*iter)->getIntersection(ray, true);
- if(std::get<0>(pair)==1)
- {
- delta = 1;
- break;
- }
- }
- return delta;
- }
- // returns pair ( delta , pair ( light vector , light object ) )
- std::vector<std::shared_ptr<SFDS>> const Scene::shadowFeeler(math3d::point const& intersection_point) const
- {
- // temp variables
- // delta: hit-miss value
- // vector: intersection_point->light -vector
- // ray: intersection_point->light -ray
- int delta;
- math3d::vector vector;
- Ray ray;
- // make hit+light-object vector and reserve memory for
- // number of lights in scene
- std::vector<std::shared_ptr<SFDS>> spot_list;
- spot_list.reserve(lights_.size());
- // iterate over lights
- for(std::vector<std::shared_ptr<Light>>::const_iterator iter = lights_.begin(); iter!=lights_.end(); ++iter)
- {
- vector = math3d::vector( (*iter)->position_[0]-intersection_point[0],
- (*iter)->position_[1]-intersection_point[1],
- (*iter)->position_[2]-intersection_point[2]
- ).normalize();
- ray = Ray(math3d::point( intersection_point[0],
- intersection_point[1],
- intersection_point[2]), vector);
- delta = getFirstIntersection(ray);
- spot_list.push_back(std::make_shared<SFDS> (SFDS(delta,vector,*iter)));
- }
- return spot_list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement