Area.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. switch (dir)
  48. {
  49. case NORTH:
  50. return 0;
  51. case EAST:
  52. return 1;
  53. case SOUTH:
  54. return 2;
  55. case WEST:
  56. return 3;
  57. case TOP:
  58. return 4;
  59. case BOTTOM:
  60. return 5;
  61. default:
  62. break;
  63. }
  64. assert(false);
  65. return -1;
  66. }
  67. Direction getDirectionFromIndex(int index)
  68. {
  69. return (Direction)(1 << index);
  70. }