home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / uray / code / uray.c < prev    next >
C/C++ Source or Header  |  1994-06-20  |  6KB  |  216 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1988, David B. Wecker            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  * This file is part of DBW_uRAY                    *
  7.  *                                    *
  8.  * DBW_uRAY is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts        *
  10.  * responsibility to anyone for the consequences of using it or for    *
  11.  * whether it serves any particular purpose or works at all, unless    *
  12.  * he says so in writing. Refer to the DBW_uRAY General Public        *
  13.  * License for full details.                        *
  14.  *                                    *
  15.  * Everyone is granted permission to copy, modify and redistribute    *
  16.  * DBW_uRAY, but only under the conditions described in the        *
  17.  * DBW_uRAY General Public License. A copy of this license is        *
  18.  * supposed to have been given to you along with DBW_uRAY so you    *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named LICENSE. Among other things, the copyright notice and this    *
  21.  * notice must be preserved on all copies.                *
  22.  ************************************************************************
  23.  *                                    *
  24.  * Authors:                                *
  25.  *    DBW - David B. Wecker                        *
  26.  *                                    *
  27.  * Versions:                                *
  28.  *    V1.0 881023 DBW    - First released version            *
  29.  *    V1.1 881110 DBW - Fixed scan coherence code            *
  30.  *    V1.2 881125 DBW - Removed ALL scan coherence code (useless)    *
  31.  *              added "fat" extent boxes            *
  32.  *    V1.3 881203 DBW - Fixed single precision TOLerances        *
  33.  *                                    *
  34.  ************************************************************************/
  35.  
  36. #define URAY_MAIN 1
  37. #include "uray.h"
  38.  
  39. /************************************************************************/
  40. /************* top level routines ***************************************/
  41. /************************************************************************/
  42.  
  43. /* ray trace 1 pixel on the screen and store it away */
  44. dotrace(v1)
  45. VEC    v1;
  46.     {
  47.     int        i;
  48.     VEC        v2;
  49.  
  50.     /* compute the point we're looking at (from 0,0,0) */
  51.      v1[0] = (double)col-(double)cols/2.0;
  52.  
  53.     /* normalize the direction, and ray trace it */
  54.     vunit(v1,v2);
  55.     trace(-1, 1.0, BLACK, v2, v2, NULL);
  56.  
  57.     /* scale the color and store it */
  58.     for (i=0; i<3; i++) {
  59.     if (v2[i] < 0.0) v2[i] = 0.0;
  60.     if (v2[i] > 1.0) v2[i] = 1.0;
  61.     outary[i][col] = (unsigned char)(v2[i]*255.9);
  62.     }
  63.  
  64. #if DEBUG_pixels
  65.     printf("(%3d,%3d) = [%02x %02x %02x] [%4.2f %4.2f %4.2f]\n",
  66.     row,col,outary[0][col],outary[1][col],outary[2][col],v2[0],v2[1],v2[2]);
  67. #endif
  68.  
  69.     }
  70.  
  71.  
  72. /* interrupt handler for any errors */
  73. handler(sig) {
  74.     leave("signal %d received... exiting",sig);
  75.     }
  76.  
  77.  
  78.  
  79. main(argc,argv)
  80. char    **argv;
  81.     {
  82.     int        i,j;
  83.     VEC        v1;
  84.  
  85.     /* definitions for doing elapsed user time */
  86.     double  dtime;
  87. #   ifdef U__X
  88.     struct  tms        etime;
  89. #    endif
  90. #   ifdef VMS
  91.     struct    tbuffer     etime;
  92.     double            btime;
  93. #    endif
  94. #   ifdef AMIGA
  95.     unsigned long        bsecs,bmicros,csecs,cmicros;
  96.     struct IntuitionBase    *OpenLibrary();
  97. #    endif
  98.  
  99.     printf(VERSION);
  100.  
  101.     /* grab as many errors as possible */
  102.     signal(SIGINT,handler);    /* ^C hit  */
  103.     signal(SIGFPE,handler);    /* floating point error (/ 0) */
  104.     signal(SIGILL,handler);    /* illegal instruction */
  105.     signal(SIGSEGV,handler);    /* segmentation violation (addr err) */
  106.  
  107.     /* Get the starting time */
  108. #   ifdef AMIGA
  109.     IntuitionBase = OpenLibrary("intuition.library",0L);
  110.     if (!IntuitionBase) exit(0);
  111.  
  112.     CurrentTime(&bsecs,&bmicros);
  113. #   endif
  114.  
  115.  
  116. #   ifdef VMS
  117.     times(&etime);
  118.     btime = ((double)etime.proc_user_time)/100.0;
  119. #    endif
  120.  
  121.     /* get a base file name */
  122.     if (argc > 1) basnam = argv[1];
  123.  
  124.     /* get all the object definitions in to memory */
  125.     readinput();
  126.  
  127.     /* build a tree of object extents */
  128.     doextents();
  129.  
  130. #   if DEBUG_dumpnodes
  131.     dumpnodes(nodes,0);
  132. #    endif
  133.  
  134.     /* get the current time (after setting up extents) */
  135. #   ifdef U__X
  136.     times(&etime);
  137.     dtime = ((double)etime.tms_utime)/60.0;
  138. #    endif
  139.  
  140. #   ifdef VMS
  141.     times(&etime);
  142.     dtime = ((double)etime.proc_user_time)/100.0 - btime;
  143. #    endif
  144.  
  145. #   ifdef AMIGA
  146.     CurrentTime(&csecs,&cmicros);
  147.     if (cmicros < bmicros) {
  148.         cmicros += 1000000;
  149.         csecs   -= 1;
  150.         }
  151.     dtime  =  (double)(csecs-bsecs);
  152.     dtime += ((double)(cmicros-bmicros)) / 1000000.0;
  153. #    endif
  154.  
  155.     printf("\nExtent setup time: %12.2f\n\n",dtime);
  156.  
  157.     /* compute the number of output bytes in a scan line */
  158.     if        (bpp == 24) obpsl = cols;
  159.     else if (bpp == 12) obpsl = cols >> 1;
  160.     else if (bpp) leave("BPP must be either 12, 24 or 0");
  161.     bpp        /= 3;
  162.  
  163.     /* create output files */
  164.     coutputs();
  165.  
  166.     /* define depth of the screen */
  167.     v1[2] = ((double)(rows+cols))/4.0/tan((double)aov/114.5915590261);
  168.  
  169.     /* now ray trace each pixel */
  170.     for (row=startrow; row<endrow; row++) {
  171.  
  172.     /* define row we're looking at */
  173.     v1[1] = ((double)rows/2.0-(double)row) * aspect;
  174.  
  175.     /* ray trace all pixels */
  176.     for (col=0; col<cols; col++) dotrace(v1);
  177.  
  178.     /* output the line */
  179.     woutputs((short)row);
  180.  
  181.     }
  182.  
  183.     printf("\n\n");
  184.  
  185.  
  186.     /* get the ending elapsed time */
  187. #   ifdef U__X
  188.     times(&etime);
  189.     dtime = ((double)etime.tms_utime)/60.0;
  190. #    endif
  191.  
  192. #   ifdef VMS
  193.     times(&etime);
  194.     dtime = ((double)etime.proc_user_time)/100.0 - btime;
  195. #    endif
  196.  
  197. #   ifdef AMIGA
  198.     CurrentTime(&csecs,&cmicros);
  199.     if (cmicros < bmicros) {
  200.         cmicros += 1000000;
  201.         csecs   -= 1;
  202.         }
  203.     dtime  =  (double)(csecs-bsecs);
  204.     dtime += ((double)(cmicros-bmicros)) / 1000000.0;
  205. #    endif
  206.  
  207.     printf("\nTotal  run   time: %12.2f\n\n",dtime);
  208.     printf("False hits: Extents = %10d, Nodes = %10d\n",fehits,fnhits);
  209.     printf("Good  hits: Extents = %10d, Nodes = %10d\n",gehits,gnhits);
  210.     printf("Total hits: Extents = %10d, Nodes = %10d\n\n",
  211.     fehits+gehits,fnhits+gnhits);
  212.  
  213.     /* all done, so finish up */
  214.     leave(NULL);
  215.     }
  216.