Starting work to sort out corner-based shapes

Need to sleep on it and figure out the math.
This commit is contained in:
Bill Kendrick 2020-08-15 01:25:00 -07:00
parent 1bf15f2d27
commit c89daa1b37

View file

@ -1966,7 +1966,7 @@ static void free_surface_array(SDL_Surface * surface_array[], int count);
/*static void update_shape(int cx, int ox1, int ox2, int cy, int oy1, int oy2, /*static void update_shape(int cx, int ox1, int ox2, int cy, int oy1, int oy2,
int fixed); */ int fixed); */
static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush); static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush);
static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy); static int shape_rotation(int ctr_x, int ctr_y, int ox, int oy);
static int brush_rotation(int ctr_x, int ctr_y, int ox, int oy); static int brush_rotation(int ctr_x, int ctr_y, int ox, int oy);
static int do_save(int tool, int dont_show_success_results); static int do_save(int tool, int dont_show_success_results);
@ -12821,19 +12821,19 @@ static void free_surface_array(SDL_Surface * surface_array[], int count)
* FIXME * FIXME
*/ */
/* Draw a shape! */ /* Draw a shape! */
static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush) static void do_shape(int sx, int sy, int nx, int ny, int rotn, int use_brush)
{ {
int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp, xv, yv, old_brush, step; int side, angle_skip, init_ang, rx, ry, rmax, x1, y1, x2, y2, xp, yp, xv, yv, old_brush, step;
float a1, a2, rotn_rad; float a1, a2, rotn_rad;
int xx, yy; int xx, yy, offx, offy;
/* Determine radius/shape of the shape to draw: */ /* Determine radius/shape of the shape to draw: */
old_brush = 0; old_brush = 0;
rx = abs(ox - cx); rx = abs(nx - sx);
ry = abs(oy - cy); ry = abs(ny - sy);
/* If the shape has a 1:1 ("locked") aspect ratio, use the larger radius: */ /* If the shape has a 1:1 ("locked") aspect ratio, use the larger radius: */
@ -12884,6 +12884,16 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
} }
/* Where is the object? */
if (shape_mode == SHAPEMODE_CENTER) {
offx = 0;
offy = 0;
} else {
/* FIXME: This needs help! */
offx = (nx - sx) / 2;
offy = (ny - sy) / 2;
}
for (side = 0; side < shape_sides[cur_shape]; side = side + step) for (side = 0; side < shape_sides[cur_shape]; side = side + step)
{ {
a1 = (angle_skip * side + init_ang) * M_PI / 180; a1 = (angle_skip * side + init_ang) * M_PI / 180;
@ -12898,43 +12908,40 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
xv = (int)(cos((a1 + a2) / 2) * rx * shape_valley[cur_shape] / 100); xv = (int)(cos((a1 + a2) / 2) * rx * shape_valley[cur_shape] / 100);
yv = (int)(-sin((a1 + a2) / 2) * ry * shape_valley[cur_shape] / 100); yv = (int)(-sin((a1 + a2) / 2) * ry * shape_valley[cur_shape] / 100);
/* Rotate the line: */ /* Rotate the line: */
if (rotn != 0) if (rotn != 0)
{ {
rotn_rad = rotn * M_PI / 180; rotn_rad = rotn * M_PI / 180;
xp = x1 * cos(rotn_rad) - y1 * sin(rotn_rad); xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad);
yp = x1 * sin(rotn_rad) + y1 * cos(rotn_rad); yp = (x1 + offx) * sin(rotn_rad) + (y1 + offy) * cos(rotn_rad);
x1 = xp; x1 = xp - offx;
y1 = yp; y1 = yp - offy;
xp = x2 * cos(rotn_rad) - y2 * sin(rotn_rad); xp = (x2 + offx) * cos(rotn_rad) - (y2 + offy) * sin(rotn_rad);
yp = x2 * sin(rotn_rad) + y2 * cos(rotn_rad); yp = (x2 + offx) * sin(rotn_rad) + (y2 + offy) * cos(rotn_rad);
x2 = xp; x2 = xp - offx;
y2 = yp; y2 = yp - offy;
xp = xv * cos(rotn_rad) - yv * sin(rotn_rad); xp = (xv + offx) * cos(rotn_rad) - (yv + offy) * sin(rotn_rad);
yp = xv * sin(rotn_rad) + yv * cos(rotn_rad); yp = (xv + offx) * sin(rotn_rad) + (yv + offy) * cos(rotn_rad);
xv = xp; xv = xp - offx;
yv = yp; yv = yp - offy;
} }
/* Center the line around the center of the shape: */ /* Center the line around the center of the shape: */
x1 = x1 + cx; x1 = x1 + sx + offx;
y1 = y1 + cy; y1 = y1 + sy + offy;
x2 = x2 + cx; x2 = x2 + sx + offx;
y2 = y2 + cy; y2 = y2 + sy + offy;
xv = xv + cx; xv = xv + sx + offx;
yv = yv + cy; yv = yv + sy + offy;
/* Draw: */ /* Draw: */
@ -13008,34 +13015,34 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
{ {
rotn_rad = rotn * M_PI / 180; rotn_rad = rotn * M_PI / 180;
xp = x1 * cos(rotn_rad) - y1 * sin(rotn_rad); xp = (x1 + offx) * cos(rotn_rad) - (y1 + offy) * sin(rotn_rad);
yp = x1 * sin(rotn_rad) + y1 * cos(rotn_rad); yp = (x1 + offx) * sin(rotn_rad) + (y1 + offy) * cos(rotn_rad);
x1 = xp; x1 = xp - offx;
y1 = yp; y1 = yp - offy;
xp = x2 * cos(rotn_rad) - y2 * sin(rotn_rad); xp = (x2 + offx) * cos(rotn_rad) - (y2 + offy) * sin(rotn_rad);
yp = x2 * sin(rotn_rad) + y2 * cos(rotn_rad); yp = (x2 + offx) * sin(rotn_rad) + (y2 + offy) * cos(rotn_rad);
x2 = xp; x2 = xp - offx;
y2 = yp; y2 = yp - offy;
xp = xv * cos(rotn_rad) - yv * sin(rotn_rad); xp = (xv + offx) * cos(rotn_rad) - (yv + offy) * sin(rotn_rad);
yp = xv * sin(rotn_rad) + yv * cos(rotn_rad); yp = (xv + offx) * sin(rotn_rad) + (yv + offy) * cos(rotn_rad);
xv = xp; xv = xp - offx;
yv = yp; yv = yp - offy;
} }
/* Center the line around the center of the shape: */ /* Center the line around the center of the shape: */
x1 = x1 + cx; x1 = x1 + sx + offx;
y1 = y1 + cy; y1 = y1 + sy + offy;
x2 = x2 + cx; x2 = x2 + sx + offx;
y2 = y2 + cy; y2 = y2 + sy + offy;
xv = xv + cx; xv = xv + sx + offx;
yv = yv + cy; yv = yv + sy + offy;
/* Draw: */ /* Draw: */
@ -13064,7 +13071,7 @@ static void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush)
else else
rmax = abs(ry) + 20; rmax = abs(ry) + 20;
update_canvas(cx - rmax, cy - rmax, cx + rmax, cy + rmax); update_canvas(sx - rmax + offx, sy - rmax + offy, sx + rmax + offx, sy + rmax + offy);
} }