]> icculus.org git repositories - btb/d2x.git/blob - 2d/disc.c
improved automake config. make dist, VPATH builds, ...
[btb/d2x.git] / 2d / disc.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 #include <conf.h>
15 #include "u_mem.h"
16
17 #include "gr.h"
18 #include "grdef.h"
19
20 int gr_disk(fix xc1,fix yc1,fix r1)
21 {
22         int p,x, y, xc, yc, r;
23
24         r = f2i(r1);
25         xc = f2i(xc1);
26         yc = f2i(yc1);
27         p=3-(r*2);
28         x=0;
29         y=r;
30
31         // Big clip
32         if ( (xc+r) < 0 ) return 1;
33         if ( (xc-r) > GWIDTH ) return 1;
34         if ( (yc+r) < 0 ) return 1;
35         if ( (yc-r) > GHEIGHT ) return 1;
36
37         while(x<y)
38         {
39                 // Draw the first octant
40                 gr_scanline( xc-y, xc+y, yc-x );
41                 gr_scanline( xc-y, xc+y, yc+x );
42
43                 if (p<0) 
44                         p=p+(x<<2)+6;
45                 else    {
46                         // Draw the second octant
47                         gr_scanline( xc-x, xc+x, yc-y );
48                         gr_scanline( xc-x, xc+x, yc+y );
49                         p=p+((x-y)<<2)+10;
50                         y--;
51                 }
52                 x++;
53         }
54         if(x==y)        {
55                 gr_scanline( xc-x, xc+x, yc-y );
56                 gr_scanline( xc-x, xc+x, yc+y );
57         }
58         return 0;
59 }
60
61 int gr_udisk(fix xc1,fix yc1,fix r1)
62 {
63         int p,x, y, xc, yc, r;
64
65         r = f2i(r1);
66         xc = f2i(xc1);
67         yc = f2i(yc1);
68         p=3-(r*2);
69         x=0;
70         y=r;
71
72         while(x<y)
73         {
74                 // Draw the first octant
75                 gr_uscanline( xc-y, xc+y, yc-x );
76                 gr_uscanline( xc-y, xc+y, yc+x );
77
78                 if (p<0) 
79                         p=p+(x<<2)+6;
80                 else    {
81                         // Draw the second octant
82                         gr_uscanline( xc-x, xc+x, yc-y );
83                         gr_uscanline( xc-x, xc+x, yc+y );
84                         p=p+((x-y)<<2)+10;
85                         y--;
86                 }
87                 x++;
88         }
89         if(x==y)        {
90                 gr_uscanline( xc-x, xc+x, yc-y );
91                 gr_uscanline( xc-x, xc+x, yc+y );
92         }
93         return 0;
94 }
95