Date: Wed, 4 Aug 1993 22:05:07 -0400 From: garym AT argos DOT rose DOT utoronto DOT ca (Gary Lawrence Murphy) To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: DKBTrace djgpp.c module Here 'tis; no guarantees and no restrictions other than, should you improve it, please offer me a copy :-) I'm including a non-functional Makefile to show (1) how Makefiles _should_ be structured ;-) and (2) the libraries &c I had used. (------------------------------------------ Makefile.gcc) # Makefile for DKB Ray Tracing Program by David Buck and Aaron Collins # This file is released to the public domain. # # # MAKE Macros and Such... # #*************************************************************** #* #* GNU/DJP NDMakefile by Gary Lawrence Murphy #* garym AT virtual DOT rose DOT utoronto DOT ca #* #* Doesn't work as it was, so commented out the 'include' #* (how do you do this in NDMAKE?) #* #*************************************************************** # The exact options may depend on your compiler. Feel free to modify # these as required. CC=gcc OBJ = o MACHINE = djgpp.c CFLAGS= -c -O -DMATH_CO LFLAGS = -o dkbtrace -O -lm -lgrx -lpc -lg # Make's implicit rules for making a .o file from a .c file... # .SUFFIXES: .o .p .c DKBSRC = trace.c render.c tokenize.c parse.c \ objects.c spheres.c quadrics.c lighting.c \ prioq.c texture.c matrices.c csg.c dump.c \ colour.c viewpnt.c ray.c planes.c iff.c \ gif.c gifdecod.c triangle.c raw.c targa.c \ quartics.c vect.c $(MACHINE).c DKBOBJS=$(DKBSRC:.c=.o) .c.o : $(CC) $(CFLAGS) $*.c dkbtrace: depend $(DKBOBJS) >copts $(CFLAGS) -o $@ $(DKBOBJS) $(LFLAGS) $(CC) @copts depend: $(DKBSRC) $(CC) $(CFLAGS) -M *.c > depend #include depend (------------------------------------------ djgpp.c) #include #include #include #include "frame.h" #include "dkbproto.h" #include "config.h" #define SetColor(c,r,g,b) GrSetColor((c),(r)<<2,(g)<<2,(b)<<2) struct exception { /* Math Error exception struct format: */ int type; /* - exception type - see below */ char *name; /* - name of function where error occured */ long double arg1; /* - first argument to function */ long double arg2; /* - second argument (if any) to function */ long double retval; /* - value to be returned by function */ }; extern unsigned int Options; /* djgpp.c */ void unix_init_dkb_trace PARAMS ((void )); void pallete_init PARAMS ((void )); void hsv_to_rgb PARAMS ((DBL hue , DBL s , DBL v , unsigned *r , unsigned *g , unsigned *b )); void rgb_to_hsv PARAMS ((unsigned r , unsigned g , unsigned b , DBL *h , DBL *s , DBL *v )); void unix_init_dkb_trace PARAMS ((void)) { } void display_finished () { if (Options & PROMPTEXIT) { printf ("\007\007"); /* long beep */ while(!kbhit()) /* wait for key hit */ ; if (!getchar()) /* get another if ext. scancode */ getchar(); } } int screen_height, screen_width; void display_init (int width, int height) { if (height<=200) GrSetMode(GR_320_200_graphics); else if (height<=480) GrSetMode(GR_width_height_graphics,640,480,256); else GrSetMode(GR_default_graphics); screen_height=height; screen_width=width; pallete_init(); } void pallete_init() /* Fill VGA 256 color palette with colors! */ { register unsigned m; unsigned r, g, b; register DBL hue, sat, val; GrSetColor(0,0,0,0); /* black */ GrSetColor(64,63,63,63); /* white */ GrSetColor(128,31,31,31); /* dark grey */ GrSetColor(192,48,48,48); /* light grey */ for (m=1; m < 64; m++) { sat = 0.5; /* start with the saturation and intensity low */ val = 0.5; hue = 360.0 * ((DBL)(m)) / 64.0; /* normalize to 360 */ hsv_to_rgb (hue, sat, val, &r, &g, &b); SetColor (m, r, g, b); /* set m to rgb value */ sat = 1.0; /* high saturation and half intensity (shades) */ val = 0.50; hue = 360.0 * ((DBL)(m)) / 64.0; /* normalize to 360 */ hsv_to_rgb (hue, sat, val, &r, &g, &b); SetColor (m + 64, r, g, b); /* set m + 64 */ sat = 0.5; /* half saturation and high intensity (pastels) */ val = 1.0; hue = 360.0 * ((DBL)(m)) / 64.0; /* normalize to 360 */ hsv_to_rgb (hue, sat, val, &r, &g, &b); SetColor (m + 128, r, g, b); /* set m + 128 */ sat = 1.0; /* normal full HSV set at full intensity */ val = 1.0; hue = 360.0 * ((DBL)(m)) / 64.0; /* normalize to 360 */ hsv_to_rgb (hue, sat, val, &r, &g, &b); SetColor (m + 192, r, g, b); /* set m + 192 */ } } void display_close () { GrSetMode(GR_default_text); } void display_plot (x, y, Red, Green, Blue) int x, y; char Red, Green, Blue; { register unsigned char color; DBL h, s, v, fx, fy; static int lasty=-1, lastline=-1, lastx=-1; if (!x) /* first pixel on this line? */ { lastx = -1; /* reset cache, make sure we do the 1st one */ lasty = lastline; /* set last line do to prior line */ } if (screen_height > GrMaxY()) /* auto-scale Y */ { fy = (DBL)y / ((DBL)screen_height / (DBL)GrMaxY()); y = (int)fy; /* scale y to svga_height */ if (y <= lasty) /* discard if repeated line */ return; lastline = y; /* save current working line */ } if (screen_width > GrMaxX()) /* auto-scale X */ { fx = (DBL)x / ((DBL)screen_width / (DBL)GrMaxX()); x = (int)fx; /* scale x to svga_width */ if (x <= lastx) /* discard if repeated pixel */ return; lastx = x; /* save most recent pixel done */ } /* Translate RGB value to best of 256 pallete Colors (by HSV?) */ rgb_to_hsv((unsigned)Red,(unsigned)Green,(unsigned)Blue, &h, &s, &v); if (s < 0.20) /* black or white if no saturation of color... */ { if (v < 0.25) color = 0; /* black */ else if (v > 0.8) color = 64; /* white */ else if (v > 0.5) color = 192; /* lite grey */ else color = 128; /* dark grey */ } else { color = (unsigned char) (64.0 * ((DBL)(h)) / 360.0); if (!color) color = 1; /* avoid black, white or grey */ if (color > 63) color = 63; /* avoid same */ if (v > 0.50) color |= 0x80; /* colors 128-255 for high inten. */ if (s > 0.50) /* more than half saturated? */ color |= 0x40; /* color range 64-128 or 192-255 */ } if ( (xtype) { case DOMAIN : printf("DOMAIN error in '%s'\n", e->name); break; case SING : printf("SING error in '%s'\n", e->name); break; case OVERFLOW : printf("OVERFLOW error in '%s'\n", e->name); break; case UNDERFLOW: printf("UNDERFLOW error in '%s'\n", e->name); break; case TLOSS : printf("TLOSS error in '%s'\n", e->name); break; case PLOSS : printf("PLOSS error in '%s'\n", e->name); break; /* case EDOM : printf("EDOM error in '%s'\n", e->name); break; * case ERANGE : printf("ERANGE error in '%s'\n", e->name); break; */ default : printf("Unknown math error in '%s'\n",e->name);break; } } return (1); /* Indicate the math error was corrected... */ } (--------------------------------------------) Gary Lawrence Murphy ---------------- garym AT virtual DOT rose DOT utoronto DOT ca University of Toronto, Industrial Eng Dept fax: (416) 978-3453 4 Taddle Creek Rd, Toronto, Ont M5S 1A4 voice: (416) 978-3776 The true destination is always just here, now ----------------------