Area.cpp 1.5 KB

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