]> icculus.org git repositories - btb/d2x.git/blob - 2d/circle.c
fix NASMFLAGS bug
[btb/d2x.git] / 2d / circle.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #ifdef RCS
19 static char rcsid[] = "$Id: circle.c,v 1.2 2001-01-31 15:17:47 bradleyb Exp $";
20 #endif
21
22 #include "u_mem.h"
23
24 #include "gr.h"
25 #include "grdef.h"
26
27 #ifndef OGL
28
29 int gr_circle(fix xc1,fix yc1,fix r1)
30 {
31         int p,x, y, xc, yc, r;
32
33         r = f2i(r1);
34         xc = f2i(xc1);
35         yc = f2i(yc1);
36         p=3-(r*2);
37         x=0;
38         y=r;
39
40         // Big clip
41         if ( (xc+r) < 0 ) return 1;
42         if ( (xc-r) > GWIDTH ) return 1;
43         if ( (yc+r) < 0 ) return 1;
44         if ( (yc-r) > GHEIGHT ) return 1;
45
46         while(x<y)
47         {
48                 // Draw the first octant
49                 gr_pixel( xc-y, yc-x );
50                 gr_pixel( xc+y, yc-x );
51                 gr_pixel( xc-y, yc+x );
52                 gr_pixel( xc+y, yc+x );
53
54                 if (p<0) 
55                         p=p+(x<<2)+6;
56                 else    {
57                         // Draw the second octant
58                         gr_pixel( xc-x, yc-y );
59                         gr_pixel( xc+x, yc-y );
60                         gr_pixel( xc-x, yc+y );
61                         gr_pixel( xc+x, yc+y );
62                         p=p+((x-y)<<2)+10;
63                         y--;
64                 }
65                 x++;
66         }
67         if(x==y)        {
68                 gr_pixel( xc-x, yc-y );
69                 gr_pixel( xc+x, yc-y );
70                 gr_pixel( xc-x, yc+y );
71                 gr_pixel( xc+x, yc+y );
72         }
73         return 0;
74 }
75
76 int gr_ucircle(fix xc1,fix yc1,fix r1)
77 {
78         int p,x, y, xc, yc, r;
79
80         r = f2i(r1);
81         xc = f2i(xc1);
82         yc = f2i(yc1);
83         p=3-(r*2);
84         x=0;
85         y=r;
86
87         while(x<y)
88         {
89                 // Draw the first octant
90                 gr_upixel( xc-y, yc-x );
91                 gr_upixel( xc+y, yc-x );
92                 gr_upixel( xc-y, yc+x );
93                 gr_upixel( xc+y, yc+x );
94
95                 if (p<0) 
96                         p=p+(x<<2)+6;
97                 else    {
98                         // Draw the second octant
99                         gr_upixel( xc-x, yc-y );
100                         gr_upixel( xc+x, yc-y );
101                         gr_upixel( xc-x, yc+y );
102                         gr_upixel( xc+x, yc+y );
103                         p=p+((x-y)<<2)+10;
104                         y--;
105                 }
106                 x++;
107         }
108         if(x==y)        {
109                 gr_upixel( xc-x, yc-y );
110                 gr_upixel( xc+x, yc-y );
111                 gr_upixel( xc-x, yc+y );
112                 gr_upixel( xc+x, yc+y );
113         }
114         return 0;
115 }
116
117 #endif //!OGL