Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1.     void fill_map(int height, int width, int start, int stop, vector<pixel>& bitmap) {
  2.         pixel ray_coord = { 0, 0, 0 };
  3.         float pi = atan(-1.0);
  4.         float z = -1;
  5.         #pragma omp parallel for
  6.         for (int i = start; i < stop; i++) {
  7.             for (int j = 0; j < width; j++) {
  8.  
  9.                 float x = (2 * (i + 0.5) / (float)width - 1) * tan(pi / 3) * width / (float)height;
  10.                 float y = -(2 * (j + 0.5) / (float)height - 1) * tan(pi / 3);
  11.                 pixel vec = { x, y, z };
  12.                 pixel direction = normalize(vec);
  13.                 pixel pix = unitize(cast_ray(ray_coord, direction));
  14.                 bitmap[j + i * width] = pix;
  15.             }
  16.         }
  17.     }
  18.  
  19.  
  20.  
  21.     void render(string filename, int height = 768, int width = 1024) {
  22.         vector<pixel> bitmap(width*height);
  23.  
  24.         thread t_1(std::bind(&Scene::fill_map, this, height, width, 0, int(height/8), ref(bitmap)));
  25.         thread t_2(std::bind(&Scene::fill_map, this, height, width, int(height/8), int(height/8*2), ref(bitmap)));
  26.         thread t_3(std::bind(&Scene::fill_map, this, height, width, int(height/8*2), int(height / 8 * 3), ref(bitmap)));
  27.         thread t_4(std::bind(&Scene::fill_map, this, height, width, int(height/8*3), int(height / 8 * 4), ref(bitmap)));
  28.         thread t_5(std::bind(&Scene::fill_map, this, height, width, int(height / 8 * 4), int(height / 8 * 5), ref(bitmap)));
  29.         thread t_6(std::bind(&Scene::fill_map, this, height, width, int(height / 8 * 5), int(height / 8 * 6), ref(bitmap)));
  30.         thread t_7(std::bind(&Scene::fill_map, this, height, width, int(height / 8 * 6), int(height / 8 * 7), ref(bitmap)));
  31.         thread t_8(std::bind(&Scene::fill_map, this, height, width, int(height / 8 * 7), height, ref(bitmap)));
  32.  
  33.         //fill_map(height, width, 0, height, bitmap);
  34.         t_1.join();
  35.         t_2.join();
  36.         t_3.join();
  37.         t_4.join();
  38.         t_5.join();
  39.         t_6.join();
  40.         t_7.join();
  41.         t_8.join();
  42.  
  43.         SaveBMP(filename.c_str(), bitmap, width, height);
  44.  
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement