Area.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  57. Directions getDirectionsFromVector(Framework::Vec3<float> dir)
  58. {
  59. Directions dirs = NO_DIRECTION;
  60. if (dir.y < 0)
  61. dirs |= NORTH;
  62. else if (dir.y > 0)
  63. dirs |= SOUTH;
  64. if (dir.x < 0)
  65. dirs |= WEST;
  66. else if (dir.x > 0)
  67. dirs |= EAST;
  68. if (dir.z < 0)
  69. dirs |= BOTTOM;
  70. else if (dir.z > 0)
  71. dirs |= TOP;
  72. return dirs;
  73. }