From 19a2892e88da0d47badcc4af03efdede241a8c0d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 1 Jul 2009 19:21:58 +0000 Subject: [PATCH] I extended the line clamping to do iso pixelart. However I only managed to find the equation for the 3 others. Maybe someone is better at geometry. I let the unequationed lines move free when you press shift. The limit between each spot can also be adjusted. Is someone better than me at math around here ? git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@894 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- graph.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- operatio.c | 6 ++++-- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/graph.c b/graph.c index 9a9d8fac..6d0a424c 100644 --- a/graph.c +++ b/graph.c @@ -1356,42 +1356,65 @@ void Draw_filled_ellipse(short center_x,short center_y,short horizontal_radius,s * TRACÉ DE LIGNES * ******************/ +/// Alters bx and by so the (AX,AY)-(BX,BY) segment becomes either horizontal, +/// vertical, 45degrees, or isometrical for pixelart (ie 2:1 ratio) void Clamp_coordinates_45_degrees(short ax, short ay, short* bx, short* by) -// Modifie bx et by pour que la ligne AXAY - BXBY soit -// - une droite horizontale -// - une droite verticale -// - une droite avec une pente de 45 degrés { int dx, dy; float tan; 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 + 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 + 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 tan = (float)dy/(float)dx; - if (tan <= 0.4142 && tan >= -0.4142) + // These equation look a bit more complex than they should, but that's + // because we have to balance the line length to make it end near the + // cursor + if (tan <= 0.25 && tan >= -0.25) { - // Cas 1 : Lock Y + // horizontal (OK) *by = ay; } - else if ( tan > 0.4142 && tan < 2.4142) + else if ( tan > 0.25 && tan < 0.75) { - // Cas 2 : dy=dx + // dx=2dy, iso (ok) + *bx = (2* *bx + ax + 2*dy)/3; + *by = ay - (*bx-ax)/2; + } + else if ( tan >=0.75 && tan <= 1.5 ) + { + // dy=-dx, diagonal upright (ok) *by = (*by + ay - dx)/2; *bx = ax + ay - *by; - } - else if (tan < -0.4142 && tan >= -2.4142) + } + else if ( tan > 1.5 && tan <= 3 ) + { + // "vertical iso" + } + else if (tan < -0.25 && tan >= -0.75) { - // Cas 8 : dy = -dx + // iso to bottom + } + else if ( tan <-0.75 && tan > -1.5 ) + { + // dy=dx, downright diagonal (ok) *by = (*by + ay + dx)/2; *bx = ax - ay + *by; - } + } + else if ( tan < -1.5 && tan >= -3 ) + { + // vertical iso to bottom + } else { - // Cas 3 : Lock X + // vertical (ok) *bx = ax; } diff --git a/operatio.c b/operatio.c index a1454ef4..863d58c0 100644 --- a/operatio.c +++ b/operatio.c @@ -39,7 +39,8 @@ #define M_PI 3.14159265358979323846 #endif -/// Time (in SDL ticks) when the next airbrush drawing should be done. Also used for discontinuous freehand drawing. +/// Time (in SDL ticks) when the next airbrush drawing should be done. Also used +/// for discontinuous freehand drawing. Uint32 Airbrush_next_time; void Start_operation_stack(word new_operation) @@ -482,7 +483,8 @@ void Line_12_5(void) // // Souris effacée: Non -// Poursuite du tracé d'une ligne (déplacement de la souris en gardant le curseur appuyé) +// Poursuite du tracé d'une ligne (déplacement de la souris en gardant le +// curseur appuyé) { short start_x; short start_y;