Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. case NDT_NODEBOX:
  2. static const v3s16 tile_dirs[6] = {
  3. v3s16(0, 1, 0),
  4. v3s16(0, -1, 0),
  5. v3s16(1, 0, 0),
  6. v3s16(-1, 0, 0),
  7. v3s16(0, 0, 1),
  8. v3s16(0, 0, -1)
  9. };
  10. TileSpec tiles[6];
  11. u16 l = getInteriorLight(n, 0, data);
  12. video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
  13.  
  14. v3f pos = intToFloat(p, BS);
  15.  
  16. std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
  17.  
  18. for(std::vector<aabb3f>::iterator
  19. i = boxes.begin();
  20. i != boxes.end(); i++)
  21. {
  22. for(int j = 0; j < 6; j++)
  23. {
  24. // Handles facedir rotation for textures
  25. tiles[j] = getNodeTile(n, p, tile_dirs[j], data);
  26. }
  27. aabb3f box = *i;
  28. box.MinEdge += pos;
  29. box.MaxEdge += pos;
  30.  
  31.  
  32. f32 temp;
  33. if (box.MinEdge.X > box.MaxEdge.X)
  34. {
  35. temp=box.MinEdge.X;
  36. box.MinEdge.X=box.MaxEdge.X;
  37. box.MaxEdge.X=temp;
  38. }
  39. if (box.MinEdge.Y > box.MaxEdge.Y)
  40. {
  41. temp=box.MinEdge.Y;
  42. box.MinEdge.Y=box.MaxEdge.Y;
  43. box.MaxEdge.Y=temp;
  44. }
  45. if (box.MinEdge.Z > box.MaxEdge.Z)
  46. {
  47. temp=box.MinEdge.Z;
  48. box.MinEdge.Z=box.MaxEdge.Z;
  49. box.MaxEdge.Z=temp;
  50. }
  51.  
  52.  
  53. // Compute texture coords
  54. f32 tx1 = (i->MinEdge.X/BS)+0.5;
  55. f32 ty1 = (i->MinEdge.Y/BS)+0.5;
  56. f32 tz1 = (i->MinEdge.Z/BS)+0.5;
  57. f32 tx2 = (i->MaxEdge.X/BS)+0.5;
  58. f32 ty2 = (i->MaxEdge.Y/BS)+0.5;
  59. f32 tz2 = (i->MaxEdge.Z/BS)+0.5;
  60. f32 txc[24] = {
  61. // up
  62. tx1, 1-tz2, tx2, 1-tz1,
  63. // down
  64. tx1, tz1, tx2, tz2,
  65. // right
  66. tz1, 1-ty2, tz2, 1-ty1,
  67. // left
  68. 1-tz2, 1-ty2, 1-tz1, 1-ty1,
  69. // back
  70. 1-tx2, 1-ty2, 1-tx1, 1-ty1,
  71. // front
  72. tx1, 1-ty2, tx2, 1-ty1,
  73. };
  74. f32 t;
  75. for(int k = 0; k < 6; k++)
  76. {
  77. switch (tiles[k].rotation)
  78. {
  79. case 0:
  80. break;
  81. case 2: //R180
  82. t = txc[k*4];
  83. txc[k*4] = txc[k*4+2];
  84. txc[k*4+2] = t;
  85. t = txc[k*4+1];
  86. txc[k*4+1] = txc[k*4+3];
  87. txc[k*4+3] = t;
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. makeCuboid(&collector, box, tiles, 6, c, txc);
  94. }
  95. break;
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement