]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/circle.cpp
bunch of cleanup
[taylor/freespace2.git] / src / graphics / circle.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/Circle.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Code to draw circles.
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:17  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:09  root
22  * Initial import.
23  *
24  * 
25  * 2     10/07/98 10:52a Dave
26  * Initial checkin.
27  * 
28  * 1     10/07/98 10:48a Dave
29  * 
30  * 9     3/10/98 4:18p John
31  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
32  * & Glide have popups and print screen.  Took out all >8bpp software
33  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
34  * support Fred.  Made zbuffering key off of functions rather than one
35  * global variable.
36  * 
37  * 8     11/06/97 11:18a John
38  * fixed bug with some scanlines being drawn twice
39  * 
40  * 7     11/26/96 6:50p John
41  * Added some more hicolor primitives.  Made windowed mode run as current
42  * bpp, if bpp is 8,16,or 32.
43  * 
44  * 6     11/26/96 4:30p John
45  * Put in some better quality circle_empty code.
46  * 
47  * 5     11/07/96 6:19p John
48  * Added a bunch of 16bpp primitives so the game sort of runs in 16bpp
49  * mode.
50  * 
51  * 4     10/26/96 1:40p John
52  * Added some now primitives to the 2d library and
53  * cleaned up some old ones.
54  *
55  * $NoKeywords: $
56  */
57
58 #include "2d.h"
59 #include "pixel.h"
60 #include "circle.h"
61
62 // THIS COULD BE OPTIMIZED BY MOVING THE GR_RECT CODE INTO HERE!!!!!!!!
63
64 #define circle_fill(x,y,w) gr_rect((x),(y),(w),1)
65
66 void gr8_circle( int xc, int yc, int d )
67 {
68         int p,x, y, r;
69
70         r = d/2;
71         p=3-d;
72         x=0;
73         y=r;
74
75         // Big clip
76         if ( (xc+r) < gr_screen.clip_left ) return;
77         if ( (xc-r) > gr_screen.clip_right ) return;
78         if ( (yc+r) < gr_screen.clip_top ) return;
79         if ( (yc-r) > gr_screen.clip_bottom ) return;
80
81         while(x<y)      {
82                 // Draw the first octant
83                 circle_fill( xc-y, yc-x, y*2+1 );
84                 if ( x != 0 )   
85                         circle_fill( xc-y, yc+x, y*2+1 );
86
87                 if (p<0) 
88                         p=p+(x<<2)+6;
89                 else    {
90                         // Draw the second octant
91                         circle_fill( xc-x, yc-y, x*2+1 );
92                         if ( y != 0 )   
93                                 circle_fill( xc-x, yc+y, x*2+1 );
94                         p=p+((x-y)<<2)+10;
95                         y--;
96                 }
97                 x++;
98         }
99
100         if(x==y)        {
101                 circle_fill( xc-x, yc-y, x*2+1 );
102                 if ( y != 0 )   
103                         circle_fill( xc-x, yc+y, x*2+1 );
104         }
105
106 }
107