Advertisement
Guest User

Untitled

a guest
Aug 7th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.42 KB | None | 0 0
  1. case NDT_MESECONLIKE:
  2.             {
  3.                 bool is_mesecon_x [] = { false, false };  /* x-1, x+1 */
  4.                 bool is_mesecon_z [] = { false, false };  /* z-1, z+1 */
  5.  
  6.                 bool is_mesecon_z_minus_y [] = { false, false };  /* z-1, z+1; y-1 */
  7.                 bool is_mesecon_x_minus_y [] = { false, false };  /* x-1, z+1; y-1 */
  8.                 bool is_mesecon_z_plus_y [] = { false, false };  /* z-1, z+1; y+1 */
  9.                 bool is_mesecon_x_plus_y [] = { false, false };  /* x-1, x+1; y+1 */
  10.  
  11.                 MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
  12.                 MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
  13.                 MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
  14.                 MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
  15.                 MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
  16.                 MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
  17.                 MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
  18.                 MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
  19.                 MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
  20.                 MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
  21.                 MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
  22.                 MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
  23.  
  24.                 content_t thiscontent = n.getContent();
  25.                 if(n_minus_x.getContent() == thiscontent)
  26.                 {
  27.                     is_mesecon_x[0] = true;
  28.                 }
  29.                 if(n_minus_x_minus_y.getContent() == thiscontent)
  30.                 {
  31.                     is_mesecon_x_minus_y[0] = true;
  32.                 }
  33.                 if(n_minus_x_plus_y.getContent() == thiscontent)
  34.                 {
  35.                     is_mesecon_x_plus_y[0] = true;
  36.                 }
  37.  
  38.                 if(n_plus_x.getContent() == thiscontent)
  39.                 {
  40.                     is_mesecon_x[1] = true;
  41.                 }
  42.                 if(n_plus_x_minus_y.getContent() == thiscontent)
  43.                 {
  44.                     is_mesecon_x_minus_y[1] = true;
  45.                 }
  46.                 if(n_plus_x_plus_y.getContent() == thiscontent)
  47.                 {
  48.                     is_mesecon_x_plus_y[1] = true;
  49.                 }
  50.  
  51.                 if(n_minus_z.getContent() == thiscontent)
  52.                 {
  53.                     is_mesecon_z[0] = true;
  54.                 }
  55.                 if(n_minus_z_minus_y.getContent() == thiscontent)
  56.                 {
  57.                     is_mesecon_z_minus_y[0] = true;
  58.                 }
  59.                 if(n_minus_z_plus_y.getContent() == thiscontent)
  60.                 {
  61.                     is_mesecon_z_plus_y[0] = true;
  62.                 }
  63.  
  64.                 if(n_plus_z.getContent() == thiscontent)
  65.                 {
  66.                     is_mesecon_z[1] = true;
  67.                 }
  68.                 if(n_plus_z_minus_y.getContent() == thiscontent)
  69.                 {
  70.                     is_mesecon_z_minus_y[1] = true;
  71.                 }
  72.                 if(n_plus_z_plus_y.getContent() == thiscontent)
  73.                 {
  74.                     is_mesecon_z_plus_y[1] = true;
  75.                 }
  76.  
  77.  
  78.                 bool is_mesecon_x_all[] = {false, false};
  79.                 bool is_mesecon_z_all[] = {false, false};
  80.                 is_mesecon_x_all[0] = is_mesecon_x[0] || is_mesecon_x_minus_y[0] || is_mesecon_x_plus_y[0];
  81.                 is_mesecon_x_all[1] = is_mesecon_x[1] || is_mesecon_x_minus_y[1] || is_mesecon_x_plus_y[1];
  82.                 is_mesecon_z_all[0] = is_mesecon_z[0] || is_mesecon_z_minus_y[0] || is_mesecon_z_plus_y[0];
  83.                 is_mesecon_z_all[1] = is_mesecon_z[1] || is_mesecon_z_minus_y[1] || is_mesecon_z_plus_y[1];
  84.  
  85.                 bool is_straight = (is_mesecon_x_all[0] && is_mesecon_x_all[1] && !is_mesecon_z_all[1] && !is_mesecon_z_all[0]) || (is_mesecon_z_all[0] && is_mesecon_z_all[1] && !is_mesecon_x_all[1] && !is_mesecon_x_all[0]);//is really straight, mesecons on both sides
  86.                 int adjacencies = is_mesecon_x_all[0] + is_mesecon_x_all[1] + is_mesecon_z_all[0] + is_mesecon_z_all[1];
  87.  
  88.  
  89.                 // Assign textures
  90.                 u8 tileindex = 0; // straight
  91.                 if(adjacencies < 2)
  92.                     tileindex = 0; // straight
  93.                 else if(adjacencies == 2)
  94.                 {
  95.                     if(is_straight)
  96.                     {
  97.                         tileindex = 0; // straight
  98.                     }
  99.                     else
  100.                     {
  101.                         tileindex = 1; // curved
  102.                     }
  103.                 }
  104.                 else if(adjacencies == 3)
  105.                 {
  106.                     tileindex = 2; // t-junction
  107.                 }
  108.                 else if(adjacencies == 4)
  109.                 {
  110.                     tileindex = 3; // crossing
  111.                 }
  112.  
  113.                 TileSpec tile = getNodeTileN(n, p, tileindex, data);
  114.                 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
  115.                 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
  116.  
  117.                 TileSpec tile_slope = getNodeTileN(n, p, 0, data);
  118.                 tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
  119.                 tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
  120.  
  121.                 AtlasPointer ap = tile.texture;
  122.                 AtlasPointer ap_slope = tile_slope.texture;
  123.  
  124.                 u16 l = getInteriorLight(n, 0, data);
  125.                 video::SColor c = MapBlock_LightColor(255, l);
  126.  
  127.                 float d = (float)BS/64;
  128.  
  129.                 u16 indices[] = {0,1,2,2,3,0};
  130.  
  131.                 if(is_mesecon_x_plus_y[0] || is_mesecon_x_plus_y[1] || is_mesecon_z_plus_y[0] || is_mesecon_z_plus_y[1])
  132.                 {
  133.                     video::S3DVertex vertices_slope[4] =
  134.                     {
  135.                         video::S3DVertex(BS/2,BS/2+d,BS/2-d, 0,0,0, c,
  136.                                 ap_slope.x1(), ap_slope.y1()),
  137.                         video::S3DVertex(-BS/2,BS/2+d,BS/2-d, 0,0,0, c,
  138.                                 ap_slope.x0(), ap_slope.y1()),
  139.                         video::S3DVertex(-BS/2,-BS/2,BS/2-d, 0,0,0, c,
  140.                                 ap_slope.x0(), ap_slope.y0()),
  141.                         video::S3DVertex(BS/2,-BS/2,BS/2-d, 0,0,0, c,
  142.                                 ap_slope.x1(), ap_slope.y0()),
  143.                     };
  144.                     video::S3DVertex vertices_slope_xplus1[4];
  145.                     video::S3DVertex vertices_slope_xplus0[4];
  146.                     video::S3DVertex vertices_slope_zplus0[4];
  147.                     video::S3DVertex vertices_slope_zplus1[4];
  148.                     for(s32 i=0; i<4; i++)
  149.                     {
  150.                         if(is_mesecon_x_plus_y[1])
  151.                         {
  152.                             vertices_slope_xplus1[i] = vertices_slope[i];
  153.                             vertices_slope_xplus1[i].Pos.rotateXZBy(-90);
  154.                         }
  155.                         if(is_mesecon_x_plus_y[0])
  156.                         {
  157.                             vertices_slope_xplus0[i] = vertices_slope[i];
  158.                             vertices_slope_xplus0[i].Pos.rotateXZBy(90);
  159.                         }
  160.                         if(is_mesecon_z_plus_y[0])
  161.                         {
  162.                             vertices_slope_zplus0[i] = vertices_slope[i];
  163.                             vertices_slope_zplus0[i].Pos.rotateXZBy(180);
  164.                         }
  165.                         if(is_mesecon_z_plus_y[1])
  166.                         {
  167.                             vertices_slope_zplus1[i] = vertices_slope[i];
  168.                             vertices_slope_zplus1[i].Pos.rotateXZBy(0);
  169.                         }
  170.                         vertices_slope_xplus1[i].Pos += intToFloat(p, BS);
  171.                         vertices_slope_xplus0[i].Pos += intToFloat(p, BS);
  172.                         vertices_slope_zplus1[i].Pos += intToFloat(p, BS);
  173.                         vertices_slope_zplus0[i].Pos += intToFloat(p, BS);
  174.                     }
  175.                     if(is_mesecon_x_plus_y[1])
  176.                     {
  177.                         collector.append(tile, vertices_slope_xplus1, 4, indices, 6);
  178.                     }
  179.                     if(is_mesecon_x_plus_y[0])
  180.                     {
  181.                         collector.append(tile, vertices_slope_xplus0, 4, indices, 6);
  182.                     }
  183.                     if(is_mesecon_z_plus_y[1])
  184.                     {
  185.                         collector.append(tile, vertices_slope_zplus1, 4, indices, 6);
  186.                     }
  187.                     if(is_mesecon_z_plus_y[0])
  188.                     {
  189.                         collector.append(tile, vertices_slope_zplus0, 4, indices, 6);
  190.                     }
  191.                 }
  192.  
  193.                 video::S3DVertex vertices[4] =
  194.                 {
  195.                         video::S3DVertex(-BS/2-d,-BS/2+d,-BS/2-d, 0,0,0, c,
  196.                                 ap.x0(), ap.y1()),
  197.                         video::S3DVertex(BS/2+d,-BS/2+d,-BS/2-d, 0,0,0, c,
  198.                                 ap.x1(), ap.y1()),
  199.                         video::S3DVertex(BS/2+d,-BS/2+d,BS/2+d, 0,0,0, c,
  200.                                 ap.x1(), ap.y0()),
  201.                         video::S3DVertex(-BS/2-d,-BS/2+d,BS/2+d, 0,0,0, c,
  202.                                 ap.x0(), ap.y0()),
  203.                 };
  204.  
  205.                 // Rotate textures
  206.                 int angle = 0;
  207.  
  208.                 if(adjacencies == 1)
  209.                 {
  210.                     if(is_mesecon_x_all[0] || is_mesecon_x_all[1])
  211.                     {
  212.                         angle = 90;
  213.                     }
  214.                 }
  215.                 if(adjacencies == 2)
  216.                 {
  217.                     if(is_mesecon_x_all[0] && is_mesecon_x_all[1])
  218.                     {
  219.                         angle = 90;
  220.                     }
  221.                     if(is_mesecon_z_all[0] && is_mesecon_z_all[1])
  222.                     {
  223.                         if (n_minus_z_plus_y.getContent() == thiscontent)
  224.                         {
  225.                             angle = 180;
  226.                         }
  227.                     }
  228.                     else if(is_mesecon_x_all[0] && is_mesecon_z_all[0])
  229.                     {
  230.                         angle = 270;
  231.                     }
  232.                     else if(is_mesecon_x_all[0] && is_mesecon_z_all[1])
  233.                     {
  234.                         angle = 180;
  235.                     }
  236.                     else if(is_mesecon_x_all[1] && is_mesecon_z_all[1])
  237.                     {
  238.                         angle = 90;
  239.                     }
  240.                 }
  241.                 if(adjacencies == 3)
  242.                 {
  243.                     if(!is_mesecon_x_all[0])
  244.                     {
  245.                         angle=0;
  246.                     }
  247.                     if(!is_mesecon_x_all[1])
  248.                     {
  249.                         angle=180;
  250.                     }
  251.                     if(!is_mesecon_z_all[0])
  252.                     {
  253.                         angle=90;
  254.                     }
  255.                     if(!is_mesecon_z_all[1])
  256.                     {
  257.                         angle=270;
  258.                     }
  259.                 }
  260.  
  261.                 if(angle != 0)
  262.                 {
  263.                     for(u16 i=0; i<4; i++)
  264.                     {
  265.                         vertices[i].Pos.rotateXZBy(angle);
  266.                     }
  267.                 }
  268.  
  269.                 for(s32 i=0; i<4; i++)
  270.                 {
  271.                     vertices[i].Pos += intToFloat(p, BS);
  272.                 }
  273.  
  274.                 collector.append(tile, vertices, 4, indices, 6);
  275.                 break;
  276.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement