Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //draw to surface
- surface_set_target(global.surid);
- //list stuff
- var aAC,aBC,aAB,bpassed,t,zAC,zAB,zBC,ABDiff,BCDiff,ACDiff,y1,y2,z1,z2,drawn;
- m = 0;
- n = 0;
- a = 0;
- b = 0;
- c = 0;
- count = 0;
- drawn = false;
- //start loop through vertices
- repeat(12)
- {
- bpassed = false;
- sxt[0] = round((vertex_x[count]*Ez)/(-vertex_z[count]+Ez)+Ex);
- syt[0] = round((vertex_y[count]*Ez)/(-vertex_z[count]+Ez)+Ey);
- sxt[1] = round((vertex_x[count+1]*Ez)/(-vertex_z[count+1]+Ez)+Ex);
- syt[1] = round((vertex_y[count+1]*Ez)/(-vertex_z[count+1]+Ez)+Ey);
- sxt[2] = round((vertex_x[count+2]*Ez)/(-vertex_z[count+2]+Ez)+Ex);
- syt[2] = round((vertex_y[count+2]*Ez)/(-vertex_z[count+2]+Ez)+Ey);
- vertex_z[count] = 1/vertex_z[count];
- vertex_z[count+1] = 1/vertex_z[count+1];
- vertex_z[count+2] = 1/vertex_z[count+2];
- switch count
- {
- case 0:
- draw_set_color(c_red); coly = c_red; break;
- case 3:
- draw_set_color(c_red); coly = c_red; break;
- case 6:
- draw_set_color(c_yellow); coly = c_yellow; break;
- case 9:
- draw_set_color(c_blue); coly = c_blue; break;
- case 12:
- draw_set_color(c_yellow); coly = c_yellow; break;
- case 15:
- draw_set_color(c_blue); coly = c_blue; break;
- case 18:
- draw_set_color(c_green); coly = c_green; break;
- case 21:
- draw_set_color(c_purple); coly = c_purple; break;
- case 24:
- draw_set_color(c_green); coly = c_green; break;
- case 27:
- draw_set_color(c_purple); coly = c_purple; break;
- case 30:
- draw_set_color(c_orange); coly = c_orange; break;
- case 33:
- draw_set_color(c_orange); coly = c_orange; break;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if sxt[0]<sxt[1]
- {
- if sxt[1]<sxt[2]
- {
- a = 0;
- b = 1;
- c = 2;
- }
- }
- if sxt[0]<sxt[2]
- {
- if sxt[2]<sxt[1]
- {
- a = 0;
- b = 2;
- c = 1;
- }
- }
- if sxt[1]<sxt[2]
- {
- if sxt[2]<sxt[0]
- {
- a = 1;
- b = 2;
- c = 0;
- }
- }
- if sxt[1]<sxt[0]
- {
- if sxt[0]<sxt[2]
- {
- a = 1;
- b = 0;
- c = 2;
- }
- }
- if sxt[2]<sxt[1]
- {
- if sxt[1]<sxt[0]
- {
- a = 2;
- b = 1;
- c = 0;
- }
- }
- if sxt[2]<sxt[0]
- {
- if sxt[0]<sxt[1]
- {
- a = 2;
- b = 0;
- c = 1;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if a != 0 or b != 0 or c != 0
- {
- m = sxt[a];
- n = syt[a];
- tempz = vertex_z[count+a];
- y1 = n//v3.x; the main helper
- y2 = n + 0.5 //v3.x + 0.5f; the other helper
- aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
- aAB = (syt[a] - syt[b] )/(sxt[a] - sxt[b]);
- aBC = (syt[b] - syt[c] )/(sxt[b] - sxt[c]);
- ABDiff = sxt[b] - sxt[a];
- BCDiff = sxt[c] - sxt[b];
- ACDiff = sxt[c] - sxt[a];
- zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
- zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff;
- zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff;
- /* get the change of color components along edge (v3,v1) */
- //v3v1Diff = (v3.y - v1.y);
- //colorSlopeBlue1 = (a.getBlue() - c1.getBlue()) / v3v1Diff;
- //colorSlopeRed1 = (a.getRed() - c1.getRed()) / v3v1Diff;
- //colorSlopeGreen1 = (a.getGreen() - c1.getGreen()) / v3v1Diff;
- /* get the change of color components along edge (v3,v2) */
- //v3v2Diff = (v3.y - v2.y);
- //colorSlopeBlue2 = (a.getBlue() - c2.getBlue()) / v3v2Diff;
- //colorSlopeRed2 = (a.getRed() - c2.getRed()) / v3v2Diff;
- //colorSlopeGreen2 = (a.getGreen() - c2.getGreen()) / v3v2Diff;
- /* set starting values */
- /*
- cBlue1 = a.getBlue();
- cRed1 = a.getRed();
- cGreen1 = a.getGreen();
- cBlue2 = a.getBlue();
- cRed2 = a.getRed();
- cGreen2 = a.getGreen();
- */
- z1 = tempz;
- z2 = tempz;
- if aAC*sxt[b] + (syt[c] - aAC * sxt[c]) < syt[b]
- {
- /* makes sense with situations
- if (aAB < slope2)
- {
- float slopeTmp = aAB;
- aAB = slope2;
- slope2 = slopeTmp;
- slopeTmp = colorSlopeRed1;
- colorSlopeRed1 = colorSlopeRed2;
- colorSlopeRed2 = slopeTmp;
- slopeTmp = colorSlopeGreen1;
- colorSlopeGreen1 = colorSlopeGreen2;
- colorSlopeGreen2 = slopeTmp;
- slopeTmp = colorSlopeBlue1;
- colorSlopeBlue1 = colorSlopeBlue2;
- colorSlopeBlue2 = slopeTmp;
- }*/
- repeat(sxt[b] - sxt[a])//x until b
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y2)-round(y1))//y
- {
- if n < view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[m,n] < tempz
- {
- //int red = (int)((1 - t) * cRed1 + t * cRed2);
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n += 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- //if n > testo or n < testu
- //show_message(string(bpassed)+"A"+string(count)+"_"+string(y1)+"_"+string(y2)+"_"+string(aAC)+"_"+string(aBC)+"_"+string(aAB));
- n = round(y1);
- y2 += aAB;
- z2 -= zAB;
- /* get new color of left endpoint of vertical line */
- //cRed1 -= colorSlopeRed1;
- //cGreen1 -= colorSlopeGreen1;
- //cBlue1 -= colorSlopeBlue1;
- /* get new color of right endpoint of horizontal line */
- //cRed2 -= colorSlopeRed2;
- //cGreen2 -= colorSlopeGreen2;
- //cBlue2 -= colorSlopeBlue2;
- m +=1;
- }
- repeat(sxt[c] - sxt[b])//x until c
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y2)-round(y1))//y
- {
- if n < view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[m,n] < tempz
- {
- //int red = (int)((1 - t) * cRed1 + t * cRed2);
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n += 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- n = round(y1);
- y2 += aBC;
- z2 -= zBC;
- m +=1;
- }
- }
- else
- {
- /* makes sense with situations
- if (aAB < slope2)
- {
- float slopeTmp = aAB;
- aAB = slope2;
- slope2 = slopeTmp;
- slopeTmp = colorSlopeRed1;
- colorSlopeRed1 = colorSlopeRed2;
- colorSlopeRed2 = slopeTmp;
- slopeTmp = colorSlopeGreen1;
- colorSlopeGreen1 = colorSlopeGreen2;
- colorSlopeGreen2 = slopeTmp;
- slopeTmp = colorSlopeBlue1;
- colorSlopeBlue1 = colorSlopeBlue2;
- colorSlopeBlue2 = slopeTmp;
- }*/
- repeat(sxt[b] - sxt[a])//x until b
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y1)-round(y2))//y
- {
- if n >= 0
- {
- if n < view_hport
- {
- if global.Zbuffer[m,n] < tempz
- {
- //int red = (int)((1 - t) * cRed1 + t * cRed2);
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n -= 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- //if n > testo or n < testu
- //show_message(string(bpassed)+"A"+string(count)+"_"+string(y1)+"_"+string(y2)+"_"+string(aAC)+"_"+string(aBC)+"_"+string(aAB));
- n = round(y1);
- y2 += aAB;
- z2 -= zAB;
- /* get new color of left endpoint of vertical line */
- //cRed1 -= colorSlopeRed1;
- //cGreen1 -= colorSlopeGreen1;
- //cBlue1 -= colorSlopeBlue1;
- /* get new color of right endpoint of horizontal line */
- //cRed2 -= colorSlopeRed2;
- //cGreen2 -= colorSlopeGreen2;
- //cBlue2 -= colorSlopeBlue2;
- m +=1;
- }
- repeat(sxt[c] - sxt[b])//x until c
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y1)-round(y2))//y
- {
- if n >= 0
- {
- if n < view_hport
- {
- if global.Zbuffer[m,n] < tempz
- {
- //int red = (int)((1 - t) * cRed1 + t * cRed2);
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n -= 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- n = round(y1);
- y2 += aBC;
- z2 -= zBC;
- m +=1;
- }
- }
- drawn = true;
- a = 0;
- b = 0;
- c = 0;
- }
- else
- {
- if sxt[1]<sxt[2]/////////////////////////////////////////////////////////////////////////////////////////////////////////////
- {
- if sxt[0]=sxt[1]
- {
- if syt[0] < syt[1]
- {
- a = 0;
- b = 1;
- c = 2;
- }
- else
- {
- a = 1;
- b = 0;
- c = 2;
- }
- }
- else if sxt[2]=sxt[0]
- {
- if syt[2] < syt[0]
- {
- a = 1;
- b = 0;
- c = 2;
- }
- else
- {
- a = 1;
- b = 2;
- c = 0;
- }
- }
- }
- else if sxt[2]<sxt[1]
- {
- if sxt[0]=sxt[2]
- {
- if syt[0] < syt[2]
- {
- a = 0;
- b = 2;
- c = 1;
- }
- else
- {
- a = 2;
- b = 0;
- c = 1;
- }
- }
- else if sxt[1]=sxt[0]
- {
- if syt[1] < syt[0]
- {
- a = 2;
- b = 0;
- c = 1;
- }
- else
- {
- a = 2;
- b = 1;
- c = 0;
- }
- }
- }
- else if sxt[2]<sxt[0]
- {
- if sxt[1]=sxt[2]
- {
- if syt[1] < syt[2]
- {
- a = 1;
- b = 2;
- c = 0;
- }
- else
- {
- a = 2;
- b = 1;
- c = 0;
- }
- }
- }
- else if sxt[0]<sxt[1]
- {
- if sxt[1]=sxt[2]
- {
- if syt[1] < syt[2]
- {
- a = 0;
- b = 2;
- c = 1;
- }
- else
- {
- a = 0;
- b = 1;
- c = 2;
- }
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if (a != 0 or b != 0 or c != 0) and drawn = false
- {
- m = sxt[a];
- n = syt[a];
- tempz = vertex_z[count+a];
- y1 = n//v3.x; the main helper
- y2 = n+ 0.5 //v3.x + 0.5f; the other helper
- /* get the change of color components along edge (v3,v1) */
- //v3v1Diff = (v3.y - v1.y);
- //colorSlopeBlue1 = (a.getBlue() - c1.getBlue()) / v3v1Diff;
- //colorSlopeRed1 = (a.getRed() - c1.getRed()) / v3v1Diff;
- //colorSlopeGreen1 = (a.getGreen() - c1.getGreen()) / v3v1Diff;
- /* get the change of color components along edge (v3,v2) */
- //v3v2Diff = (v3.y - v2.y);
- //colorSlopeBlue2 = (a.getBlue() - c2.getBlue()) / v3v2Diff;
- //colorSlopeRed2 = (a.getRed() - c2.getRed()) / v3v2Diff;
- //colorSlopeGreen2 = (a.getGreen() - c2.getGreen()) / v3v2Diff;
- /* set starting values */
- /*
- cBlue1 = a.getBlue();
- cRed1 = a.getRed();
- cGreen1 = a.getGreen();
- cBlue2 = a.getBlue();
- cRed2 = a.getRed();
- cGreen2 = a.getGreen();
- */
- z1 = tempz;
- z2 = tempz;
- if sxt[a] = sxt[b]
- {
- aBC = (syt[b] - syt[c] )/(sxt[b] - sxt[c]);
- aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
- BCDiff = sxt[c] - sxt[b];
- ACDiff = sxt[c] - sxt[a];
- y2 = syt[b];
- zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
- zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
- repeat(sxt[c] - sxt[a])
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y2)-round(y1))
- {
- if n < view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[m,n] < tempz
- {
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n += 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- n = round(y1);
- y2 += aBC;
- z2 -= zBC;
- m += 1;
- }//loop until last point is reached
- }
- else
- {
- //pre calculating slopes for interpolation
- aAB = (syt[a] - syt[b] )/(sxt[a] - sxt[b]) ;
- aAC = (syt[c] - syt[a] )/(sxt[c] - sxt[a]);
- ABDiff = sxt[b] - sxt[a];
- ACDiff = sxt[c] - sxt[a];
- zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff;
- zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
- repeat(sxt[c] - sxt[a])
- {
- if m < view_wport
- {
- if m >= 0
- {
- repeat(round(y2)-round(y1))
- {
- if n < view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[m,n] < tempz
- {
- //write to z-buffer
- global.Zbuffer[m,n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- t = (n - y1) / (y2 - y1);
- tempz = (1-t)* z1 + t * z2;
- n += 1;
- }
- }
- }
- else
- break;
- y1 += aAC;
- z1 -= zAC;
- n = round(y1);
- y2 += aAB;
- z2 -= zAB;
- m += 1;
- }//loop until last point is reached
- }
- }//if sxt[2]=sxt[1]and sxt[1]=sxt[0] and sxt[0] >= 0 and sxt[0] < view_wport///////////////////////////////////////////////////
- else if drawn = false//the last and most bull-shit draw
- {
- m = sxt[0]
- if syt[0] > syt[1] and syt[1] > syt[2]
- {
- a = 2;
- b = 1;
- c = 0;
- }
- else if syt[0] > syt[2] and syt[2] > syt[1]
- {
- a = 1;
- b = 2;
- c = 0;
- }
- else if syt[1] > syt[0] and syt[0] > syt[2]
- {
- a = 2;
- b = 0;
- c = 1;
- }
- else if syt[1] > syt[2] and syt[2] > syt[0]
- {
- a = 0;
- b = 2;
- c = 1;
- }
- else if syt[2] > syt[0] and syt[0] > syt[1]
- {
- a = 1;
- b = 0;
- c = 2;
- }
- else if syt[2] > syt[1] and syt[1] > syt[0]
- {
- a = 0;
- b = 1;
- c = 2;
- }
- tempz = vertex_z[count+a];
- n = syt[a];
- if round(vertex_z[count+a] - vertex_z[count+c]) != 0
- {
- 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]))
- {
- ABDiff = syt[b] - syt[a];
- BCDiff = syt[c] - syt[b];
- zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
- zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
- repeat(ABDiff)
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < 1/tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = 1/tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- tempz -= zAB
- }
- repeat(BCDiff)
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < 1/tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = 1/tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- tempz -= zBC
- }
- }
- else
- {
- ACDiff = syt[c] - syt[a];
- if vertex_z[count+c] > vertex_z[count+a]
- zAC = (vertex_z[count+c] - vertex_z[count+a])/ACDiff
- else
- zAC = (vertex_z[count+a] - vertex_z[count+c])/ACDiff
- repeat(ACDiff)
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- tempz -= zAC
- }
- }
- }
- else if vertex_z[a] < vertex_z[b]
- {
- ABDiff = syt[b] - syt[a];
- BCDiff = syt[c] - syt[b];
- if vertex_z[count+c] > vertex_z[count+a]
- zAB = (vertex_z[count+b] - vertex_z[count+a])/ABDiff
- else
- zAB = (vertex_z[count+a] - vertex_z[count+b])/ABDiff
- if vertex_z[count+c] > vertex_z[count+b]
- zBC = (vertex_z[count+c] - vertex_z[count+b])/BCDiff
- else
- zBC = (vertex_z[count+b] - vertex_z[count+c])/BCDiff
- repeat(ABDiff)
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < 1/tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = 1/tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- tempz -= zAB
- }
- repeat(BCDiff)
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < 1/tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = 1/tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- tempz -= zBC
- }
- }
- else
- {
- repeat(syt[c]-syt[a])
- {
- if n <= view_hport
- {
- if n >= 0
- {
- if global.Zbuffer[sxt[c],n] < tempz
- {
- //write to z-buffer
- global.Zbuffer[sxt[c],n] = tempz
- //draw pixel
- scr_render();
- }
- }
- }
- else
- break;
- n += 1;
- }
- }
- }
- //all drawing end here.
- //some variables are cleared and the loop continues
- count += 3;
- draw_set_alpha(1);
- a = 0;
- b = 0;
- c = 0;
- drawn = false;
- }
- //once all vertices are done, stop drawing on this surface and go to the draw output
- surface_reset_target();
Add Comment
Please, Sign In to add comment