[net.sources] basic ray tracing: part 1

fritzz@net1.UCSD.EDU (Friedrich Knauss) (07/26/86)

/*****************************************************************
 *                                                               *
 *                      basic ray tracing:                       *
 *    spheres and a floor (reflection, refraction and diffuse)   *
 *                       (black and white)                       *
 *                  programmer: friedrich knauss                 *
 *                       7-4-86 to 7-21-86                       *
 *                                                               *
 *****************************************************************/

#include <stdio.h>
#include <math.h>
#include "rtd.h"

/* these definitions describe a window in the x-y plane
   that the whole thing is viewd through. */
#define XMIN 100.0
#define XMAX 250.0
#define YMIN 30.0
#define YMAX 180.0
#define INC  0.333333333333


FILE * fp;
struct ball bl[] = {
#include "bdata.i"
};
int     level,
        nob;
struct sphere   ls;

main () {			/* piss off, no args */
    static float    xco,
                    yco;
    struct ray  rr;
    struct vector   vp;
    float   x,
            y,
            z;
    int     i;

    fp = fopen ("data.dis", "w");
/* define viewpoint */
    mv (195.0, 140.0, -200.0, &vp);
/* define light source (rad defines how fuzzy the shadows will be) */
    mv (50.0, 300.0, 0.0, &(ls.cent));
    ls.rad = 40;
/* how many balls do we have */
    nob = sizeof (bl) / sizeof (struct ball);
    for (i = 0; i < nob; i++)
	bl[i].ior = sqrt (bl[i].ior * bl[i].ior - 1.0);

    for (xco = XMIN; xco < XMAX; xco += INC) {
	for (yco = YMIN; yco < YMAX; yco += INC) {
	    mv (xco, yco, 0.0, &(rr.org));
/* define the ray through a pixel and find out the value for that pixel */
	    sv (&(rr.dir), &(rr.org), &vp);
	    fprintf (fp, "%c", shade (&rr));
	}
/* put some info out so we can guess how long this all takes. */
	update (xco, XMIN, XMAX);
    }
}