X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fsgp.cpp;h=cc87671d0c45388327cba801bc1c69b2a0cce518;hp=e3241a8e8e3dc129e057ae6e42d649360ef00a24;hb=37ccf79b1044c04db41f5cf924f63c75be1c2366;hpb=bf7295a63667dcca309389ee6dd5328a3a25f22b diff --git a/libctgraphics/sgp.cpp b/libctgraphics/sgp.cpp index e3241a8..cc87671 100644 --- a/libctgraphics/sgp.cpp +++ b/libctgraphics/sgp.cpp @@ -1,28 +1,13 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sgp.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $ -** $Log: sgp.cpp,v $ -** Revision 1.1 2000/06/19 18:05:03 kevin -** initial cvs import -** -** Revision 1.1 2000/06/13 16:20:31 kevin -** finished c++ conversions -** -** Revision 1.4 2000/05/24 22:49:01 kevin -** Updated SGP: first function X-windows version -** -** Revision 1.3 2000/05/11 14:07:23 kevin -** Fixed compilation warnings +** FILE IDENTIFICATION ** -** Revision 1.2 2000/05/08 20:08:15 kevin -** *** empty log message *** -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release +** Name: sgp.c Simple Graphics Package +** Programmer: Kevin Rosenberg ** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg ** +** $Id: sgp.cpp,v 1.3 2000/06/19 19:16:17 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 @@ -38,19 +23,12 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/*----------------------------------------------------------------------------- - * FILE IDENTIFICATION - * - * Name: sgp.c Simple Graphics Package - * Programmer: Kevin Rosenberg - * - *---------------------------------------------------------------------------*/ - -#include "stdio.h" -#include "kstddef.h" -#include "math.h" -#include "kmath.h" +#include +#include +#include "ctsupport.h" #include "sgp.h" + + static SGP_ID _sgp2_cwin = NULL; extern CHARSPEC cspec; @@ -470,6 +448,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 */ /*----------------------------------------------------------------------*/