Advertisement
alex_dot

scene.cpp

Aug 24th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. std::shared_ptr<CRDS> const Scene::getNearestIntersection(Ray const& ray) const
  2. {
  3.   int hit = 0;
  4.   std::shared_ptr<Shape> shape;
  5.   double t = 1000000.;
  6.   std::pair<int,double> pair;
  7.   for(std::vector<std::shared_ptr<Shape>>::const_iterator iter = shapes_.begin(); iter!=shapes_.end(); ++iter)
  8.   {
  9.     pair = (*iter)->getIntersection(ray, false);
  10.     if(std::get<0>(pair)==1 && std::get<1>(pair) < t)
  11.     {
  12.       shape = *iter;
  13.       t = std::get<1>(pair);
  14.       hit = 1;
  15.     }
  16.   }
  17.   if(hit==0)
  18.   {
  19.     std::shared_ptr<Sphere> shape = std::make_shared<Sphere>();
  20.   }
  21.   std::shared_ptr<CRDS> data = std::make_shared<CRDS> (hit,t,shape);
  22.   return data;
  23. }
  24. int Scene::getFirstIntersection(Ray const& ray) const
  25. {
  26.   int delta = 1;
  27.   std::pair<int,double> pair;
  28.   for(std::vector<std::shared_ptr<Shape>>::const_iterator iter = shapes_.begin(); iter!=shapes_.end(); ++iter)
  29.   {
  30.     pair = (*iter)->getIntersection(ray, true);
  31.     if(std::get<0>(pair)==1)
  32.     {
  33.       delta = 1;
  34.       break;
  35.     }
  36.   }
  37.   return delta;
  38. }
  39. // returns pair ( delta , pair ( light vector , light object ) )
  40. std::vector<std::shared_ptr<SFDS>> const Scene::shadowFeeler(math3d::point const& intersection_point) const
  41. {
  42.   // temp variables
  43.   // delta: hit-miss value
  44.   // vector: intersection_point->light -vector
  45.   // ray: intersection_point->light -ray
  46.   int delta;
  47.   math3d::vector vector;
  48.   Ray ray;
  49.   // make hit+light-object vector and reserve memory for
  50.   // number of lights in scene
  51.   std::vector<std::shared_ptr<SFDS>> spot_list;
  52.   spot_list.reserve(lights_.size());
  53.   // iterate over lights
  54.   for(std::vector<std::shared_ptr<Light>>::const_iterator iter = lights_.begin(); iter!=lights_.end(); ++iter)
  55.   {
  56.     vector = math3d::vector( (*iter)->position_[0]-intersection_point[0],
  57.                              (*iter)->position_[1]-intersection_point[1],
  58.                              (*iter)->position_[2]-intersection_point[2]
  59.                            ).normalize();
  60.     ray = Ray(math3d::point( intersection_point[0],
  61.                              intersection_point[1],
  62.                              intersection_point[2]), vector);
  63.     delta = getFirstIntersection(ray);
  64.     spot_list.push_back(std::make_shared<SFDS> (SFDS(delta,vector,*iter)));
  65.   }
  66.   return spot_list;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement