Advertisement
Guest User

Untitled

a guest
Feb 16th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. /*
  2. Gets node tile given a face direction.
  3. */
  4. TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
  5. {
  6. INodeDefManager *ndef = data->m_gamedef->ndef();
  7.  
  8. // Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0),
  9. // (0,0,1), (0,0,-1) or (0,0,0)
  10. assert(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z <= 1);
  11.  
  12. // Convert direction to single integer for table lookup
  13. // 0 = (0,0,0)
  14. // 1 = (1,0,0)
  15. // 2 = (0,1,0)
  16. // 3 = (0,0,1)
  17. // 4 = invalid, treat as (0,0,0)
  18. // 5 = (0,0,-1)
  19. // 6 = (0,-1,0)
  20. // 7 = (-1,0,0)
  21. u8 dir_i = ((dir.X + 2 * dir.Y + 3 * dir.Z) & 7)*2;
  22.  
  23. // Get rotation for things like chests
  24. u8 facedir = mn.getFaceDir(ndef);
  25. assert(facedir <= 23);
  26. static const u16 dir_to_tile[24 * 16] =
  27. {
  28. // 0 +X +Y +Z 0 -Z -Y -X value=tile,rotation
  29. 0,0, 2,0 , 0,0 , 4,0 , 0,0, 5,0 , 1,0 , 3,0 , // rotate over y+ 0 - 3
  30. 0,0, 4,0 , 0,3 , 3,0 , 0,0, 2,0 , 1,1 , 5,0 ,
  31. 0,0, 3,0 , 0,2 , 5,0 , 0,0, 4,0 , 1,2 , 2,0 ,
  32. 0,0, 5,0 , 0,1 , 2,0 , 0,0, 3,0 , 1,3 , 4,0 ,
  33.  
  34. 0,0, 3,6 , 5,0 , 0,2 , 0,0, 1,0 , 4,2 , 2,7 , // rotate over z+ 4 - 7
  35. 0,0, 5,3 , 3,0 , 0,3 , 0,0, 1,6 , 2,2 , 4,1 ,
  36. 0,0, 3,3 , 4,0 , 0,0 , 0,0, 1,2 , 5,2 , 2,1 ,
  37. 0,0, 4,3 , 2,0 , 0,1 , 0,0, 1,1 , 3,2 , 5,1 ,
  38.  
  39. 0,0, 2,7 , 5,2 , 1,0 , 0,0, 0,2 , 4,0 , 3,6 , // rotate over z- 8 - 11
  40. 0,0, 5,1 , 2,2 , 1,6 , 0,0, 0,3 , 3,0 , 4,3 ,
  41. 0,0, 3,7 , 4,2 , 1,2 , 0,0, 0,0 , 5,0 , 2,6 ,
  42. 0,0, 4,1 , 3,2 , 1,3 , 0,0, 0,3 , 2,0 , 5,3 ,
  43.  
  44. 0,0, 0,2 , 5,3 , 2,4 , 0,0, 3,5 , 4,3 , 1,0 , // rotate over x+ 12 - 15
  45. 0,0, 0,1 , 3,5 , 5,1 , 0,0, 4,3 , 2,5 , 1,1 ,
  46. 0,0, 0,0 , 4,3 , 3,4 , 0,0, 2,5 , 5,3 , 1,2 ,
  47. 0,0, 0,3 , 2,5 , 4,1 , 0,0, 5,3 , 3,5 , 1,3 ,
  48.  
  49. 0,0, 1,0 , 5,1 , 3,5 , 0,0, 2,4 , 4,1 , 0,0 , // rotate over x- 16 - 19
  50. 0,0, 1,3 , 2,4 , 5,3 , 0,0, 4,1 , 3,4 , 0,3 ,
  51. 0,0, 1,2 , 4,1 , 2,5 , 0,0, 3,4 , 5,1 , 0,8 ,
  52. 0,0, 1,1 , 3,4 , 4,3 , 0,0, 5,1 , 2,4 , 0,1 ,
  53.  
  54. 0,0, 3,2 , 1,2 , 4,2 , 0,0, 5,2 , 0,2 , 2,2 , // rotate over y- 20 - 23
  55. 0,0, 4,2 , 1,1 , 2,2 , 0,0, 3,2 , 0,3 , 5,2 ,
  56. 0,0, 2,2 , 1,0 , 5,2 , 0,0, 4,2 , 0,0 , 3,2 ,
  57. 0,0, 5,2 , 1,3 , 3,2 , 0,0, 2,2 , 0,1 , 4,2
  58. };
  59.  
  60. TileSpec spec = getNodeTileN(mn, p, dir_to_tile[facedir*16 + dir_i], data);
  61. spec.rotation=dir_to_tile[facedir*16 + dir_i+1];
  62. std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
  63. spec.texture = data->m_gamedef->tsrc()->getTexture(name);
  64. return spec;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement