Area.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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(Framework::Vec3<float> currentPos, Framework::Vec3<float> otherPos)
  23. {
  24. Directions result = NO_DIRECTION;
  25. if (currentPos.x < otherPos.x)
  26. result |= EAST;
  27. if (currentPos.x > otherPos.x)
  28. result |= WEST;
  29. if (currentPos.y < otherPos.y)
  30. result |= SOUTH;
  31. if (currentPos.y > otherPos.y)
  32. result |= NORTH;
  33. if (currentPos.z < otherPos.z)
  34. result |= TOP;
  35. if (currentPos.z > otherPos.z)
  36. result |= BOTTOM;
  37. return result;
  38. }
  39. Framework::Vec3<int> getDirection(Directions dir)
  40. {
  41. Framework::Vec3<int> result(0, 0, 0);
  42. if ((dir | NORTH) == dir)
  43. --result.y;
  44. if ((dir | EAST) == dir)
  45. ++result.x;
  46. if ((dir | SOUTH) == dir)
  47. ++result.y;
  48. if ((dir | WEST) == dir)
  49. --result.x;
  50. if ((dir | TOP) == dir)
  51. ++result.z;
  52. if ((dir | BOTTOM) == dir)
  53. --result.z;
  54. return result;
  55. }
  56. int getDirectionIndex(Direction dir)
  57. {
  58. if (dir == NORTH)
  59. return 0;
  60. if (dir == EAST)
  61. return 1;
  62. if (dir == SOUTH)
  63. return 2;
  64. if (dir == WEST)
  65. return 3;
  66. if (dir == TOP)
  67. return 4;
  68. if (dir == BOTTOM)
  69. return 5;
  70. assert(false);
  71. return -1;
  72. }
  73. Direction getDirectionFromIndex(int index)
  74. {
  75. return (Direction)(1 << index);
  76. }