Advertisement
alex_dot

main.cpp

Aug 24th, 2013
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1.     // for all pixels of window
  2.     for (int y = height_half_neg; y < height_half; ++y) {
  3.       for (int x = width_half_neg; x < width_half; ++x) {
  4.         Pixel p(x+width_half, y+height_half);
  5.                
  6.                 // pseudo-camera-model:
  7.                 // by setting the camera origin at z=+focal_length, projecting
  8.                 // the vector at z=-focal_length results in the image plane being at
  9.                 // [0,0,0]
  10.                 camera_ray = Ray( math3d::point(0.,0.,focal_length),
  11.                                   math3d::vector(x,y,-focal_length));
  12.  
  13.         // compute color for pixel
  14.         std::shared_ptr<CRDS> intersection = m_scene->getNearestIntersection(camera_ray);
  15.         if (intersection->hit == 1)
  16.         {
  17.           Ray camera_ray_t = Ray(
  18.                 intersection->shape->getInverseTransformation()
  19.                       * camera_ray.origin,
  20.                 intersection->shape->getInverseTransformation()
  21.                       * camera_ray.dir
  22.                                 );
  23.           //camera_ray_t = camera_ray;   // ???
  24.           math3d::point intersection_point = math3d::point(
  25.                    camera_ray_t.origin[0]+intersection->t*camera_ray_t.dir[0],
  26.                    camera_ray_t.origin[1]+intersection->t*camera_ray_t.dir[1],
  27.                    camera_ray_t.origin[2]+intersection->t*camera_ray_t.dir[2]
  28.                                              );
  29.           intersection_point = intersection->shape->getTransformation()
  30.                                * intersection_point;
  31.                                       // ???
  32.           Color temp_color = intersection->shape->getColor(intersection_point, m_scene);
  33.           p.color = temp_color;
  34.         } else {
  35.           p.color = Color(0., 0., 0.);
  36.         }
  37.  
  38.         window.write(p); // write pixel to output window
  39.         image.write(p);  // write pixel to image writer
  40.       }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement