direction.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. """
  2. Directions identifiers 3D, central position is 14.
  3. niv -1: 1 2 3
  4. 4 5 6
  5. 7 8 9
  6. niv 0: 10 11 12
  7. 13 14 15
  8. 16 17 18
  9. niv 1: 19 20 21
  10. 22 23 24
  11. 25 26 27
  12. """
  13. directions = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)
  14. directions_under_level = (1, 2, 3, 4, 5, 6, 7, 8, 9)
  15. directions_same_level = (10, 11, 12, 13, 15, 16, 17, 18)
  16. directions_upper_level = (19, 20, 21, 22, 23, 24, 25, 26, 27)
  17. directions_by_levels = (directions_under_level, directions_same_level, directions_upper_level)
  18. directions_modifiers = {
  19. # (z, x, y)
  20. 1: (-1, -1, -1),
  21. 2: (-1, 0, -1),
  22. 3: (-1, 1, -1),
  23. 4: (-1, -1, 0),
  24. 5: (-1, 0, 0),
  25. 6: (-1, 1, 0),
  26. 7: (-1, -1, 1),
  27. 8: (-1, 0, 1),
  28. 9: (-1, 1, 1),
  29. # (z, x, y)
  30. 10: (0, -1, -1),
  31. 11: (0, 0, -1),
  32. 12: (0, 1, -1),
  33. 13: (0, -1, 0),
  34. 14: (0, 0, 0),
  35. 15: (0, 1, 0),
  36. 16: (0, -1, 1),
  37. 17: (0, 0, 1),
  38. 18: (0, 1, 1),
  39. # (z, x, y)
  40. 19: (1, -1, -1),
  41. 20: (1, 0, -1),
  42. 21: (1, 1, -1),
  43. 22: (1, -1, 0),
  44. 23: (1, 0, 0),
  45. 24: (1, 1, 0),
  46. 25: (1, -1, 1),
  47. 26: (1, 0, 1),
  48. 27: (1, 1, 1),
  49. }
  50. NORTH = 11
  51. NORTH_EST = 12
  52. EST = 15
  53. SOUTH_EST = 18
  54. SOUTH = 17
  55. SOUTH_WEST = 16
  56. WEST = 13
  57. NORTH_WEST = 10
  58. CENTER = 14
  59. """
  60. Directions identifiers 3D, central position is 14.
  61. niv -1: 1 2 3
  62. 4 5 6
  63. 7 8 9
  64. niv 0: 10 11 12
  65. 13 14 15
  66. 16 17 18
  67. niv 1: 19 20 21
  68. 22 23 24
  69. 25 26 27
  70. """
  71. directions_slighty = {
  72. 1: (1, 2, 4, 13, 10, 11),
  73. 2: (1, 2, 3, 10, 11, 12),
  74. 3: (2, 3, 6, 11, 12, 15),
  75. 4: (1, 4, 7, 10, 13, 16),
  76. 5: (1, 2, 3, 4, 5, 6, 7, 8, 9),
  77. 6: (2, 3, 6, 12, 15, 18),
  78. 7: (4, 7, 8, 13, 16, 17),
  79. 8: (7, 8, 9, 16, 17, 18),
  80. 9: (6, 9, 8, 15, 18, 17),
  81. # (z, x, y)
  82. 10: (13, 10, 11),
  83. 11: (10, 11, 12),
  84. 12: (11, 12, 15),
  85. 13: (10, 13, 16),
  86. 14: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27),
  87. 15: (12, 15, 18),
  88. 16: (13, 16, 17),
  89. 17: (16, 17, 18),
  90. 18: (15, 18, 17),
  91. # (z, x, y)
  92. 19: (22, 19, 20, 13, 10, 11),
  93. 20: (19, 20, 21, 10, 11, 12),
  94. 21: (20, 21, 24, 11, 12, 15),
  95. 22: (19, 22, 25, 10, 13, 16),
  96. 23: (19, 20, 21, 22, 23, 24, 25, 26, 27),
  97. 24: (21, 24, 27, 12, 15, 18),
  98. 25: (22, 25, 26, 13, 16, 17),
  99. 26: (25, 26, 27, 16, 17, 18),
  100. 27: (24, 27, 26, 15, 18, 17),
  101. }
  102. directions_degrees = {
  103. (0, 22.5): 11,
  104. (22.5, 67): 12,
  105. (67, 112.5): 15,
  106. (112.5, 157.5): 18,
  107. (157.5, 202.5): 17,
  108. (202.5, 247.5): 16,
  109. (247.5, 292.5): 13,
  110. (292.5, 337.5): 10,
  111. (337.5, 360): 11,
  112. (337.5, 0): 11
  113. }
  114. def get_direction_for_degrees(degrees):
  115. if degrees < 0:
  116. degrees = 360 - abs(degrees)
  117. for plage in directions_degrees:
  118. if plage[0] <= degrees <= plage[1]:
  119. return directions_degrees[plage]
  120. raise Exception("Unknow plage for degree \"" + str(degrees) + '"')
  121. """
  122. niv 0: 10 11 12
  123. 13 14 15
  124. 16 17 18
  125. """
  126. directions_opposites = {
  127. 10: 18,
  128. 11: 17,
  129. 12: 16,
  130. 13: 15,
  131. 15: 13,
  132. 16: 12,
  133. 17: 11,
  134. 18: 10
  135. }
  136. def get_direction_opposite(direction):
  137. return directions_opposites[direction]
  138. def get_position_with_direction_decal(direction=CENTER, point=(0, 0, 0)):
  139. z, x, y = point
  140. directions_modifier = directions_modifiers[direction]
  141. return z + directions_modifier[0], x + directions_modifier[1], y + directions_modifier[2]