From 221b7cae0092ccb5adc1e9fab6cbe52631ee020b Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 21 Oct 2008 13:56:28 +0000 Subject: [PATCH] ok, fixed line drawing. The error in previous commit was my fault, after all :) git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@295 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- graph.c | 13 +++++++------ operatio.c | 10 ++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/graph.c b/graph.c index effa2839..e1fe46bc 100644 --- a/graph.c +++ b/graph.c @@ -4470,35 +4470,36 @@ void Rectifier_coordonnees_a_45_degres(short AX, short AY, short* BX, short* BY) { int dx, dy; - DEBUG("ax",AX); dx = (*BX)-AX; dy = AY- *BY; // On prend l'opposée car à l'écran les Y sont positifs en bas, et en maths, positifs en haut if (dx==0) return; // On est en lockx et de toutes façons le X n'a pas bougé, on sort tout de suite pour éviter une méchante division par 0 - float tan = dy/dx; + float tan = (float)dy/(float)dx; if (tan <= 0.4142 && tan >= -0.4142) { // Cas 1 : Lock Y *BY = AY; - DEBUG("horiz",dx); } else if ( tan > 0.4142 && tan < 2.4142) { // Cas 2 : dy=dx - DEBUG("PLOP",dx); + int nBY = AY - dx; + *BY = (*BY + nBY)/2; + *BX = AX + AY - *BY; } else if (tan < -0.4142 && tan >= -2.4142) { // Cas 8 : dy = -dx - DEBUG("PLiP",dx); + int nBY = AY + dx; + *BY = (*BY + nBY)/2; + *BX = AX - AY + *BY; } else { // Cas 3 : Lock X *BX = AX; - DEBUG("vert",dx); } return; diff --git a/operatio.c b/operatio.c index 78994db7..bef95fa8 100644 --- a/operatio.c +++ b/operatio.c @@ -448,16 +448,14 @@ void Ligne_12_5(void) Operation_POP(&Fin_Y); Operation_POP(&Fin_X); - - DEBUG("px ",Pinceau_X); if ((Pinceau_X!=Fin_X) || (Pinceau_Y!=Fin_Y)) { - // On corrige les coordonnées de la ligne si la touche shift est appuyée... - if(SDL_GetModState() & KMOD_SHIFT) - Rectifier_coordonnees_a_45_degres(Debut_X,Debut_Y,&Pinceau_X,&Pinceau_Y); Effacer_curseur(); Operation_POP(&Debut_Y); Operation_POP(&Debut_X); + // On corrige les coordonnées de la ligne si la touche shift est appuyée... + if(SDL_GetModState() & KMOD_SHIFT) + Rectifier_coordonnees_a_45_degres(Debut_X,Debut_Y,&Pinceau_X,&Pinceau_Y); Aff_coords_rel_ou_abs(Debut_X,Debut_Y); @@ -513,7 +511,7 @@ void Ligne_0_5(void) Pixel_figure_Preview (Debut_X,Debut_Y,Lit_pixel_dans_ecran_courant(Debut_X,Debut_Y)); Effacer_ligne_Preview (Debut_X,Debut_Y,Fin_X,Fin_Y); Afficher_pinceau (Debut_X,Debut_Y,Couleur,0); - Tracer_ligne_Definitif(Debut_X,Debut_Y,Pinceau_X,Pinceau_Y,Couleur); + Tracer_ligne_Definitif(Debut_X,Debut_Y,Fin_X,Fin_Y,Couleur); if ( (Config.Coords_rel) && (Menu_visible) ) {