diff options
author | amy <[email protected]> | 2023-05-01 11:09:20 +0000 |
---|---|---|
committer | amy <[email protected]> | 2023-05-01 11:09:20 +0000 |
commit | 5474ce816be91ecbd7472e55cdc4357b8158f5bf (patch) | |
tree | 3478fbf771f9b54027ec010e04db275a79ca9145 /src/point.c | |
parent | 0093cc08458e032b924d680e70a8f115dcbcc927 (diff) |
fixed the uh thingy:(
Diffstat (limited to 'src/point.c')
-rw-r--r-- | src/point.c | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/src/point.c b/src/point.c index 55aff10..672d8b7 100644 --- a/src/point.c +++ b/src/point.c @@ -5,6 +5,8 @@ #include "glfww.h" #include <unistd.h> double NUU = 0.0; +double FL_DIS = 1e-10; +double NaN = 0.0f/0.0f; typedef struct { double x; double y; @@ -408,7 +410,8 @@ void perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ct printf("%f %i\n",trline->at[ii].at[3],trline->at[ii].len); }*/ double ffclen = c_len; - + //printf("---\n"); + //printf("%i\n",trline->len); double lmax_t = -2.0; double lmin_t = 2.0; double lmax2_t = -2.0; @@ -430,22 +433,25 @@ void perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ct } //min_t = (min_t>trline.at[zzi].at[zzi2]?trline.at[zzi].at[zzi2]:min_t); } - //printf("%i\n",zzi); + // printf("%i\n",zzi); free(trline->at[zzi].at); - if(trline->at[zzi].len==0) - continue; - + //printf("lls\n"); + if (trline->at[zzi].len == 0) + continue; if(lmax2_t!=max2_t&&lmin_t!=2.0&&lmax_t!=-2.0){ + //printf("ll\n"); float color = (float)zzi/trline->len; float color2 = 1.0f-((float)zzi/trline->len); double di = pow(lmin_t-max_t,2)+pow(lmin2_t-max2_t,2);//sqrt should be used here double di2 = pow(lmax_t-min_t,2)+pow(lmax2_t-min2_t,2); - double ux1,uy1,ux2,uy2; - if(di>di2){ + double ux1, uy1, ux2, uy2; + int ma_to_mi = 0; + if (di > di2) { ux1 = max_t; uy1 = max2_t; ux2 = lmin_t; uy2 = lmin2_t; + ma_to_mi=1; } else { ux1 = min_t; uy1 = min2_t; @@ -455,23 +461,35 @@ void perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ct //printf("%f %f >> %f %f (f,%f) | %f %f\n",di,di2,ux1,uy1,min_t,ux2,uy2); color2 = 1.0f; //printf("%f\n",color2); - double bb[] = {ux1,ux2}; - double bb2[] = {uy1, uy2}; - point_arr* asd = basier2d(bb,bb2,2,0.1,0.1,0.1); - //y - y1 = m(x - x1) + + + if(ma_to_mi){ + //printf("%f -> %f | %f for %f\n",max_t,lmin_t,diff(max_t,lmin_t)/asd->len,asd->len); + } else { + //printf("%f -> %f | %f for %f\n",min_t,lmax_t,diff(min_t,lmax_t)/asd->len,asd->len); + } + + //y - y1 = m(x - x1) //double a1x = (uy2 - uy1); //double b1y = (ux2 - ux1); //double a1c = (ux2*a1x + uy2*b1y); - //printf("%fx+%fy=%f\n",a1x,b1y,a1c); - double ex = 0.0; - double ey = 0.0; - double dtex = -1.0; - for(int yyu = 0; yyu!=fc_len-1; yyu++){ - double x1 = ux1; - double x2 = ux2; - double y1 = uy1; - double y2 = uy2; - double m1 = (y2-y1)/(x2-x1); + //printf("%fx+%fy=%f\n",a1x,b1y,a1c); + + double x1 = ma_to_mi?max_t:min_t; + double x2 = ma_to_mi?lmin_t:lmax_t; + double y1 = uy1; + double y2 = uy2; + double m1 = (y2-y1)/(x2-x1); + + double bb[] = {x1,x2}; + double bb2[] = {y1, y2}; + point_arr* asd = basier2d(bb,bb2,2,0.1,0.1,0.1); + + int coll = 0; + //printf("-\n"); + //printf("%f -> %f\n",x1,x2); + for(int yyu = 0; yyu!=fc_len-1; yyu++){ + double x3 = pixels[yyu*2]; double x4 = pixels[(yyu+1)*2]; @@ -486,9 +504,12 @@ void perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ct double nsy = m1*nsx+b1; if(!(nsx >= greater(lesser(x1, x2), lesser(x3, x4)) && nsx <= lesser(greater(x1, x2), greater(x3, x4))) - ||(nsx<x1||nsx>x2||nsy<y1||nsy>y2)) + //||(nsx<x1||nsx>x2||nsy<y1||nsy>y2) + ||(diff(nsx,x2)<FL_DIS&&diff(nsy,y2)<FL_DIS) + ||(diff(nsx,x1)<FL_DIS&&diff(nsy,y1)<FL_DIS)) continue; - + //printf("aaa\n"); + /* pixels = realloc(pixels,sizeof *pixels *((c_len+1)*4)); colors = realloc(colors,sizeof *colors *((c_len+1)*5)); pixels[c_len*2] = nsx; @@ -496,18 +517,20 @@ void perspective_proj(GLFWwindow* b,point_arr* c,double ctx,double cty,double ct colors[c_len*3] = 1.0f;//yyu/(fc_len-1); colors[c_len*3+1] = 0.5f;//vvi==3?0.1f:vvi==4?0.5f:1.0f; colors[c_len*3+2] = 1.0f;//-yyu/(fc_len-1); - c_len++; + c_len++;*/ + coll=1; + //printf("aaa\n"); //printf("%f,%f,%f,%f,%f,%f %f,%f,%f,%f,%f,%f, %f %f\n",x1,y1,x2,y2,m1,b1, x3,y3,x4,y4,m2,b2,nsx,nsy); //printf("(%f,%f) -> (%f,%f) :: x:%f,y:%f\n",ux1,uy1,ux2,uy2,nsx,nsy); } - for(int lli = 0; lli!=asd->len&&0; lli++){ + for(int lli = 0; !coll&&lli!=asd->len; lli++){ pixels = realloc(pixels,sizeof *pixels *((c_len+1)*4)); colors = realloc(colors,sizeof *colors *((c_len+1)*5)); double dd = 10; - if(diff(asd->c[lli].at.x,ex)<(float)dd/get_w()&&diff(asd->c[lli].at.y,ey)<(float)dd/get_w()) - break; + //if(diff(asd->c[lli].at.x,ex)<(float)dd/get_w()&&diff(asd->c[lli].at.y,ey)<(float)dd/get_w()) + // break; pixels[c_len*2] = asd->c[lli].at.x; pixels[c_len*2+1] = asd->c[lli].at.y; colors[c_len*3] = color2; |