home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 015.lha / tracer_source / tracer.c.old < prev    next >
Text File  |  1986-11-10  |  4KB  |  179 lines

  1. /***************************************************************
  2.  *            basic ray tracing package tracer2.0              *
  3.  *            version 0.0 done 6/1/86-6/10/86                  *
  4.  *            version 1.0 released 6/29/86                     *
  5.  *            version 2.0 released 7/5/86                      *
  6.  *            by friedrich knauss (one tired programmer)       *
  7.  *                                   *
  8.  *          amiga version adapted by mark reichert           *
  9.  ***************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include "MyMath.h"
  14. #include "rtd.h"
  15. #include "macros.h"
  16.  
  17. #define    CHECK_IT    if ( Chk_Abort() ) {\
  18.                 printf("Aborted\n");\
  19.                 gfx_close();\
  20.                 exit(104);\
  21.             }
  22.  
  23. FILE    *fptr;
  24. char    suzie[300][300];
  25. FFP    sam;
  26.  
  27. int    xsue,
  28.     ysue;
  29.  
  30. struct    ball    *bl[150];
  31.  
  32. int    level=0,
  33.     nob;
  34.  
  35. struct    sphere    ls;
  36.  
  37. main(argc, argv)
  38. int    argc;
  39. char    **argv;
  40. {
  41.     FILE    *df, *texfile;
  42.     static    double    xco,
  43.             yco;
  44.     struct    ray    rr;
  45.     struct    vector    vp;
  46.     int    i,
  47.         in = 0,
  48.         tex = 0;
  49.     int    c;
  50.     char    temp[10];
  51.  
  52.     if( !open_math() ) {
  53.         printf("couldn't open math library\n");
  54.         exit(103);
  55.     }
  56.  
  57.     sam = SPFlt(1);
  58.  
  59.     /* command interp */
  60.     for (i = 1; i < argc; i++) {
  61.         if (argv[i][0] != '-')
  62.             booboo ("Options start with a '-'");
  63.  
  64.         c = argv[i][1];
  65.  
  66.         switch (c) {
  67.         case ('i') : /* input file */
  68.             if (in)
  69.                     booboo ("Sorry, only one input file");
  70.             in = 1;
  71.  
  72.             if ((i + 1) >= argc || argv[i + 1][0] == '-')
  73.                 /* no arg */
  74.                 df = stdin;
  75.             else if ((df = fopen (argv[++i], "r")) == NULL)
  76.                 booboo ("input file not found");
  77.  
  78.             break;
  79.  
  80.         case ('o'): /* output file */
  81.             booboo ("-o option no longer supported.");
  82.             break;
  83.  
  84.         case ('s'): /* susie file */
  85.             if (tex)
  86.                 booboo ("Sorry, only one image file");
  87.  
  88.             if ((i + 1) >= argc || argv[i + 1][0] == '-')
  89.                 /* no arg */
  90.                 booboo ("-s requires an argument");
  91.  
  92.             tex = 1;
  93.  
  94.             if ((texfile = fopen (argv[++i], "r")) == NULL)
  95.                 booboo ("image file not found");
  96.  
  97.             break;
  98.  
  99.         case ('S'): /* amount of susie */
  100.             if (argv[i][2] < '0' || argv[i][2] > 9)
  101.                 booboo ("-S needs a numerical argument");
  102.  
  103.             sam = ieee_to_ffp( atof (&(argv[i][2])) );
  104.  
  105.             break;
  106.  
  107.         default: 
  108.             booboo ("Unrecognized option. Better try again");
  109.         }
  110.     }
  111.  
  112.  
  113.     if (!in)
  114.         if ((df = fopen ("bdata.i", "r")) == NULL)
  115.             booboo ("bdata.i not found");
  116.  
  117.     if (!tex)
  118.         if ((texfile = fopen ("pat.def", "r")) == NULL)
  119.             booboo ("pat.def not found");
  120.  
  121.  
  122.     /* if you can't figure *this* out, you should go home */
  123.     nob = g_bal (df);
  124.  
  125.     g_bod (texfile);
  126.  
  127.     MV (SPFlt(95), SPFlt(140), SPFlt(-200), vp);    /* view point    */
  128.     MV (SPFlt(95), SPFlt(900), SPFlt(0), ls.cent);    /* light source    */
  129.     ls.rad = SPFlt(70);
  130.  
  131.     gfx_open();
  132.  
  133.     for (yco = (YMAX * SCALE); yco > YMIN * SCALE; yco-= 2.0 ) {
  134.         for (xco = XMIN * SCALE; xco < XMAX * SCALE; xco+= 2.0 ) {
  135.             MV (ieee_to_ffp(xco / SCALE),ieee_to_ffp(yco / SCALE), SPFlt(0), rr.org );
  136.             SV (rr.dir, rr.org, vp);
  137.             do_pixel( (int)xco, (int)yco, shade(&rr) );
  138.         }
  139.         CHECK_IT;
  140.     }
  141.  
  142.     for (yco = (YMAX * SCALE) + 1.0; yco > YMIN * SCALE; yco-= 2.0 ) {
  143.         for (xco = (XMIN * SCALE)+1.0; xco < XMAX * SCALE; xco+= 2.0 ) {
  144.             MV (ieee_to_ffp(xco / SCALE),ieee_to_ffp(yco / SCALE), SPFlt(0), rr.org );
  145.             SV (rr.dir, rr.org, vp);
  146.             do_pixel( (int)xco, (int)yco, shade(&rr) );
  147.         }
  148.         CHECK_IT;
  149.     }
  150.  
  151.     for (yco = (YMAX * SCALE); yco > YMIN * SCALE; yco-= 2.0 ) {
  152.         for (xco = (XMIN * SCALE)+1.0; xco < XMAX * SCALE;xco+=2.0) {
  153.             MV (ieee_to_ffp(xco / SCALE),ieee_to_ffp(yco / SCALE), SPFlt(0), rr.org );
  154.             SV (rr.dir, rr.org, vp);
  155.             do_pixel( (int)xco, (int)yco, shade(&rr) );
  156.         }
  157.         CHECK_IT;
  158.     }
  159.  
  160.     for (yco = (YMAX * SCALE) + 1.0; yco > YMIN * SCALE; yco-= 2.0 ) {
  161.         for (xco = XMIN * SCALE; xco < XMAX * SCALE;xco+=2.0) {
  162.             MV (ieee_to_ffp(xco / SCALE),ieee_to_ffp(yco / SCALE), SPFlt(0), rr.org );
  163.             SV (rr.dir, rr.org, vp);
  164.             do_pixel( (int)xco, (int)yco, shade(&rr) );
  165.         }
  166.         CHECK_IT;
  167.     }
  168.  
  169.     gets(temp);
  170.     gfx_close();
  171. }
  172.  
  173. booboo (str)
  174. char     *str;
  175. {
  176.     printf ("%s\n", str);
  177.     exit (-1);
  178. }
  179.