#include #include "typedefs.h" #include "maindecl.h" #define FAR_AWAY 99.99E+20 void raytrace(int depth, t_3d *pos, t_3d *ray, t_color *color) { int objhit, i; double d, dist; t_3d hit, normal; color->r = color->g = color->b = 0.0; if (depth < 0) { color->r = background.r; color->g = background.g; color->b = background.b; return; } objhit = -1; dist = FAR_AWAY; for (i = 0; i < nobject; i++) { d = (*objint[object[i].objtyp])(pos, ray, &object[i]); if ((d > 0.0) && (d <= dist)) { objhit = i; dist = d; } } if (objhit < 0) { color->r = background.r; color->g = background.g; color->b = background.b; return; } hit.x = pos->x + dist * ray->x; hit.y = pos->y + dist * ray->y; hit.z = pos->z + dist * ray->z; (*objnrm[object[objhit].objtyp]) (&hit, &object[objhit], &normal); shade(&hit, ray, &normal, &object[objhit], color); } int main(int argc, char **argv) { int line_y, pixel_x, depth; t_3d scrnx, scrny, firstray, ray; t_color color; double line[SCREENWIDTH][3]; setup(); viewing(&scrnx, &scrny, &firstray); startpic(outfilename, sizey, sizex); depth = 0; for (line_y = 0; line_y < sizey; line_y++) { for (pixel_x = 0; pixel_x < sizex; pixel_x++) { ray.x = firstray.x + pixel_x * scrnx.x - line_y * scrny.x; ray.y = firstray.y + pixel_x * scrnx.y - line_y * scrny.y; ray.z = firstray.z + pixel_x * scrnx.z - line_y * scrny.z; normalize(&ray); raytrace(0, &eyep, &ray, &color); line[pixel_x][0] = color.r; line[pixel_x][1] = color.g; line[pixel_x][2] = color.b; } linepic(line); /* if (line_y % 10 == 0) { */ /* printf("done line %d\n", line_y); */ /* fflush(stdout); */ /* } */ } endpic(); return 0; }