Face.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "common/utils/Face.h"
  2. Face Face::FACES[6] =
  3. {
  4. Face(0, 0, 1, 0, 1, "Up"),
  5. Face(1, 1, 0, 0, 2, "North"),
  6. Face(2, 0, 0, 1, 4, "East"),
  7. Face(3, 0, -1, 0, 8, "Down"),
  8. Face(4, -1, 0, 0, 16, "South"),
  9. Face(5, 0, 0, -1, 32, "West")
  10. };
  11. Face& Face::UP = FACES[0];
  12. Face& Face::DOWN = FACES[3];
  13. Face& Face::NORTH = FACES[1];
  14. Face& Face::SOUTH = FACES[4];
  15. Face& Face::EAST = FACES[2];
  16. Face& Face::WEST = FACES[5];
  17. int Face::getCullData(bool up, bool down, bool north, bool south, bool east, bool west)
  18. {
  19. return (up * 1) | (down * 8) | (north * 2) | (south * 16) | (east * 4) | (west * 32);
  20. }
  21. Face::Face(int index, int offsetX, int offsetY, int offsetZ, int cullBit, const char* name) :
  22. index(index), offsetX(offsetX), offsetY(offsetY), offsetZ(offsetZ), cullBit(cullBit), name(name)
  23. {
  24. }
  25. int Face::getX() const
  26. {
  27. return offsetX;
  28. }
  29. int Face::getY() const
  30. {
  31. return offsetY;
  32. }
  33. int Face::getZ() const
  34. {
  35. return offsetZ;
  36. }
  37. Face& Face::getOpposite() const
  38. {
  39. return FACES[(index + 3) % 6];
  40. }
  41. const char* Face::getName() const
  42. {
  43. return name;
  44. }
  45. int Face::getCullData() const
  46. {
  47. return cullBit;
  48. }
  49. void Face::forEach(void* data, void (*fun) (Face&, void*))
  50. {
  51. for(int i = 0; i < 6; i++)
  52. {
  53. fun(FACES[i], data);
  54. }
  55. }
  56. bool operator==(const Face& l, const Face& r)
  57. {
  58. return &l == &r;
  59. }
  60. bool operator!=(const Face& l, const Face& r)
  61. {
  62. return &l != &r;
  63. }
  64. std::ostream& operator<<(std::ostream& os, const Face& f)
  65. {
  66. os << f.getName();
  67. return os;
  68. }