Area.cpp 1.7 KB

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