From 1cce870987e0fcfc63e729fca7998eaafe1b6fda Mon Sep 17 00:00:00 2001 From: Milang Date: Fri, 16 Aug 2019 17:35:32 +0200 Subject: [PATCH] test experimental perspective correction feature --- src/FxEngine/face.c | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/src/FxEngine/face.c b/src/FxEngine/face.c index ea46577..9b32856 100644 --- a/src/FxEngine/face.c +++ b/src/FxEngine/face.c @@ -95,14 +95,6 @@ void FE_draw_face(FE_face const * face) const int fact_1=(10000*yAC)/diviseur_commun, fact_2=(10000*xAC)/diviseur_commun; const int fact_3=(10000*xAB)/diviseur_commun, fact_4=(10000*yAB)/diviseur_commun; - const int r_xAB=face->s2->rotated.x-face->s1->rotated.x, r_yAB=face->s2->rotated.y-face->s1->rotated.y; - const int r_xAC=face->s3->rotated.x-face->s1->rotated.x, r_yAC=face->s3->rotated.y-face->s1->rotated.y; - - const int r_diviseur_commun=(r_xAB*r_yAC-r_yAB*r_xAC); - const int r_fact_1=(10000*r_yAC)/r_diviseur_commun, r_fact_2=(10000*r_xAC)/r_diviseur_commun; - const int r_fact_3=(10000*r_xAB)/r_diviseur_commun, r_fact_4=(10000*r_yAB)/r_diviseur_commun; - - for (int y=ymin; y<=ymax; y++) { // détermination du xmin et du xmax de la ligne @@ -115,37 +107,20 @@ void FE_draw_face(FE_face const * face) for (int x=txmin; x<=txmax; x++) { - int xcalc,ycalc,vx,vy,vz,z,rx,ry; - // initialisation des variables temporaires au calcul de vx, vy - xcalc=x-face->s1->translated.x; - ycalc=y-face->s1->translated.y; - - // calcul de vx,vy, et vz sans la déformation + double vx, vy, z; + // calcul de vx, vy vx=(xcalc*fact_1-ycalc*fact_2); // 0 s1->translated.z + (vx*zAB+vy*zAC)/10000; + vx/=10000; + vy/=10000; - vz=face->s1->translated.z + (vx*zAB+vy*zAC)/10000; - - - // transformation - rx=x-63; // on determine le centre de l'écran comme le point X(63,31) - ry=y-31; - rx*=vz; // on annule la perspective - ry*=vz; - - // deuxieme processus de calcul (avec déformation) - xcalc=rx-face->s1->rotated.x; - ycalc=ry-face->s1->rotated.y; - - vx=(xcalc*r_fact_1-ycalc*r_fact_2); - vy=(ycalc*r_fact_3-xcalc*r_fact_4); - - - z=face->s1->translated.z + (vx*zAB+vy*zAC)/10000; - + vx /= (double)face->s2->translated.z / ((1-vx) / face->s1->translated.z + vx / (double)face->s2->translated.z); + vy /= (double)face->s3->translated.z / ((1-vy) / face->s1->translated.z + vy / (double)face->s3->translated.z); + // Affichage du point if (FE_zbuffer_set_dist(x,y,z)) - dpixel(x, y, 3*FE_get_pixel(face->texturenum,vx/1250,vy/1250)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7 + dpixel(x, y, 3*FE_get_pixel(face->texturenum, 8*vx, 8*vy)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7 } }