Area.cpp 1.4 KB

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