Area.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "Area.h"
  2. Framework::Vec3<int> getDirection(Directions dir)
  3. {
  4. Framework::Vec3<int> result(0, 0, 0);
  5. if ((dir | NORTH) == dir)
  6. --result.y;
  7. if ((dir | EAST) == dir)
  8. ++result.x;
  9. if ((dir | SOUTH) == dir)
  10. ++result.y;
  11. if ((dir | WEST) == dir)
  12. --result.x;
  13. if ((dir | TOP) == dir)
  14. ++result.z;
  15. if ((dir | BOTTOM) == dir)
  16. --result.z;
  17. return result;
  18. }
  19. int getDirectionIndex(Direction dir)
  20. {
  21. if (dir == NORTH)
  22. return 0;
  23. if (dir == EAST)
  24. return 1;
  25. if (dir == SOUTH)
  26. return 2;
  27. if (dir == WEST)
  28. return 3;
  29. if (dir == TOP)
  30. return 4;
  31. if (dir == BOTTOM)
  32. return 5;
  33. assert(false);
  34. return -1;
  35. }
  36. Direction getOppositeDirection(Direction dir)
  37. {
  38. if (dir == NORTH)
  39. return SOUTH;
  40. if (dir == EAST)
  41. return WEST;
  42. if (dir == SOUTH)
  43. return NORTH;
  44. if (dir == WEST)
  45. return EAST;
  46. if (dir == TOP)
  47. return BOTTOM;
  48. if (dir == BOTTOM)
  49. return TOP;
  50. assert(false);
  51. return NO_DIRECTION;
  52. }
  53. Direction getDirectionFromIndex(int index)
  54. {
  55. return (Direction)(1 << index);
  56. }