Advertisement
Geometrian

pixel id to pixel coord

Apr 9th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. ivec2 get_coord(uint id) {
  2.     uint res_div_x = screen_size[0]/4;
  3.     uint res_div_y = screen_size[1]/4;
  4.     uint res_div_total = res_div_x * res_div_y;
  5.     ivec2 add;
  6.     if        (id <    res_div_total) {
  7.         add = ivec2(0,0);
  8.     } else if (id <  2*res_div_total) {
  9.         id -= res_div_total;
  10.         add = ivec2(2,2);
  11.     } else if (id <  4*res_div_total) {
  12.         id -= 2*res_div_total;
  13.         uint rem=id%2; id/=2;
  14.         if (rem==0u) add=ivec2(2,0);
  15.         else         add=ivec2(0,2);
  16.     } else if (id <  8*res_div_total) {
  17.         id -= 4*res_div_total;
  18.         uint rem=id%4; id/=4;
  19.         switch (rem) {
  20.             case 0u: add=ivec2(1,1); break;
  21.             case 1u: add=ivec2(3,1); break;
  22.             case 2u: add=ivec2(1,3); break;
  23.             case 3u: add=ivec2(3,3); break;
  24.         }
  25.     } else if (id < 16*res_div_total) {
  26.         id -= 8*res_div_total;
  27.         uint rem=id%8; id/=8;
  28.         switch (rem) {
  29.             case 0u: add=ivec2(1,0); break;
  30.             case 1u: add=ivec2(3,0); break;
  31.             case 2u: add=ivec2(0,1); break;
  32.             case 3u: add=ivec2(2,1); break;
  33.             case 4u: add=ivec2(1,2); break;
  34.             case 5u: add=ivec2(3,2); break;
  35.             case 6u: add=ivec2(0,3); break;
  36.             case 7u: add=ivec2(2,3); break;
  37.         }
  38.     } else {
  39.         return ivec2(-1,-1); //Don't actually care.  Probably won't even ever happen.
  40.     }
  41.     uint x = 4u*(id % res_div_x);
  42.     uint y = 4u*(id / res_div_x);
  43.     x += add.x;
  44.     y += add.y;
  45.     return ivec2(x,y);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement