/* Create a gasket for the Radiance rendering program (Easily mdified for any other renderer) Paul Bourke */ #include "stdio.h" #include "stdlib.h" #include "math.h" main(c,v) int c; char **v; { int i,n=0; char s[32]; float x,y,z,r; FILE *fin,*fout,*frad; /* The first argument is the level to create The previous level must have already been created */ if (c == 2) { n = atoi(v[1]); printf("Creating gasket at level %d\n",n); } /* Open the data file for the last level */ sprintf(s,"gasket%d",n); if ((fin = fopen(s,"r")) == NULL) { printf("Unable to open input file\n"); return; } /* Open the data file for the next level */ sprintf(s,"gasket%d",n+1); if ((fout = fopen(s,"w")) == NULL) { printf("Unavble to open output file\n"); return; } /* Open the radiance output file for the next level */ sprintf(s,"gasket%d.rad",n+1); if ((frad = fopen(s,"w")) == NULL) { printf("Unable to open output file\n"); return; } /* Add some stuff to the top of the Radiance file */ fprintf(frad,"void plastic m 0 0 5 .5 .5 .5 .05 05\n"); fprintf(frad,"void light light1 0 0 3 100 100 100\n"); fprintf(frad,"light1 sphere thelight1 0 0 4 100 0 100 10\n"); fprintf(frad,"light1 sphere thelight2 0 0 4 0 0 0 2\n"); fprintf(frad,"light1 sphere thelight3 0 0 4 0 -100 0 10\n"); /* Read the last level data file and construct the next level */ while (fscanf(fin,"%f %f %f %f\n",&x,&y,&z,&r) == 4) { /* Data file stuff */ fprintf(fout,"%g %g %g %g\n",x-r/4,y-r/4,z-r/4,r/2); fprintf(fout,"%g %g %g %g\n",x-r/4,y+r/4,z-r/4,r/2); fprintf(fout,"%g %g %g %g\n",x+r/4,y-r/4,z-r/4,r/2); fprintf(fout,"%g %g %g %g\n",x+r/4,y+r/4,z-r/4,r/2); fprintf(fout,"%g %g %g %g\n",x ,y ,z+r/4,r/2); /* Radiance stuff */ genprism(frad,r/2,x-r/2,y-r/2,z-r/2); genprism(frad,r/2,x ,y-r/2,z-r/2); genprism(frad,r/2,x-r/2,y ,z-r/2); genprism(frad,r/2,x ,y ,z-r/2); genprism(frad,r/2,x-r/4,y-r/4,z ); } /* Thats all, close the files */ fclose(fin); fclose(fout); fclose(frad); } /* Create the Radiance description for a pyramid Don't need the bottom if we always look from above */ void genprism(f,r,x,y,z) FILE *f; float r,x,y,z; { float r2; r2 = r / 2.0; fprintf(f,"m polygon p 0 0 9 "); fprintf(f,"%g %g %g %g %g %g %g %g %g\n",x,y,z,x+r,y,z,x+r2,y+r2,z+r); fprintf(f,"m polygon p 0 0 9 "); fprintf(f,"%g %g %g %g %g %g %g %g %g\n",x+r,y,z,x+r,y+r,z,x+r2,y+r2,z+r); fprintf(f,"m polygon p 0 0 9 "); fprintf(f,"%g %g %g %g %g %g %g %g %g\n",x+r,y+r,z,x,y+r,z,x+r2,y+r2,z+r); fprintf(f,"m polygon p 0 0 9 "); fprintf(f,"%g %g %g %g %g %g %g %g %g\n",x,y+r,z,x,y,z,x+r2,y+r2,z+r); }