X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=libctgraphics%2Fsgp.cpp;h=8a5400fc00e620ffbbc802a558a1ed2dd47afe98;hb=286d655a25df2668bd65ad365676c6ecc94415a1;hp=55d3c0e151188e3bc26b0f66b3536be8fe28a003;hpb=12e2c29153a0f55ac23bdeec06b404638672985b;p=ctsim.git diff --git a/libctgraphics/sgp.cpp b/libctgraphics/sgp.cpp index 55d3c0e..8a5400f 100644 --- a/libctgraphics/sgp.cpp +++ b/libctgraphics/sgp.cpp @@ -7,7 +7,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: sgp.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $ +** $Id: sgp.cpp,v 1.4 2000/07/11 10:32:44 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -84,12 +84,13 @@ void sgp2_close (SGP_ID gid) { #if HAVE_G2_H + if (gid) g2_close (gid->g2_id); #endif - if (gid == _sgp2_cwin) - _sgp2_cwin = NULL; + if (gid == _sgp2_cwin) + _sgp2_cwin = NULL; - delete gid; + delete gid; } void @@ -448,6 +449,83 @@ sgp2_point_rel (double x, double y) } +/* NAME + * sgp2_draw_rect Draw box in graphics mode + * + * SYNOPSIS + * drawbox (xmin, ymin, xmax, ymax) + * double xmin, ymin Lower left corner of box + * double xmax, ymax Upper left corner of box + * + * NOTES + * This routine leaves the current position of graphic cursor at lower + * left corner of box. + */ + +void +sgp2_draw_rect(double xmin, double ymin, double xmax, double ymax) +{ + sgp2_move_abs (xmin, ymin); + sgp2_line_abs (xmax, ymin); + sgp2_line_abs (xmax, ymax); + sgp2_line_abs (xmin, ymax); + sgp2_line_abs (xmin, ymin); +} + +/* FUNCTION + * sgp2_circle - draw circle of radius r at current center + */ + +void +sgp2_draw_circle (const double r) +{ + sgp2_draw_arc (0.0, 7.0, r); +} + +/*==============================================================*/ +/* draw arc around current center. pass angles and radius */ +/*==============================================================*/ + +void +sgp2_draw_arc (double start, double stop, const double r) +{ + double c, s, theta, angle; + float x, y, xp, yp; + + if ((stop-start) > 2 * PI) + stop = start + 2 * PI; + if ((start-stop) > 2 * PI) + stop = start + 2 * PI; + while (start >= stop) + stop += 2*PI; + + x = r * cos ((double) start); + y = r * sin ((double) start); + sgp2_move_rel (x, y); /* move from center to start of arc */ + + theta = 5 * PI / 180; + c = cos(theta); + s = sin(theta); + + for (angle = start; angle < stop - theta; angle += theta) { + xp = c * x - s * y; + yp = s * x + c * y; + sgp2_line_rel (xp - x, yp - y); + x = xp; y = yp; + } + + c = cos (stop - angle); + s = sin (stop - angle); + xp = c * x - s * y; + yp = s * x + c * y; + sgp2_line_rel (xp - x, yp - y); + + x = r * cos ((double) stop); + y = r * sin ((double) stop); + sgp2_move_rel (-x, -y); /* move back to center of circle */ +} + + /*----------------------------------------------------------------------*/ /* Current Transformation Matrix Routine */ /*----------------------------------------------------------------------*/