Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int CoordinatesToTileNumber(int clickX, int clickY, int imageW, int imageH, int imageLevels, int magnificationLevel)
- {
- int tileW = 1570,
- tileH = 748;
- //1 - Set correct magnification level
- magnificationLevel = magnificationLevel == 0 ? imageLevels : magnificationLevel;
- //2 - Snap to tile
- //clickX = (int)(Math.Floor(clickX / (double)tileW) * tileW);
- //clickY = (int)(Math.Floor(clickY / (double)tileH) * tileH);
- //2 - Calculate new tileW and tileH
- tileW = (int)(tileW * Math.Pow(2, imageLevels - magnificationLevel));
- tileH = (int)(tileH * Math.Pow(2, imageLevels - magnificationLevel));
- //3 - Get number of tiles per row
- int cntTileX = (int)Math.Ceiling((double)imageW / tileW);
- //4 - Get tile number
- int xNum = (int)Math.Floor((double)clickX / tileW);
- int yNum = (int)Math.Floor((double)clickY / tileH);
- int result = xNum + yNum * cntTileX + 1;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement