Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. case NDT_GLASSLIKE_FRAMED:
  2. {
  3. static const v3s16 dirs[6] = {
  4. v3s16( 0, 1, 0),
  5. v3s16( 0,-1, 0),
  6. v3s16( 1, 0, 0),
  7. v3s16(-1, 0, 0),
  8. v3s16( 0, 0, 1),
  9. v3s16( 0, 0,-1)
  10. };
  11.  
  12. TileSpec tiles[2];
  13. tiles[0] = getNodeTile(n, p, dirs[0], data);
  14. tiles[1] = getNodeTile(n, p, dirs[1], data);
  15. u16 l = getInteriorLight(n, 1, data);
  16. video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
  17. v3f pos = intToFloat(p, BS);
  18. static const float a=BS/2;
  19. static const float b=.876*(BS/2);
  20. static const aabb3f frame_edges[12] =
  21. {
  22. aabb3f( b, b,-a, a, a, a), // y+
  23. aabb3f(-a, b,-a,-b, a, a), // y+
  24. aabb3f( b,-a,-a, a,-b, a), // y-
  25. aabb3f(-a,-a,-a,-b,-b, a), // y-
  26. aabb3f( b,-a, b, a, a, a), // x+
  27. aabb3f( b,-a,-a, a, a,-b), // x+
  28. aabb3f(-a,-a, b,-b, a, a), // x-
  29. aabb3f(-a,-a,-a,-b, a,-b), // x-
  30. aabb3f(-a, b, b, a, a, a), // z+
  31. aabb3f(-a,-a, b, a,-b, a), // z+
  32. aabb3f(-a,-a,-a, a,-b,-b), // z-
  33. aabb3f(-a, b,-a, a, a,-b) // z-
  34. };
  35. aabb3f glass_faces[6] =
  36. {
  37. aabb3f(-a, a,-a, a, a, a), // y+
  38. aabb3f(-a,-a,-a, a,-a, a), // y-
  39. aabb3f( a,-a,-a, a, a, a), // x+
  40. aabb3f(-a,-a,-a,-a, a, a), // x-
  41. aabb3f(-a,-a, a, a, a, a), // z+
  42. aabb3f(-a,-a,-a, a, a,-a) // z-
  43. };
  44.  
  45. int visible_faces[6] = {0,0,0,0,0,0};
  46. int nb[18]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  47. u8 i;
  48. content_t current = n.getContent();
  49. //errorstream<<"glass id = "<<current<<std::endl;
  50. content_t content;
  51. MapNode n2;
  52. v3s16 n2p;
  53. for(i=0; i<18; i++)
  54. {
  55. n2p = blockpos_nodes + p + g_26dirs[i];
  56. n2 = data->m_vmanip.getNodeNoEx(n2p);
  57. content_t n2c = n2.getContent();
  58. //TODO: remove CONTENT_IGNORE when getNodeNoEx is fixed
  59. //if (i==2) errorstream<<"x+ = "<<n2c<<std::endl;
  60. if (n2c == current || n2c == CONTENT_IGNORE)
  61. nb[i]=1;
  62. }
  63. for(i=0; i<6; i++)
  64. {
  65. n2p = blockpos_nodes + p + dirs[i];
  66. n2 = data->m_vmanip.getNodeNoEx(n2p);
  67. content = n2.getContent();
  68. const ContentFeatures &f2 = nodedef->get(content);
  69. if (content == CONTENT_AIR || f2.isLiquid())
  70. visible_faces[i]=1;
  71. }
  72. static const u8 nb_triplet[12*3] = {
  73. 1,2,7,
  74. 1,5,6,
  75. 4,2,15,
  76. 4,5,14,
  77. 2,0,11,
  78. 2,3,13,
  79. 5,0,10,
  80. 5,3,12,
  81. 0,1,8,
  82. 0,4,16,
  83. 3,4,17,
  84. 3,1,9
  85. };
  86.  
  87. f32 tx1,ty1,tz1,tx2,ty2,tz2;
  88. for(i=0; i<12; i++)
  89. {
  90. int edge_visible;
  91. if (nb[nb_triplet[i*3+2]]==1)
  92. edge_visible=nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]];
  93. else
  94. edge_visible=nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]];
  95. if (edge_visible)
  96. continue;
  97. aabb3f box;
  98. box=frame_edges[i];
  99. box.MinEdge += pos;
  100. box.MaxEdge += pos;
  101. tx1 = (box.MinEdge.X/BS)+0.5;
  102. ty1 = (box.MinEdge.Y/BS)+0.5;
  103. tz1 = (box.MinEdge.Z/BS)+0.5;
  104. tx2 = (box.MaxEdge.X/BS)+0.5;
  105. ty2 = (box.MaxEdge.Y/BS)+0.5;
  106. tz2 = (box.MaxEdge.Z/BS)+0.5;
  107. f32 txc1[24] = {
  108. tx1, 1-tz2, tx2, 1-tz1,
  109. tx1, tz1, tx2, tz2,
  110. tz1, 1-ty2, tz2, 1-ty1,
  111. 1-tz2, 1-ty2, 1-tz1, 1-ty1,
  112. 1-tx2, 1-ty2, 1-tx1, 1-ty1,
  113. tx1, 1-ty2, tx2, 1-ty1,
  114. };
  115. makeCuboid(&collector, box, &tiles[0], 1, c, txc1);
  116. }
  117. for(i=0; i<6; i++)
  118. {
  119. if (visible_faces[i]==0)
  120. continue;
  121. aabb3f box;
  122. box=glass_faces[i];
  123. box.MinEdge += pos;
  124. box.MaxEdge += pos;
  125. tx1 = (box.MinEdge.X/BS)+0.5;
  126. ty1 = (box.MinEdge.Y/BS)+0.5;
  127. tz1 = (box.MinEdge.Z/BS)+0.5;
  128. tx2 = (box.MaxEdge.X/BS)+0.5;
  129. ty2 = (box.MaxEdge.Y/BS)+0.5;
  130. tz2 = (box.MaxEdge.Z/BS)+0.5;
  131. f32 txc2[24] = {
  132. tx1, 1-tz2, tx2, 1-tz1,
  133. tx1, tz1, tx2, tz2,
  134. tz1, 1-ty2, tz2, 1-ty1,
  135. 1-tz2, 1-ty2, 1-tz1, 1-ty1,
  136. 1-tx2, 1-ty2, 1-tx1, 1-ty1,
  137. tx1, 1-ty2, tx2, 1-ty1,
  138. };
  139. makeCuboid(&collector, box, &tiles[1], 1, c, txc2);
  140. }
  141. break;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement