home *** CD-ROM | disk | FTP | other *** search
- /*
- * read the input file of the ray-tracer
- */
-
- /*
- * (c) 1988 by George Kyriazis
- */
-
- #include <stdio.h>
- #include <math.h>
- #include <hypdefs.h>
- #include <hyper.h>
- #include <hypio.h>
- #include <devlib.h>
- #include <devextern.h>
- #include <msgserve.h>
-
- #define HOST
- #include "ray.h"
- #include "msg.h"
-
- int zero = FALSE;
- int one = 4;
- int test;
-
- struct dsp_vector { Ulong x, y, z; };
-
- struct dsp_color { Ulong r,g,b; };
-
- struct dsp_light { struct dsp_vector org; Ulong angle; };
-
- struct dsp_obj {
- Ushort type;
- Ushort dummy;
- union dsp_data {
- struct dsp_sphere {
- struct dsp_vector center;
- Ulong radius;
- } sphere;
- struct dsp_quad {
- struct dsp_vector p1;
- struct dsp_vector p2;
- struct dsp_vector p3;
- } quad;
- } data;
- Ulong reflection;
- Ulong refraction;
- struct dsp_color refl_color;
- struct dsp_color refr_color;
- struct dsp_color ambient;
- struct dsp_color diffuse;
- struct dsp_color specular;
- Ulong width;
- Ulong index;
- Ulong refl_diffuse;
- Ulong refr_diffuse;
- struct dsp_vector time;
- };
-
- #define TODSP(x,y) y = C_FtoDsp(x); y = Swapl(y);
-
- readfile(fname)
- char *fname;
- {
- FILE *f;
- int i, j;
- char s[10];
-
- f = fopen(fname,"r");
- if(f == NULL) {
- perror("fopen");
- exit(1);
- }
-
- /* file format is:
- * <fov> field of view
- * <eyex eyey eyez> position of the eye
- * <dirx diry dirz> direction
- * <upx upy upz> up vector
- * <time1 time2> time limits
- * <foc lens> focusing distance and diameter of lens
- * <#> background cuing
- * <min max> minimum and maximum number of interations per pixel
- * <x y z angle> light source position and angle
- * number or spheres number of squares
- * <x y z r [ambient] [diff] [spec] refl r g b refr r g b
- * width index refl_diffuse refr_diffuse tx ty tz>
- * for every sphere
- * <x y z x y z x y z [ambient] [diff] [spec]
- * refl r g b refr r g b width index
- * refl_diffuse refr_diffuse tx ty tz>
- * for every square
- */
-
- /* viewing transform */
- fscanf(f, "%lf", &fov);
- fov = tan( fov * M_PI / 180 ) / sqrt(2.0);
- fscanf(f, "%lf %lf %lf", &eye.x, &eye.y, &eye.z);
- fscanf(f, "%lf %lf %lf", &eye_dir.x, &eye_dir.y, &eye_dir.z);
- fscanf(f, "%lf %lf %lf", &up.x, &up.y, &up.z);
-
- /* time information */
- fscanf(f, "%lf %lf", &time1, &time2);
-
- /* lens information */
- fscanf(f, "%lf %lf", &foc, &lens);
-
- /* the background flag */
- fscanf(f, "%s", s);
- if( *s == 'n' ) bgflag = NONE;
- if( *s == 'x' ) bgflag = X;
- if( *s == 'y' ) bgflag = Y;
- if( *s == 'z' ) bgflag = Z;
-
- /* how many samples per pixel? */
- fscanf(f, "%d", &tries);
-
- /* now the light */
- fscanf(f, "%lf %lf %lf %lf", &light.org.x, &light.org.y,
- &light.org.z, &light.angle);
- light.angle *= M_PI / 180;
-
- fscanf(f, "%d %d", &nos, &nosq);
- noo = nos + nosq;
-
- obj = (struct obj *)malloc(noo * sizeof(struct obj) );
- if(obj == NULL) {
- perror("malloc");
- exit(1);
- }
-
- i = 0;
- for(j = 0; j < nos; j++) {
- obj[i].type = SPHERE;
- fscanf(f, "%lf %lf %lf %lf", &obj[i].data.sphere.center.x,
- &obj[i].data.sphere.center.y,
- &obj[i].data.sphere.center.z,
- &obj[i].data.sphere.radius );
- fscanf(f, "%lf %lf %lf", &obj[i].ambient.r,
- &obj[i].ambient.g,
- &obj[i].ambient.b);
- fscanf(f, "%lf %lf %lf", &obj[i].diffuse.r,
- &obj[i].diffuse.g,
- &obj[i].diffuse.b);
- fscanf(f, "%lf %lf %lf", &obj[i].specular.r,
- &obj[i].specular.g,
- &obj[i].specular.b);
- fscanf(f, "%lf %lf %lf %lf", &obj[i].reflection,
- &obj[i].refl_color.r,
- &obj[i].refl_color.g,
- &obj[i].refl_color.b);
- fscanf(f, "%lf %lf %lf %lf", &obj[i].refraction,
- &obj[i].refr_color.r,
- &obj[i].refr_color.g,
- &obj[i].refr_color.b);
- fscanf(f, "%lf %lf", &obj[i].width, &obj[i].index);
- fscanf(f, "%lf %lf", &obj[i].refl_diffuse,
- &obj[i].refr_diffuse);
- obj[i].refl_diffuse *= M_PI / 180;
- obj[i].refr_diffuse *= M_PI / 180;
- fscanf(f, "%lf %lf %lf", &obj[i].time.x,
- &obj[i].time.y, &obj[i].time.z);
-
- i++;
- }
-
- for(j = 0 ; j < nosq; j++) {
- obj[i].type = SQUARE;
- fscanf(f, "%lf %lf %lf", &obj[i].data.quad.p1.x,
- &obj[i].data.quad.p1.y,
- &obj[i].data.quad.p1.z);
- fscanf(f, "%lf %lf %lf", &obj[i].data.quad.p2.x,
- &obj[i].data.quad.p2.y,
- &obj[i].data.quad.p2.z);
- fscanf(f, "%lf %lf %lf", &obj[i].data.quad.p3.x,
- &obj[i].data.quad.p3.y,
- &obj[i].data.quad.p3.z);
- fscanf(f, "%lf %lf %lf", &obj[i].ambient.r,
- &obj[i].ambient.g,
- &obj[i].ambient.b);
- fscanf(f, "%lf %lf %lf", &obj[i].diffuse.r,
- &obj[i].diffuse.g,
- &obj[i].diffuse.b);
- fscanf(f, "%lf %lf %lf", &obj[i].specular.r,
- &obj[i].specular.g,
- &obj[i].specular.b);
- fscanf(f, "%lf %lf %lf %lf", &obj[i].reflection,
- &obj[i].refl_color.r,
- &obj[i].refl_color.g,
- &obj[i].refl_color.b);
- fscanf(f, "%lf %lf %lf %lf", &obj[i].refraction,
- &obj[i].refr_color.r,
- &obj[i].refr_color.g,
- &obj[i].refr_color.b);
- fscanf(f, "%lf %lf", &obj[i].width, &obj[i].index);
- fscanf(f, "%lf %lf", &obj[i].refl_diffuse,
- &obj[i].refr_diffuse);
- obj[i].refl_diffuse *= M_PI / 180;
- obj[i].refr_diffuse *= M_PI / 180;
- fscanf(f, "%lf %lf %lf", &obj[i].time.x,
- &obj[i].time.y, &obj[i].time.z);
-
- i++;
- }
-
- printf("Read data\n");
- send_noo();
- DEVpoll_nodes(DEV_NONE, DEV_NONE,
- 0, DEVsystem->draw_nodes - 1,
- 0, 63,
- noo,1);
- printf("Begin tracing\n");
- }
-
- send_noo()
- {
- int i;
- short no = noo,
- ns = nos,
- nsq = nosq,
- bg = bgflag;
-
- SHORT_SWAP(no);
- SHORT_SWAP(ns);
- SHORT_SWAP(nsq);
- SHORT_SWAP(bg);
- for( i = 0; i < DEVsystem->draw_nodes; i++) {
- HypDrawWrite( DEVsystem->draw_dsp[i], pixel_nos[i],
- &ns, sizeof(short) );
- HypDrawWrite( DEVsystem->draw_dsp[i], pixel_nosq[i],
- &nsq, sizeof(short) );
- HypDrawWrite( DEVsystem->draw_dsp[i], pixel_bgflag[i],
- &bg, sizeof(short) );
- HypDrawWrite( DEVsystem->draw_dsp[i], pixel_status[i],
- &zero, sizeof(int) );
- }
-
- }
-
- send_light(l, node)
- int node;
- Ushort l;
- {
- struct dsp_light dsp_l;
-
- dsp_l.org.x = C_FtoDsp(light.org.x); dsp_l.org.x = Swapl(dsp_l.org.x);
- dsp_l.org.y = C_FtoDsp(light.org.y); dsp_l.org.y = Swapl(dsp_l.org.y);
- dsp_l.org.z = C_FtoDsp(light.org.z); dsp_l.org.z = Swapl(dsp_l.org.z);
- dsp_l.angle = C_FtoDsp(light.angle); dsp_l.angle = Swapl(dsp_l.angle);
- HypDrawWrite( DEVsystem->draw_dsp[node], l,
- &dsp_l, sizeof( struct dsp_light ) );
- }
-
- send_object(i, o, node)
- Ushort i;
- Ushort o;
- int node;
- {
- struct dsp_obj dsp_o;
-
- dsp_o.type = (Ushort) obj[i].type;
- SHORT_SWAP( dsp_o.type );
- switch( obj[i].type ) {
- case SPHERE:
- TODSP( obj[i].data.sphere.center.x,
- dsp_o.data.sphere.center.x);
- TODSP( obj[i].data.sphere.center.y,
- dsp_o.data.sphere.center.y);
- TODSP( obj[i].data.sphere.center.z,
- dsp_o.data.sphere.center.z);
- TODSP( obj[i].data.sphere.radius,
- dsp_o.data.sphere.radius);
- break;
- case SQUARE:
- TODSP( obj[i].data.quad.p1.x, dsp_o.data.quad.p1.x );
- TODSP( obj[i].data.quad.p1.y, dsp_o.data.quad.p1.y );
- TODSP( obj[i].data.quad.p1.z, dsp_o.data.quad.p1.z );
- TODSP( obj[i].data.quad.p2.x, dsp_o.data.quad.p2.x );
- TODSP( obj[i].data.quad.p2.y, dsp_o.data.quad.p2.y );
- TODSP( obj[i].data.quad.p2.z, dsp_o.data.quad.p2.z );
- TODSP( obj[i].data.quad.p3.x, dsp_o.data.quad.p3.x );
- TODSP( obj[i].data.quad.p3.y, dsp_o.data.quad.p3.y );
- TODSP( obj[i].data.quad.p3.z, dsp_o.data.quad.p3.z );
- break;
- default:
- break;
- }
- TODSP( obj[i].reflection, dsp_o.reflection);
- TODSP( obj[i].refraction, dsp_o.refraction);
- TODSP( obj[i].refl_color.r, dsp_o.refl_color.r);
- TODSP( obj[i].refl_color.g, dsp_o.refl_color.g);
- TODSP( obj[i].refl_color.b, dsp_o.refl_color.b);
- TODSP( obj[i].refr_color.r, dsp_o.refr_color.r);
- TODSP( obj[i].refr_color.g, dsp_o.refr_color.g);
- TODSP( obj[i].refr_color.b, dsp_o.refr_color.b);
- TODSP( obj[i].ambient.r, dsp_o.ambient.r);
- TODSP( obj[i].ambient.g, dsp_o.ambient.g);
- TODSP( obj[i].ambient.b, dsp_o.ambient.b);
- TODSP( obj[i].diffuse.r, dsp_o.diffuse.r);
- TODSP( obj[i].diffuse.g, dsp_o.diffuse.g);
- TODSP( obj[i].diffuse.b, dsp_o.diffuse.b);
- TODSP( obj[i].specular.r, dsp_o.specular.r);
- TODSP( obj[i].specular.g, dsp_o.specular.g);
- TODSP( obj[i].specular.b, dsp_o.specular.b);
- TODSP( obj[i].width, dsp_o.width);
- TODSP( obj[i].index, dsp_o.index);
- TODSP( obj[i].refl_diffuse, dsp_o.refl_diffuse);
- TODSP( obj[i].refr_diffuse, dsp_o.refr_diffuse);
- TODSP( obj[i].time.x, dsp_o.time.x);
- TODSP( obj[i].time.y, dsp_o.time.y);
- TODSP( obj[i].time.z, dsp_o.time.z);
-
- HypDrawWrite( DEVsystem->draw_dsp[node], o,
- &dsp_o, sizeof( struct dsp_obj ));
- }
-
- send_data(opcode, dsp, node)
- int opcode;
- DrawDsp *dsp;
- int node;
- {
- Ushort o; /* DSP obj address */
- Ushort l; /* DSP light address */
- Ushort i;
-
- i = HypDrawGetPir(dsp);
- /* get the object pointer address */
- o = HypDrawGetPir(dsp);
- /* now get the light address */
- l = HypDrawGetPir(dsp);
-
- send_light(l, node);
- send_object(i, o, node);
-
- HypDrawWrite( DEVsystem->draw_dsp[node], pixel_status[node],
- &zero, sizeof(int) );
- }
-