Guest User

End Step

a guest
Sep 26th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //draw to surface
  2. surface_set_target(global.surid);
  3.  
  4. //list stuff
  5. var aAC,aBC,aAB,bpassed,t,zAC,zAB,zBC,ABDiff,BCDiff,ACDiff,y1,y2,z1,z2,drawn;
  6. m = 0;
  7. n = 0;
  8. a = 0;
  9. b = 0;
  10. c = 0;
  11. count = 0;
  12. drawn = false;
  13.  
  14. //start loop through vertices
  15. repeat(12)
  16. {
  17. bpassed = false;
  18.  
  19. sxt[0] = round((vertex_x[count]*Ez)/(-vertex_z[count]+Ez)+Ex);
  20. syt[0] = round((vertex_y[count]*Ez)/(-vertex_z[count]+Ez)+Ey);
  21. sxt[1] = round((vertex_x[count+1]*Ez)/(-vertex_z[count+1]+Ez)+Ex);
  22. syt[1] = round((vertex_y[count+1]*Ez)/(-vertex_z[count+1]+Ez)+Ey);
  23. sxt[2] = round((vertex_x[count+2]*Ez)/(-vertex_z[count+2]+Ez)+Ex);
  24. syt[2] = round((vertex_y[count+2]*Ez)/(-vertex_z[count+2]+Ez)+Ey);
  25. vertex_z[count] = 1/vertex_z[count];
  26. vertex_z[count+1] = 1/vertex_z[count+1];
  27. vertex_z[count+2] = 1/vertex_z[count+2];
  28.  
  29.     switch count
  30.     {
  31.     case 0:
  32.     draw_set_color(c_red); coly = c_red; break;
  33.     case 3:
  34.     draw_set_color(c_red); coly = c_red; break;
  35.     case 6:
  36.     draw_set_color(c_yellow); coly = c_yellow; break;
  37.     case 9:
  38.     draw_set_color(c_blue); coly = c_blue; break;
  39.     case 12:
  40.     draw_set_color(c_yellow); coly = c_yellow; break;
  41.     case 15:
  42.     draw_set_color(c_blue); coly = c_blue; break;
  43.     case 18:
  44.     draw_set_color(c_green); coly = c_green; break;
  45.     case 21:
  46.     draw_set_color(c_purple); coly = c_purple; break;
  47.     case 24:
  48.     draw_set_color(c_green); coly = c_green; break;
  49.     case 27:
  50.     draw_set_color(c_purple); coly = c_purple; break;
  51.     case 30:
  52.     draw_set_color(c_orange); coly = c_orange; break;
  53.     case 33:
  54.     draw_set_color(c_orange); coly = c_orange; break;
  55.     }
  56.    
  57. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  58.     if sxt[0]<sxt[1]
  59.     {
  60.         if sxt[1]<sxt[2]
  61.         {
  62.         a = 0;
  63.         b = 1;
  64.         c = 2;
  65.         }
  66.     }
  67.     if sxt[0]<sxt[2]
  68.     {
  69.         if sxt[2]<sxt[1]
  70.         {
  71.         a = 0;
  72.         b = 2;
  73.         c = 1;
  74.         }
  75.     }
  76.     if sxt[1]<sxt[2]
  77.     {
  78.         if sxt[2]<sxt[0]
  79.         {
  80.         a = 1;
  81.         b = 2;
  82.         c = 0;
  83.         }
  84.     }
  85.     if sxt[1]<sxt[0]
  86.     {
  87.         if sxt[0]<sxt[2]
  88.         {
  89.         a = 1;
  90.         b = 0;
  91.         c = 2;
  92.         }
  93.     }
  94.     if sxt[2]<sxt[1]
  95.     {
  96.         if sxt[1]<sxt[0]
  97.         {
  98.         a = 2;
  99.         b = 1;
  100.         c = 0;
  101.         }
  102.     }
  103.     if sxt[2]<sxt[0]
  104.     {
  105.         if sxt[0]<sxt[1]
  106.         {
  107.         a = 2;
  108.         b = 0;
  109.         c = 1;
  110.         }
  111.     }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114.     if a != 0 or b != 0 or c != 0
  115.     {
  116.     m = sxt[a];
  117.     n = syt[a];
  118.     tempz = vertex_z[count+a];
  119.     y1 = n//v3.x; the main helper
  120.     y2 = n + 0.5 //v3.x + 0.5f; the other helper
  121.     aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
  122.     aAB = (syt[a] - syt[b] )/(sxt[a] - sxt[b]);
  123.     aBC = (syt[b] - syt[c] )/(sxt[b] - sxt[c]);
  124.     ABDiff = sxt[b] - sxt[a];
  125.     BCDiff = sxt[c] - sxt[b];
  126.     ACDiff = sxt[c] - sxt[a];
  127.     zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
  128.     zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff;
  129.     zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff;
  130.  
  131.     /* get the change of color components along edge (v3,v1) */
  132.     //v3v1Diff = (v3.y - v1.y);
  133.     //colorSlopeBlue1 = (a.getBlue() - c1.getBlue()) / v3v1Diff;
  134.     //colorSlopeRed1 = (a.getRed() - c1.getRed()) / v3v1Diff;
  135.     //colorSlopeGreen1 = (a.getGreen() - c1.getGreen()) / v3v1Diff;
  136.     /* get the change of color components along edge (v3,v2) */
  137.     //v3v2Diff = (v3.y - v2.y);
  138.     //colorSlopeBlue2 = (a.getBlue() - c2.getBlue()) / v3v2Diff;
  139.     //colorSlopeRed2 = (a.getRed() - c2.getRed()) / v3v2Diff;
  140.     //colorSlopeGreen2 = (a.getGreen() - c2.getGreen()) / v3v2Diff;
  141.  
  142.     /* set starting values */
  143.     /*
  144.     cBlue1 = a.getBlue();
  145.     cRed1 = a.getRed();
  146.     cGreen1 = a.getGreen();
  147.     cBlue2 = a.getBlue();
  148.     cRed2 = a.getRed();
  149.     cGreen2 = a.getGreen();
  150.     */
  151.     z1 = tempz;
  152.     z2 = tempz;
  153.    
  154.         if aAC*sxt[b] + (syt[c] - aAC * sxt[c]) < syt[b]
  155.         {
  156.         /* makes sense with situations
  157.             if (aAB < slope2)
  158.             {
  159.             float slopeTmp = aAB;
  160.             aAB = slope2;
  161.             slope2 = slopeTmp;
  162.            
  163.             slopeTmp = colorSlopeRed1;
  164.             colorSlopeRed1 = colorSlopeRed2;
  165.             colorSlopeRed2 = slopeTmp;
  166.            
  167.             slopeTmp = colorSlopeGreen1;
  168.             colorSlopeGreen1 = colorSlopeGreen2;
  169.             colorSlopeGreen2 = slopeTmp;
  170.            
  171.             slopeTmp = colorSlopeBlue1;
  172.             colorSlopeBlue1 = colorSlopeBlue2;
  173.             colorSlopeBlue2 = slopeTmp;
  174.             }*/
  175.             repeat(sxt[b] - sxt[a])//x until b
  176.             {
  177.                 if m < view_wport
  178.                 {
  179.                     if m >= 0
  180.                     {
  181.                         repeat(round(y2)-round(y1))//y
  182.                         {
  183.                             if n < view_hport
  184.                             {
  185.                                 if n >= 0
  186.                                 {
  187.                                     if global.Zbuffer[m,n] < tempz
  188.                                     {
  189.                                     //int red = (int)((1 - t) * cRed1 + t * cRed2);
  190.                                     //write to z-buffer
  191.                                     global.Zbuffer[m,n] = tempz
  192.                                     //draw pixel
  193.                                     scr_render();
  194.                                     }
  195.                                 }
  196.                             }
  197.                             else
  198.                             break;
  199.                         t = (n - y1) / (y2 - y1);
  200.                         tempz = (1-t)* z1 + t * z2;
  201.                         n += 1;
  202.                         }
  203.                     }  
  204.                 }
  205.                 else
  206.                 break;
  207.             y1 += aAC;
  208.             z1 -= zAC;
  209.             //if n > testo or n < testu
  210.             //show_message(string(bpassed)+"A"+string(count)+"_"+string(y1)+"_"+string(y2)+"_"+string(aAC)+"_"+string(aBC)+"_"+string(aAB));
  211.             n = round(y1);
  212.             y2 += aAB;
  213.             z2 -= zAB;
  214.             /* get new color of left endpoint of vertical line */
  215.             //cRed1 -= colorSlopeRed1;
  216.             //cGreen1 -= colorSlopeGreen1;
  217.             //cBlue1 -= colorSlopeBlue1;
  218.             /* get new color of right endpoint of horizontal line */
  219.             //cRed2 -= colorSlopeRed2;
  220.             //cGreen2 -= colorSlopeGreen2;
  221.             //cBlue2 -= colorSlopeBlue2;
  222.             m +=1;
  223.             }
  224.             repeat(sxt[c] - sxt[b])//x until c
  225.             {
  226.                 if m < view_wport
  227.                 {
  228.                     if m >= 0
  229.                     {
  230.                         repeat(round(y2)-round(y1))//y
  231.                         {
  232.  
  233.                             if n < view_hport
  234.                             {
  235.                                 if n >= 0
  236.                                 {
  237.                                     if global.Zbuffer[m,n] < tempz
  238.                                     {
  239.                                     //int red = (int)((1 - t) * cRed1 + t * cRed2);
  240.                                     //write to z-buffer
  241.                                     global.Zbuffer[m,n] = tempz
  242.                                     //draw pixel
  243.                                     scr_render();
  244.                                     }
  245.                                 }
  246.                             }
  247.                             else
  248.                             break;
  249.                         t = (n - y1) / (y2 - y1);
  250.                         tempz = (1-t)* z1 + t * z2;
  251.                         n += 1;
  252.                         }
  253.                     }  
  254.                 }
  255.                 else
  256.                 break;
  257.             y1 += aAC;
  258.             z1 -= zAC;
  259.             n = round(y1);
  260.             y2 += aBC;
  261.             z2 -= zBC;
  262.             m +=1;
  263.             }
  264.         }
  265.         else
  266.         {
  267.         /* makes sense with situations
  268.             if (aAB < slope2)
  269.             {
  270.             float slopeTmp = aAB;
  271.             aAB = slope2;
  272.             slope2 = slopeTmp;
  273.            
  274.             slopeTmp = colorSlopeRed1;
  275.             colorSlopeRed1 = colorSlopeRed2;
  276.             colorSlopeRed2 = slopeTmp;
  277.            
  278.             slopeTmp = colorSlopeGreen1;
  279.             colorSlopeGreen1 = colorSlopeGreen2;
  280.             colorSlopeGreen2 = slopeTmp;
  281.            
  282.             slopeTmp = colorSlopeBlue1;
  283.             colorSlopeBlue1 = colorSlopeBlue2;
  284.             colorSlopeBlue2 = slopeTmp;
  285.             }*/
  286.             repeat(sxt[b] - sxt[a])//x until b
  287.             {
  288.                 if m < view_wport
  289.                 {
  290.                     if m >= 0
  291.                     {
  292.                         repeat(round(y1)-round(y2))//y
  293.                         {
  294.                             if n >= 0
  295.                             {
  296.                                 if n < view_hport
  297.                                 {
  298.                                     if global.Zbuffer[m,n] < tempz
  299.                                     {
  300.                                     //int red = (int)((1 - t) * cRed1 + t * cRed2);
  301.                                     //write to z-buffer
  302.                                     global.Zbuffer[m,n] = tempz
  303.                                     //draw pixel
  304.                                     scr_render();
  305.                                     }
  306.                                 }
  307.                             }
  308.                             else
  309.                             break;
  310.                         t = (n - y1) / (y2 - y1);
  311.                         tempz = (1-t)* z1 + t * z2;
  312.                         n -= 1;
  313.                         }
  314.                     }  
  315.                 }
  316.                 else
  317.                 break;
  318.             y1 += aAC;
  319.             z1 -= zAC;
  320.             //if n > testo or n < testu
  321.             //show_message(string(bpassed)+"A"+string(count)+"_"+string(y1)+"_"+string(y2)+"_"+string(aAC)+"_"+string(aBC)+"_"+string(aAB));
  322.             n = round(y1);
  323.             y2 += aAB;
  324.             z2 -= zAB;
  325.             /* get new color of left endpoint of vertical line */
  326.             //cRed1 -= colorSlopeRed1;
  327.             //cGreen1 -= colorSlopeGreen1;
  328.             //cBlue1 -= colorSlopeBlue1;
  329.             /* get new color of right endpoint of horizontal line */
  330.             //cRed2 -= colorSlopeRed2;
  331.             //cGreen2 -= colorSlopeGreen2;
  332.             //cBlue2 -= colorSlopeBlue2;
  333.             m +=1;
  334.             }
  335.             repeat(sxt[c] - sxt[b])//x until c
  336.             {
  337.                 if m < view_wport
  338.                 {
  339.                     if m >= 0
  340.                     {
  341.                         repeat(round(y1)-round(y2))//y
  342.                         {
  343.                             if n >= 0
  344.                             {
  345.                                 if n < view_hport
  346.                                 {
  347.                                     if global.Zbuffer[m,n] < tempz
  348.                                     {
  349.                                     //int red = (int)((1 - t) * cRed1 + t * cRed2);
  350.                                     //write to z-buffer
  351.                                     global.Zbuffer[m,n] = tempz
  352.                                     //draw pixel
  353.                                     scr_render();
  354.                                     }
  355.                                 }
  356.                             }
  357.                             else
  358.                             break;
  359.                         t = (n - y1) / (y2 - y1);
  360.                         tempz = (1-t)* z1 + t * z2;
  361.                         n -= 1;
  362.                         }
  363.                     }  
  364.                 }
  365.                 else
  366.                 break;
  367.             y1 += aAC;
  368.             z1 -= zAC;
  369.             n = round(y1);
  370.             y2 += aBC;
  371.             z2 -= zBC;
  372.             m +=1;
  373.             }
  374.         }
  375.         drawn = true;
  376.         a = 0;
  377.         b = 0;
  378.         c = 0;
  379.     }
  380.     else
  381.     {            
  382.     if sxt[1]<sxt[2]/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  383.     {
  384.         if sxt[0]=sxt[1]
  385.         {  
  386.             if syt[0] < syt[1]
  387.             {
  388.             a = 0;
  389.             b = 1;
  390.             c = 2;
  391.             }
  392.             else
  393.             {
  394.             a = 1;
  395.             b = 0;
  396.             c = 2;
  397.             }
  398.         }
  399.         else if sxt[2]=sxt[0]
  400.         {
  401.             if syt[2] < syt[0]
  402.             {
  403.             a = 1;
  404.             b = 0;
  405.             c = 2;
  406.             }
  407.             else
  408.             {
  409.             a = 1;
  410.             b = 2;
  411.             c = 0;
  412.             }
  413.         }
  414.     }
  415.     else if sxt[2]<sxt[1]
  416.     {
  417.         if sxt[0]=sxt[2]
  418.         {  
  419.             if syt[0] < syt[2]
  420.             {
  421.             a = 0;
  422.             b = 2;
  423.             c = 1;
  424.             }
  425.             else
  426.             {
  427.             a = 2;
  428.             b = 0;
  429.             c = 1;
  430.             }
  431.         }
  432.         else if sxt[1]=sxt[0]
  433.         {  
  434.             if syt[1] < syt[0]
  435.             {
  436.             a = 2;
  437.             b = 0;
  438.             c = 1;
  439.             }
  440.             else
  441.             {
  442.             a = 2;
  443.             b = 1;
  444.             c = 0;
  445.             }
  446.         }
  447.     }
  448.     else if sxt[2]<sxt[0]
  449.     {
  450.         if sxt[1]=sxt[2]
  451.         {  
  452.             if syt[1] < syt[2]
  453.             {
  454.             a = 1;
  455.             b = 2;
  456.             c = 0;
  457.             }
  458.             else
  459.             {
  460.             a = 2;
  461.             b = 1;
  462.             c = 0;
  463.             }
  464.         }
  465.     }
  466.     else if sxt[0]<sxt[1]
  467.     {
  468.         if sxt[1]=sxt[2]
  469.         {  
  470.             if syt[1] < syt[2]
  471.             {
  472.             a = 0;
  473.             b = 2;
  474.             c = 1;
  475.             }
  476.             else
  477.             {
  478.             a = 0;
  479.             b = 1;
  480.             c = 2;
  481.             }
  482.         }
  483.     }
  484. }
  485. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  486.     if (a != 0 or b != 0 or c != 0) and drawn = false
  487.     {
  488.     m = sxt[a];
  489.     n = syt[a];
  490.     tempz = vertex_z[count+a];
  491.     y1 = n//v3.x; the main helper
  492.     y2 = n+ 0.5 //v3.x + 0.5f; the other helper
  493.     /* get the change of color components along edge (v3,v1) */
  494.     //v3v1Diff = (v3.y - v1.y);
  495.     //colorSlopeBlue1 = (a.getBlue() - c1.getBlue()) / v3v1Diff;
  496.     //colorSlopeRed1 = (a.getRed() - c1.getRed()) / v3v1Diff;
  497.     //colorSlopeGreen1 = (a.getGreen() - c1.getGreen()) / v3v1Diff;
  498.     /* get the change of color components along edge (v3,v2) */
  499.     //v3v2Diff = (v3.y - v2.y);
  500.     //colorSlopeBlue2 = (a.getBlue() - c2.getBlue()) / v3v2Diff;
  501.     //colorSlopeRed2 = (a.getRed() - c2.getRed()) / v3v2Diff;
  502.     //colorSlopeGreen2 = (a.getGreen() - c2.getGreen()) / v3v2Diff;
  503.  
  504.     /* set starting values */
  505.     /*
  506.     cBlue1 = a.getBlue();
  507.     cRed1 = a.getRed();
  508.     cGreen1 = a.getGreen();
  509.     cBlue2 = a.getBlue();
  510.     cRed2 = a.getRed();
  511.     cGreen2 = a.getGreen();
  512.     */
  513.     z1 = tempz;
  514.     z2 = tempz;
  515.         if sxt[a] = sxt[b]
  516.         {
  517.         aBC = (syt[b] - syt[c] )/(sxt[b] - sxt[c]);
  518.         aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
  519.         BCDiff = sxt[c] - sxt[b];
  520.         ACDiff = sxt[c] - sxt[a];
  521.         y2 = syt[b];
  522.         zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
  523.         zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
  524.             repeat(sxt[c] - sxt[a])
  525.             {
  526.                 if m < view_wport
  527.                 {
  528.                     if m >= 0
  529.                     {
  530.                         repeat(round(y2)-round(y1))
  531.                         {
  532.  
  533.                             if n < view_hport
  534.                             {
  535.                                 if n >= 0
  536.                                 {
  537.                                     if global.Zbuffer[m,n] < tempz
  538.                                     {
  539.                                     //write to z-buffer
  540.                                     global.Zbuffer[m,n] = tempz
  541.                                     //draw pixel
  542.                                     scr_render();
  543.                                     }
  544.                                 }
  545.                             }
  546.                             else
  547.                             break;
  548.                         t = (n - y1) / (y2 - y1);
  549.                         tempz = (1-t)* z1 + t * z2;
  550.                         n += 1;
  551.                         }
  552.                     }
  553.                 }
  554.                 else
  555.                 break;
  556.                
  557.             y1 += aAC;
  558.             z1 -= zAC;
  559.             n = round(y1);
  560.             y2 += aBC;
  561.             z2 -= zBC;
  562.             m += 1;
  563.             }//loop until last point is reached
  564.         }
  565.         else
  566.         {
  567.         //pre calculating slopes for interpolation
  568.         aAB = (syt[a] - syt[b] )/(sxt[a] - sxt[b]) ;
  569.         aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
  570.         ABDiff = sxt[b] - sxt[a];
  571.         ACDiff = sxt[c] - sxt[a];
  572.         zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
  573.         zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
  574.             repeat(sxt[c] - sxt[a])
  575.             {
  576.                 if  m < view_wport
  577.                 {
  578.                     if m >= 0
  579.                     {
  580.                         repeat(round(y2)-round(y1))
  581.                         {
  582.  
  583.                             if n < view_hport
  584.                             {
  585.                                 if n >= 0
  586.                                 {
  587.                                     if global.Zbuffer[m,n] < tempz
  588.                                     {
  589.                                     //write to z-buffer
  590.                                     global.Zbuffer[m,n] = tempz
  591.                                     //draw pixel
  592.                                     scr_render();
  593.                                     }
  594.                                 }
  595.                             }
  596.                             else
  597.                             break;
  598.                         t = (n - y1) / (y2 - y1);
  599.                         tempz = (1-t)* z1 + t * z2;
  600.                         n += 1;
  601.                         }
  602.                     }
  603.                 }
  604.                 else
  605.                 break;    
  606.             y1 += aAC;
  607.             z1 -= zAC;
  608.             n = round(y1);
  609.             y2 += aAB;
  610.             z2 -= zAB;
  611.             m += 1;
  612.             }//loop until last point is reached
  613.         }
  614.     }//if sxt[2]=sxt[1]and sxt[1]=sxt[0] and sxt[0] >= 0 and sxt[0] < view_wport///////////////////////////////////////////////////
  615.     else if drawn = false//the last and most bull-shit draw
  616.     {
  617.     m = sxt[0]
  618.         if syt[0] > syt[1] and syt[1] > syt[2]
  619.         {
  620.         a = 2;
  621.         b = 1;
  622.         c = 0;
  623.         }
  624.         else if syt[0] > syt[2] and syt[2] > syt[1]
  625.         {
  626.         a = 1;
  627.         b = 2;
  628.         c = 0;
  629.         }
  630.         else if syt[1] > syt[0] and syt[0] > syt[2]
  631.         {
  632.         a = 2;
  633.         b = 0;
  634.         c = 1;
  635.         }
  636.         else if syt[1] > syt[2] and syt[2] > syt[0]
  637.         {
  638.         a = 0;
  639.         b = 2;
  640.         c = 1;
  641.         }
  642.         else if syt[2] > syt[0] and syt[0] > syt[1]
  643.         {
  644.         a = 1;
  645.         b = 0;
  646.         c = 2;
  647.         }
  648.         else if syt[2] > syt[1] and syt[1] > syt[0]
  649.         {
  650.         a = 0;
  651.         b = 1;
  652.         c = 2;
  653.         }
  654.         tempz = vertex_z[count+a];
  655.         n = syt[a];
  656.        
  657.         if round(vertex_z[count+a] - vertex_z[count+c]) != 0
  658.         {
  659.             if syt[b] > (syt[a] - syt[c])/(vertex_z[count+a] - vertex_z[count+c]) * vertex_z[count+b] + (syt[a] - vertex_z[count+a] * (syt[a] - syt[c])/(vertex_z[count+a] - vertex_z[count+c]))
  660.             {
  661.             ABDiff = syt[b] - syt[a];
  662.             BCDiff = syt[c] - syt[b];
  663.             zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
  664.             zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
  665.                 repeat(ABDiff)
  666.                 {
  667.                     if n <= view_hport
  668.                     {
  669.                         if n >= 0
  670.                         {
  671.                             if global.Zbuffer[sxt[c],n] < 1/tempz
  672.                             {
  673.                             //write to z-buffer
  674.                             global.Zbuffer[sxt[c],n] = 1/tempz
  675.                             //draw pixel
  676.                             scr_render();
  677.                             }
  678.                         }
  679.                     }
  680.                     else
  681.                     break;
  682.                 n += 1;
  683.                 tempz -= zAB
  684.                 }
  685.                 repeat(BCDiff)
  686.                 {
  687.                     if n <= view_hport
  688.                     {
  689.                         if n >= 0
  690.                         {
  691.                             if global.Zbuffer[sxt[c],n] < 1/tempz
  692.                             {
  693.                             //write to z-buffer
  694.                             global.Zbuffer[sxt[c],n] = 1/tempz
  695.                             //draw pixel
  696.                             scr_render();
  697.                             }
  698.                         }
  699.                     }
  700.                     else
  701.                     break;
  702.                 n += 1;
  703.                 tempz -= zBC
  704.                 }
  705.             }
  706.             else
  707.             {
  708.             ACDiff = syt[c] - syt[a];
  709.                 if vertex_z[count+c] > vertex_z[count+a]
  710.                 zAC = (vertex_z[count+c] - vertex_z[count+a])/ACDiff
  711.                 else
  712.                 zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff
  713.    
  714.                 repeat(ACDiff)
  715.                 {
  716.                     if n <= view_hport
  717.                     {
  718.                         if n >= 0
  719.                         {
  720.                             if global.Zbuffer[sxt[c],n] < tempz
  721.                             {
  722.                             //write to z-buffer
  723.                             global.Zbuffer[sxt[c],n] = tempz
  724.                             //draw pixel
  725.                             scr_render();
  726.                             }
  727.                         }
  728.                     }
  729.                     else
  730.                     break;
  731.                 n += 1;
  732.                 tempz -= zAC
  733.                 }
  734.             }
  735.         }
  736.         else if vertex_z[a] < vertex_z[b]
  737.         {
  738.         ABDiff = syt[b] - syt[a];
  739.         BCDiff = syt[c] - syt[b];
  740.             if vertex_z[count+c] > vertex_z[count+a]
  741.             zAB = (vertex_z[count+b] - vertex_z[count+a])/ABDiff
  742.             else
  743.             zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
  744.             if vertex_z[count+c] > vertex_z[count+b]
  745.             zBC = (vertex_z[count+c] - vertex_z[count+b])/BCDiff
  746.             else
  747.             zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
  748.        
  749.             repeat(ABDiff)
  750.             {
  751.                 if n <= view_hport
  752.                 {
  753.                     if n >= 0
  754.                     {
  755.                         if global.Zbuffer[sxt[c],n] < 1/tempz
  756.                         {
  757.                         //write to z-buffer
  758.                         global.Zbuffer[sxt[c],n] = 1/tempz
  759.                         //draw pixel
  760.                         scr_render();
  761.                         }
  762.                     }
  763.                 }
  764.                 else
  765.                 break;
  766.             n += 1;
  767.             tempz -= zAB
  768.             }
  769.             repeat(BCDiff)
  770.             {
  771.                 if n <= view_hport
  772.                 {
  773.                     if n >= 0
  774.                     {
  775.                         if global.Zbuffer[sxt[c],n] < 1/tempz
  776.                         {
  777.                         //write to z-buffer
  778.                         global.Zbuffer[sxt[c],n] = 1/tempz
  779.                         //draw pixel
  780.                         scr_render();
  781.                         }
  782.                     }
  783.                 }
  784.                 else
  785.                 break;
  786.             n += 1;
  787.             tempz -= zBC
  788.             }
  789.         }
  790.         else
  791.         {
  792.             repeat(syt[c]-syt[a])
  793.             {
  794.                 if n <= view_hport
  795.                 {
  796.                     if n >= 0
  797.                     {
  798.                         if global.Zbuffer[sxt[c],n] < tempz
  799.                         {
  800.                         //write to z-buffer
  801.                         global.Zbuffer[sxt[c],n] = tempz
  802.                         //draw pixel
  803.                         scr_render();
  804.                         }
  805.                     }
  806.                 }
  807.                 else
  808.                 break;
  809.             n += 1;
  810.             }
  811.         }
  812.     }
  813. //all drawing end here.
  814. //some variables are cleared and the loop continues
  815. count += 3;
  816. draw_set_alpha(1);
  817. a = 0;
  818. b = 0;
  819. c = 0;
  820. drawn = false;
  821. }
  822. //once all vertices are done, stop drawing on this surface and go to the draw output
  823. surface_reset_target();
Add Comment
Please, Sign In to add comment