Advertisement
cheprogrammer

IsometricScreenToMap

May 13th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1.         public Vector2 ScreenToMap(Vector2 source)
  2.         {
  3.             switch (CameraDirection)
  4.             {
  5.                 case FaceDirection.NorthWest:
  6.                     return new Vector2((source.X / GameConstants.CellHalfWidth + source.Y / GameConstants.CellHalfHeight) / 2.0f,
  7.                         (source.Y / GameConstants.CellHalfHeight - source.X / GameConstants.CellHalfWidth) / 2.0f);
  8.                 case FaceDirection.EastNorth:
  9.                     return new Vector2((source.Y / GameConstants.CellHalfHeight - source.X / GameConstants.CellHalfWidth) / 2.0f,
  10.                         (source.Y / GameConstants.CellHalfHeight + source.X / GameConstants.CellHalfWidth) / 2.0f);
  11.  
  12.                 case FaceDirection.SouthEast:
  13.                     return new Vector2((source.Y / GameConstants.CellHalfHeight + source.X / GameConstants.CellHalfWidth) / 2.0f,
  14.                         -(source.Y / GameConstants.CellHalfHeight - source.X / GameConstants.CellHalfWidth) / 2.0f);
  15.  
  16.                 case FaceDirection.WestSouth:
  17.                     return new Vector2(-(source.X / GameConstants.CellHalfWidth - source.Y / GameConstants.CellHalfHeight) / 2.0f,
  18.                         (source.Y / GameConstants.CellHalfHeight + source.X / GameConstants.CellHalfWidth) / 2.0f);
  19.             }
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement