Advertisement
Guest User

Untitled

a guest
Feb 15th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
  2. {
  3. INodeDefManager *ndef = data->m_gamedef->ndef();
  4.  
  5. // Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0),
  6. // (0,0,1), (0,0,-1) or (0,0,0)
  7. assert(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z <= 1);
  8.  
  9. // Convert direction to single integer for table lookup
  10. // 0 = (0,0,0)
  11. // 1 = (1,0,0)
  12. // 2 = (0,1,0)
  13. // 3 = (0,0,1)
  14. // 4 = invalid, treat as (0,0,0)
  15. // 5 = (0,0,-1)
  16. // 6 = (0,-1,0)
  17. // 7 = (-1,0,0)
  18. u8 dir_i = (dir.X + 2 * dir.Y + 3 * dir.Z) & 7;
  19.  
  20. // Get rotation for things like chests
  21. u8 facedir = mn.getFaceDir(ndef);
  22. assert(facedir <= 23);
  23.  
  24. static const u8 dir_to_tile[24 * 8] =
  25. {
  26. // 0 +X +Y +Z 0 -Z -Y -X
  27. 0, 2, 0, 4, 0, 5, 1, 3, // rotate over y+ 0 - 3
  28. 0, 4, 0, 3, 0, 2, 1, 5,
  29. 0, 3, 0, 5, 0, 4, 1, 2,
  30. 0, 5, 0, 2, 0, 3, 1, 4,
  31.  
  32. 0, 3, 5, 0, 0, 1, 4, 2, // rotate over z+ 4 - 7
  33. 0, 5, 3, 0, 0, 1, 2, 4,
  34. 0, 3, 4, 0, 0, 1, 5, 2,
  35. 0, 4, 2, 0, 0, 1, 3, 5,
  36.  
  37. 0, 2, 5, 1, 0, 0, 4, 3, // rotate over z- 8 - 11
  38. 0, 5, 2, 1, 0, 0, 3, 4,
  39. 0, 3, 4, 1, 0, 0, 5, 2,
  40. 0, 4, 3, 1, 0, 0, 2, 5,
  41.  
  42. 0, 0, 5, 2, 0, 3, 4, 1, // rotate over x+ 12 - 15
  43. 0, 0, 3, 5, 0, 4, 2, 1,
  44. 0, 0, 4, 3, 0, 2, 5, 1,
  45. 0, 0, 2, 4, 0, 5, 3, 1,
  46.  
  47. 0, 1, 5, 3, 0, 2, 4, 0, // rotate over x- 16 - 19
  48. 0, 1, 2, 5, 0, 4, 3, 0,
  49. 0, 1, 4, 2, 0, 3, 5, 0,
  50. 0, 1, 3, 4, 0, 5, 2, 0,
  51.  
  52. 0, 3, 1, 4, 0, 5, 0, 2, // rotate over y- 20 - 23
  53. 0, 4, 1, 2, 0, 3, 0, 5,
  54. 0, 2, 1, 5, 0, 4, 0, 3,
  55. 0, 5, 1, 3, 0, 2, 0, 4,
  56. };
  57.  
  58. u8 tileindex = dir_to_tile[facedir*8 + dir_i];
  59.  
  60. TileSpec spec = getNodeTileN(mn, p, tileindex, data);
  61. spec.rotation=0;
  62. std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
  63.  
  64. // Texture rotation
  65. // 0 - no rotation
  66. // 1 - R90
  67. // 2 - R180
  68. // 3 - R270
  69. // 4 - FXR90
  70. // 5 - FXR270
  71. // 6 - FYR90
  72. // 7 - FYR270
  73. // 8 - FX
  74. // 9 - FY
  75.  
  76. switch (facedir)
  77. {
  78. case 0:
  79. break;
  80. case 1:
  81. if(tileindex == 0) spec.rotation=3;
  82. else if(tileindex == 1) spec.rotation=1;
  83. break;
  84. case 2:
  85. if(tileindex == 0) spec.rotation=2;
  86. else if(tileindex == 1) spec.rotation=2;
  87. break;
  88. case 3:
  89. if(tileindex == 0) spec.rotation=1;
  90. else if(tileindex == 1) spec.rotation=3;
  91. break;
  92. case 4:
  93. if(tileindex == 0) spec.rotation=2;
  94. else if(tileindex == 2) spec.rotation=7;
  95. else if(tileindex == 3) spec.rotation=6;
  96. else if(tileindex == 4) spec.rotation=2;
  97. break;
  98. case 5:
  99. if(tileindex == 0) spec.rotation=3;
  100. else if(tileindex == 1) spec.rotation=6;
  101. else if(tileindex == 2) spec.rotation=2;
  102. else if(tileindex == 4) spec.rotation=1;
  103. else if(tileindex == 5) spec.rotation=3;
  104. break;
  105. case 6:
  106. if(tileindex == 1) spec.rotation=2;
  107. else if(tileindex == 2) spec.rotation=1;
  108. else if(tileindex == 3) spec.rotation=3;
  109. else if(tileindex == 5) spec.rotation=2;
  110. break;
  111. case 7:
  112. if(tileindex == 0) spec.rotation=1;
  113. else if(tileindex == 1) spec.rotation=1;
  114. else if(tileindex == 3) spec.rotation=2;
  115. else if(tileindex == 4) spec.rotation=3;
  116. else if(tileindex == 5) spec.rotation=1;
  117. break;
  118. case 8:
  119. if(tileindex == 0) spec.rotation=2;
  120. else if(tileindex == 2) spec.rotation=7;
  121. else if(tileindex == 3) spec.rotation=6;
  122. else if(tileindex == 5) spec.rotation=2;
  123. break;
  124. case 9:
  125. if(tileindex == 0) spec.rotation=3;
  126. else if(tileindex == 1) spec.rotation=6;
  127. else if(tileindex == 2) spec.rotation=2;
  128. else if(tileindex == 4) spec.rotation=3;
  129. else if(tileindex == 5) spec.rotation=1;
  130. break;
  131. case 10:
  132. if(tileindex == 1) spec.rotation=2;
  133. else if(tileindex == 2) spec.rotation=6;
  134. else if(tileindex == 3) spec.rotation=7;
  135. else if(tileindex == 4) spec.rotation=2;
  136. break;
  137. case 11:
  138. if(tileindex == 0) spec.rotation=3;
  139. else if(tileindex == 1) spec.rotation=3;
  140. else if(tileindex == 3) spec.rotation=2;
  141. else if(tileindex == 4) spec.rotation=1;
  142. else if(tileindex == 5) spec.rotation=3;
  143. break;
  144. case 12:
  145. if(tileindex == 0) spec.rotation=2;
  146. else if(tileindex == 2) spec.rotation=4;
  147. else if(tileindex == 3) spec.rotation=5;
  148. else if(tileindex == 4) spec.rotation=3;
  149. else if(tileindex == 5) spec.rotation=3;
  150. break;
  151. case 13:
  152. if(tileindex == 0) spec.rotation=1;
  153. else if(tileindex == 1) spec.rotation=1;
  154. else if(tileindex == 2) spec.rotation=5;
  155. else if(tileindex == 3) spec.rotation=5;
  156. else if(tileindex == 4) spec.rotation=3;
  157. else if(tileindex == 5) spec.rotation=1;
  158. break;
  159. case 14:
  160. if(tileindex == 1) spec.rotation=2;
  161. else if(tileindex == 2) spec.rotation=5;
  162. else if(tileindex == 3) spec.rotation=4;
  163. else if(tileindex == 4) spec.rotation=3;
  164. else if(tileindex == 5) spec.rotation=3;
  165. break;
  166. case 15:
  167. if(tileindex == 0) spec.rotation=3;
  168. else if(tileindex == 1) spec.rotation=3;
  169. else if(tileindex == 2) spec.rotation=5;
  170. else if(tileindex == 3) spec.rotation=5;
  171. else if(tileindex == 4) spec.rotation=1;
  172. else if(tileindex == 5) spec.rotation=3;
  173. break;
  174. case 16:
  175. if(tileindex == 2) spec.rotation=4;
  176. else if(tileindex == 3) spec.rotation=5;
  177. else if(tileindex == 4) spec.rotation=1;
  178. else if(tileindex == 5) spec.rotation=1;
  179. break;
  180. case 17:
  181. if(tileindex == 0) spec.rotation=3;
  182. else if(tileindex == 1) spec.rotation=3;
  183. else if(tileindex == 2) spec.rotation=4;
  184. else if(tileindex == 3) spec.rotation=4;
  185. else if(tileindex == 4) spec.rotation=1;
  186. else if(tileindex == 5) spec.rotation=3;
  187. break;
  188. case 18:
  189. if(tileindex == 0) spec.rotation=8;
  190. else if(tileindex == 1) spec.rotation=2;
  191. else if(tileindex == 2) spec.rotation=5;
  192. else if(tileindex == 3) spec.rotation=4;
  193. else if(tileindex == 4) spec.rotation=1;
  194. else if(tileindex == 5) spec.rotation=1;
  195. break;
  196. case 19:
  197. if(tileindex == 0) spec.rotation=1;
  198. else if(tileindex == 1) spec.rotation=1;
  199. else if(tileindex == 2) spec.rotation=4;
  200. else if(tileindex == 3) spec.rotation=4;
  201. else if(tileindex == 4) spec.rotation=3;
  202. else if(tileindex == 5) spec.rotation=1;
  203. break;
  204. case 20:
  205. spec.rotation=2;
  206. break;
  207. case 21:
  208. if(tileindex == 0) spec.rotation=3;
  209. else if(tileindex == 1) spec.rotation=1;
  210. else if(tileindex == 2) spec.rotation=2;
  211. else if(tileindex == 3) spec.rotation=2;
  212. else if(tileindex == 4) spec.rotation=2;
  213. else if(tileindex == 5) spec.rotation=2;
  214. break;
  215. case 22:
  216. if(tileindex == 2) spec.rotation=2;
  217. else if(tileindex == 3) spec.rotation=2;
  218. else if(tileindex == 4) spec.rotation=2;
  219. else if(tileindex == 5) spec.rotation=2;
  220. break;
  221. case 23:
  222. if(tileindex == 0) spec.rotation=1;
  223. else if(tileindex == 1) spec.rotation=3;
  224. else if(tileindex == 2) spec.rotation=2;
  225. else if(tileindex == 3) spec.rotation=2;
  226. else if(tileindex == 4) spec.rotation=2;
  227. else if(tileindex == 5) spec.rotation=2;
  228. break;
  229. default:
  230. break;
  231. }
  232. spec.texture = data->m_gamedef->tsrc()->getTexture(name);
  233. return spec;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement