Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. public static int CoordinatesToTileNumber(int clickX, int clickY, int imageW, int imageH, int imageLevels, int magnificationLevel)
  2.         {
  3.             int tileW = 1570,
  4.                 tileH = 748;
  5.  
  6.             //1 - Set correct magnification level
  7.             magnificationLevel = magnificationLevel == 0 ? imageLevels : magnificationLevel;
  8.  
  9.  
  10.             //2 - Snap to tile
  11.             //clickX = (int)(Math.Floor(clickX / (double)tileW) * tileW);
  12.             //clickY = (int)(Math.Floor(clickY / (double)tileH) * tileH);
  13.  
  14.             //2 - Calculate new tileW and tileH
  15.             tileW = (int)(tileW * Math.Pow(2, imageLevels - magnificationLevel));
  16.             tileH = (int)(tileH * Math.Pow(2, imageLevels - magnificationLevel));
  17.  
  18.             //3 - Get number of tiles per row
  19.             int cntTileX = (int)Math.Ceiling((double)imageW / tileW);
  20.  
  21.             //4 - Get tile number
  22.             int xNum = (int)Math.Floor((double)clickX / tileW);
  23.             int yNum = (int)Math.Floor((double)clickY / tileH);
  24.             int result = xNum + yNum * cntTileX + 1;
  25.  
  26.             return result;
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement