home *** CD-ROM | disk | FTP | other *** search
/ Altsys Virtuoso 2.0K / virtuoso_20k.iso / DemoApps / Graphics / Viewers / raytracers / ohta / Source / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  1.6 KB  |  80 lines

  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. #include "ray.h"
  5.  
  6. input(s)
  7. char *s;
  8. {struct object *o;
  9. FILE *f;
  10. int i,sp,sd;
  11. char c;
  12. double fov;
  13.     if((f=fopen(s,"r"))==0)
  14.     {    perror(s);
  15.         exit(1);
  16.     }
  17.     o=objects;
  18.     if(fscanf(f," f %lf ",&fov)!=1||fov<=0||fov>=180)
  19.     {    fprintf(stderr,"field of view format error\n");
  20.         exit(1);
  21.     }
  22.     fovf=tan(fov*3.14159/360)/sqrt(2.0);
  23.     o->flags=EYE;
  24.     o->center.x=o->center.y=o->center.z=0;
  25.     o->radius=0;
  26.     o++;
  27.     lights=0;
  28.     while(fscanf(f," l %lf %lf %lf ",&o->center.x,&o->center.y,
  29.         &o->center.z)==3)
  30.     {    o->flags=LIGHT;
  31.         o->radius=0;
  32.         o++;
  33.         lights++;
  34.     }
  35.     maxobj=lights+1;
  36.     while(fscanf(f," o %d %d ",&sp,&sd)==2)
  37.     {    if(maxobj==MAXOBJECTS)
  38.         {    fprintf(stderr,"too many objects\n");
  39.             exit(1);
  40.         }
  41.         if(sp<0||sp>=nshapetab)
  42.         {    fprintf(stderr,"shape number range error\n");
  43.             exit(1);
  44.         }
  45.         if(sd<0||sd>=nshadetab)
  46.         {    fprintf(stderr,"shade number range error\n");
  47.             exit(1);
  48.         }
  49.         o= &objects[maxobj];
  50.         o->flags=0;
  51.  
  52.         o->shape=shapetab[sp].shapefunc;
  53.         o->spparams=nalloc(double,shapetab[sp].nparams);
  54.         for(i=0;i<shapetab[sp].nparams;i++)
  55.         {    if(fscanf(f," %lf ",&o->spparams[i])!=1)
  56.             {    fprintf(stderr,"shape parameter error\n");
  57.                 exit(1);
  58.             }
  59.         }
  60.         (*shapetab[sp].shapeinitfunc)(o);
  61.  
  62.         o->shade=shadetab[sd].shadefunc;
  63.         o->sdparams=nalloc(double,shadetab[sd].nparams);
  64.         for(i=0;i<shadetab[sd].nparams;i++)
  65.         {    if(fscanf(f," %lf ",&o->sdparams[i])!=1)
  66.             {    fprintf(stderr,"shade parameter error\n");
  67.                 exit(1);
  68.             }
  69.         }
  70.         (*shadetab[sd].shadeinitfunc)(o);
  71.  
  72.         maxobj++;
  73.     }
  74.     if(fscanf(f," %c",&c)!=1||c!='e')
  75.     {    fprintf(stderr,"end command not found\n");
  76.         exit(1);
  77.     }
  78.     (void) fclose(f);
  79. }
  80.