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
This commit is contained in:
Adrien Destugues 2009-07-01 19:21:58 +00:00
parent 8b4533f105
commit 19a2892e88
2 changed files with 42 additions and 17 deletions

53
graph.c
View File

@ -1356,42 +1356,65 @@ void Draw_filled_ellipse(short center_x,short center_y,short horizontal_radius,s
* TRACÉ DE LIGNES * * 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) 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; int dx, dy;
float tan; float tan;
dx = (*bx)-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 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; 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; *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; *by = (*by + ay - dx)/2;
*bx = ax + ay - *by; *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; *by = (*by + ay + dx)/2;
*bx = ax - ay + *by; *bx = ax - ay + *by;
} }
else if ( tan < -1.5 && tan >= -3 )
{
// vertical iso to bottom
}
else else
{ {
// Cas 3 : Lock X // vertical (ok)
*bx = ax; *bx = ax;
} }

View File

@ -39,7 +39,8 @@
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #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; Uint32 Airbrush_next_time;
void Start_operation_stack(word new_operation) void Start_operation_stack(word new_operation)
@ -482,7 +483,8 @@ void Line_12_5(void)
// //
// Souris effacée: Non // 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_x;
short start_y; short start_y;