From 9d0c73b5bee2e4b029e14c4f8e7c1c23f166ae8c Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Wed, 15 Jul 2009 20:11:07 +0000 Subject: [PATCH] =?UTF-8?q?Tweaked=20the=20line=20clamping=20algorithm=20(?= =?UTF-8?q?Issue=20186):=20Multiples=20of=2045=C2=B0=20use=20orthogonal=20?= =?UTF-8?q?projection=20(again),=20ISO=20lines=20are=20now=20constrained?= =?UTF-8?q?=20to=20exact=202:1=20lines=20and=20their=20length=20is=20proje?= =?UTF-8?q?cted=20on=20most=20significant=20axis,=20horizontal=20or=20vert?= =?UTF-8?q?ical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@922 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- gfx2.cfg | Bin 10133 -> 10133 bytes graph.c | 165 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 116 insertions(+), 49 deletions(-) diff --git a/gfx2.cfg b/gfx2.cfg index a02e005c348bed9e79b9b9e14dc8e34e45e0c912..eeea8c6a91e496bbeb2557ae8d8c8446d4daa94a 100644 GIT binary patch delta 16 VcmbR0Kh=LjuR4bVg98Hy001q=1GNAE delta 16 VcmbR0Kh=LjuQ~?@0|x^L001ht14RG; diff --git a/graph.c b/graph.c index 28200734..b01133ad 100644 --- a/graph.c +++ b/graph.c @@ -1360,61 +1360,128 @@ void Draw_filled_ellipse(short center_x,short center_y,short horizontal_radius,s /// vertical, 45degrees, or isometrical for pixelart (ie 2:1 ratio) void Clamp_coordinates_regular_angle(short ax, short ay, short* bx, short* by) { - int dx, dy; - float angle; - float length; + int dx, dy; + float angle; - dx = *bx-ax; - dy = *by-ay; + dx = *bx-ax; + dy = *by-ay; // No mouse move: no need to clamp anything - if (dx==0 || dy == 0) return; + if (dx==0 || dy == 0) return; - angle = atan2(dx, dy); + // Determine angle (heading) + angle = atan2(dx, dy); - // Horizontal < 15/16 - if (angle < M_PI*(-15.0/16.0) || angle > M_PI*(15.0/16.0)) - angle = M_PI*(16.0/16.0); - // 15/16 < Iso < 13/16 - else if (angle < M_PI*(-13.0/16.0)) - angle = -2.677945045; - // 13/16 < 45deg (3pi/4) < 11/16 - else if (angle < M_PI*(-11.0/16.0)) - angle = M_PI*(-12.0/16.0); - // 11/16 < "vertical iso" < 9/19 - else if (angle < M_PI*(-9.0/16.0)) - angle = -2.034443936; - // 9/16 < vertical < 7/16 - else if (angle < M_PI*(-7.0/16.0)) - angle = M_PI*(-8.0/16.0); - else if (angle < M_PI*(-5.0/16.0)) - angle = -1.107148718; - else if (angle < M_PI*(-3.0/16.0)) - angle = M_PI*(-4.0/16.0); - else if (angle < M_PI*(-1.0/16.0)) - angle = -0.463647609; - else if (angle < M_PI*(1.0/16.0)) - angle = M_PI*(0.0/16.0); - else if (angle < M_PI*(3.0/16.0)) - angle = 0.463647609; - else if (angle < M_PI*(5.0/16.0)) - angle = M_PI*(4.0/16.0); - else if (angle < M_PI*(7.0/16.0)) - angle = 1.107148718; - else if (angle < M_PI*(9.0/16.0)) - angle = M_PI*(8.0/16.0); - else if (angle < M_PI*(11.0/16.0)) - angle = 2.034443936; - else if (angle < M_PI*(13.0/16.0)) - angle = M_PI*(12.0/16.0); - else //if (angle < M_PI*(15.0/16.0)) - angle = 2.677945045; + // Get absolute values, useful from now on: + //dx=abs(dx); + //dy=abs(dy); + + // Negative Y + if (angle < M_PI*(-15.0/16.0) || angle > M_PI*(15.0/16.0)) + { + *bx=ax; + *by=ay + dy; + } + // Iso close to negative Y + else if (angle < M_PI*(-13.0/16.0)) + { + dy=dy | 1; // Round up to next odd number + *bx=ax + dy/2; + *by=ay + dy; + } + // 45deg + else if (angle < M_PI*(-11.0/16.0)) + { + *by = (*by + ay + dx)/2; + *bx = ax - ay + *by; + } + // Iso close to negative X + else if (angle < M_PI*(-9.0/16.0)) + { + dx=dx | 1; // Round up to next odd number + *bx=ax + dx; + *by=ay + dx/2; + } + // Negative X + else if (angle < M_PI*(-7.0/16.0)) + { + *bx=ax + dx; + *by=ay; + } + // Iso close to negative X + else if (angle < M_PI*(-5.0/16.0)) + { + dx=dx | 1; // Round up to next odd number + *bx=ax + dx; + *by=ay - dx/2; + } + // 45 degrees + else if (angle < M_PI*(-3.0/16.0)) + { + *by = (*by + ay - dx)/2; + *bx = ax + ay - *by; + } + // Iso close to positive Y + else if (angle < M_PI*(-1.0/16.0)) + { + dy=dy | 1; // Round up to next odd number + *bx=ax - dy/2; + *by=ay + dy; + } + // Positive Y + else if (angle < M_PI*(1.0/16.0)) + { + *bx=ax; + *by=ay + dy; + } + // Iso close to positive Y + else if (angle < M_PI*(3.0/16.0)) + { + dy=dy | 1; // Round up to next odd number + *bx=ax + dy/2; + *by=ay + dy; + } + // 45 degrees + else if (angle < M_PI*(5.0/16.0)) + { + *by = (*by + ay + dx)/2; + *bx = ax - ay + *by; + } + // Iso close to positive X + else if (angle < M_PI*(7.0/16.0)) + { + dx=dx | 1; // Round up to next odd number + *bx=ax + dx; + *by=ay + dx/2; + } + // Positive X + else if (angle < M_PI*(9.0/16.0)) + { + *bx=ax + dx; + *by=ay; + } + // Iso close to positive X + else if (angle < M_PI*(11.0/16.0)) + { + dx=dx | 1; // Round up to next odd number + *bx=ax + dx; + *by=ay - dx/2; + } + // 45 degrees + else if (angle < M_PI*(13.0/16.0)) + { + *by = (*by + ay - dx)/2; + *bx = ax + ay - *by; + } + // Iso close to negative Y + else //if (angle < M_PI*(15.0/16.0)) + { + dy=dy | 1; // Round up to next odd number + *bx=ax - dy/2; + *by=ay + dy; + } - length = sqrt((float)(dx)*(float)(dx)+(float)(dy)*(float)(dy)); - *bx=ax + lrintf(sin(angle)*length); - *by=ay + lrintf(cos(angle)*length); - - return; + return; } // -- Tracer général d'une ligne ------------------------------------------