From: Clive Crous (ccrous@shoprite.co.za)
Date: Tue 30 Nov 1999 - 16:17:20 IST
I've never done this in c before so if it doen't compile, i'm sure you'll figure out myy dumb mistake ;-) also, i may have gotten my DEG to RAD & RAD to DEG the wrong way around ;-) i can never remember which is which. ..and (hehehe) bounds checking is NOT completely accurate but this is a quick example so :P~ here goes.... ----------------------------------------- #include <stdlib.h> #include <math.h> #include <vga.h> #include <vgagl.h> #define MAX_X 639 #define MAX_Y 479 int y_min = MAX_Y<<1; int y_max = -(MAX_Y<<1); int x_min[MAX_Y+1]; int x_max[MAX_Y+1]; void putsemipixel(int x, int y) { if ((y<0)||(y>MAX_Y)||(x<0)||(x>MAX_X)) return if (y<y_min) y_min=y; if (y>y_max) y_max=y; if (x<x_min[y]) x_min[y]=x; if (x>x_max[y]) x_max[y]=x; } void putsemiline(int x1, int y1, int x2, int y2) { int temp; int counter; if (y2<y1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; } for (counter=y1;counter<=y2;counter++) putsemipixel(x1+((x2-x1)/(y2-y1+1))*(counter-y1),counter); } void semifill( int x , int y , int r , int st_ang , int en_ang , int colour) { int counter; int curr_x; int angle,orang; int sx,sy,ex,ey; for (counter=0;counter<=MAX_Y;counter++) { x_max[counter] = - (x_min[counter]=(MAX_X<<1)); } for (counter=r;counter>=0;counter--) { /* I'm not sure if you need to convert RAD to DEG with c ???? (180/PI) */ curr_x=r*cos(orang=((180/PI)*asin(counter/r))); angle=orang; if ((angle>=st_ang)&&(angle<=en_ang)) putsemipixel(x+curr_x,y-counter); angle=180-orang; if ((angle>=st_ang)&&(angle<=en_ang)) putsemipixel(x-curr_x,y-counter); angle=180+orang if ((angle>=st_ang)&&(angle<=en_ang)) putsemipixel(x-curr_x,y+counter); angle=360-orang if ((angle>=st_ang)&&(angle<=en_ang)) putsemipixel(x+curr_x,y+counter); } /* once again these might not need RAD to DEG conversions (PI/180) */ sx=cos(st_ang*(PI/180))*r+x; sy=sin(st_ang*(PI/180))*r+y; ex=cos(en_ang*(PI/180))*r+x; ey=sin(en_ang*(PI/180))*r+y; putsemiline(x,y,sx,sy); putsemiline(x,y,ex,ey); for (counter=y_min;counter<=y_max;counter++) { if (x_max[counter]>=x_min[counter]) { gl_hline(x_min[counter], counter, x_max[counter], color); } } } um, yea, that's that hehehe
This archive was generated by hypermail 2.1.4 : Wed 21 Jan 2004 - 22:10:22 IST