home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / LICOSA.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  3KB  |  152 lines

  1.  
  2.  
  3. #include <stdio.h>
  4. #include <vogle.h>
  5.  
  6. #define    TRANS        0.06
  7.  
  8. main()
  9. {
  10.         char    *p;
  11.     float    x, y, tdir = TRANS;
  12.     int    but, nplanes;
  13.     int    i, n;
  14.  
  15.     prefposition(50, 50);
  16.     prefsize(300, 300);
  17.  
  18.     vinit("mswin");
  19.  
  20.     window(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  21.     lookat(0.0, 0.0, 2.1, 0.0, 0.0, 0.0, 0.0);
  22.  
  23.     textsize(0.15, 0.3);
  24.  
  25.     backface(1);
  26.  
  27.     /*
  28.      * Green color ramp...
  29.      */
  30.     for (i = 1; i <= 20; i++)
  31.         mapcolor(i, 20, 20 + i * 10 , 20);
  32.         
  33.     if (backbuffer() < 0) {
  34.         verror("licosa: device doesn't support double buffering."); 
  35.         exit(0); 
  36.     }        
  37.  
  38.     while((but = slocator(&x, &y)) != 44) {
  39.         pushmatrix();
  40.             rotate(120.0 * x, 'y');
  41.             rotate(120.0 * y, 'x');
  42.             color(BLACK);
  43.             clear();
  44.             color(20);
  45.             move(0.0, 0.0, 0.0);
  46.             drawstr("Hello, world");
  47.             drawshape(1);
  48.             if (nplanes == 1)
  49.                 drawshape(0);
  50.         popmatrix();
  51.         swapbuffers();
  52.  
  53.         switch (but = checkkey()) {
  54.         case 'p':
  55.             voutput("licosa.ps");
  56.             vnewdev("postscript");
  57.             pushmatrix();
  58.                 rotate(100.0 * x, 'y');
  59.                 rotate(100.0 * y, 'x');
  60.                 color(BLACK);
  61.                 clear();
  62.                 drawshape(1);
  63.                 if (nplanes == 1)
  64.                     drawshape(0);
  65.             popmatrix();
  66.             vnewdev(device);
  67.             break;
  68.         case 'x':
  69.             translate(tdir, 0.0, 0.0);
  70.             break;
  71.         case 'y':
  72.             translate(0.0, tdir, 0.0);
  73.             break;
  74.         case 'z':
  75.             translate(0.0, 0.0, tdir);
  76.             break;
  77.         case '-':
  78.             tdir = -tdir;
  79.             break;
  80.         case '+':
  81.             tdir = TRANS;
  82.             break;
  83.         case 27: /* ESC */
  84.         case 'q':
  85.             vexit();
  86.             exit(0);
  87.         default:
  88.             ;
  89.         }
  90.     }
  91.  
  92.     vexit();
  93. }
  94.  
  95. static float    xyz[12][3] = {
  96.     {0.000000, 0.000000, 1.0},
  97.     {0.809017, -0.587785, 0.500000},
  98.     {0.809017, 0.587785, 0.500000},
  99.     {-0.309017, 0.951057, 0.500000},
  100.     {-1.000000, 0.000000, 0.500000},
  101.     {-0.309017, -0.951057, 0.500000},
  102.     {1.000000, 0.000000, -0.500000},
  103.     {0.309017, 0.951057, -0.500000},
  104.     {-0.809017, 0.587785, -0.500000},
  105.     {-0.809017, -0.587785, -0.500000},
  106.     {0.309017, -0.951057, -0.500000},
  107.     {0.000000, 0.000000, -1.0}
  108. };
  109. static int    ncon[20][3] = {
  110.     {1, 2, 3},
  111.     {1, 3, 4},
  112.     {1, 4, 5},
  113.     {1, 5, 6},
  114.     {1, 6, 2},
  115.     {2, 7, 3},
  116.     {3, 8, 4},
  117.     {4, 9, 5},
  118.     {5, 10, 6},
  119.     {6, 11, 2},
  120.     {7, 8, 3},
  121.     {8, 9, 4},
  122.     {9, 10, 5},
  123.     {10, 11, 6},
  124.     {11, 7, 2},
  125.     {7, 12, 8},
  126.     {8, 12, 9},
  127.     {9, 12, 10},
  128.     {10, 12, 11},
  129.     {11, 12, 7}
  130. };
  131.  
  132. drawshape(fill)
  133.     int    fill;
  134. {
  135.     int    i;
  136.  
  137.     polyfill(fill);
  138.     if (!fill)
  139.         color(BLACK);
  140.  
  141.     for (i = 0; i < 20; i++) {
  142.         if (fill)
  143.             color(i + 1);
  144.  
  145.         makepoly();
  146.     move(xyz[ncon[i][0]-1][0], xyz[ncon[i][0]-1][1], xyz[ncon[i][0]-1][2]);
  147.     draw(xyz[ncon[i][1]-1][0], xyz[ncon[i][1]-1][1], xyz[ncon[i][1]-1][2]);
  148.     draw(xyz[ncon[i][2]-1][0], xyz[ncon[i][2]-1][1], xyz[ncon[i][2]-1][2]);
  149.         closepoly();
  150.     }
  151. }
  152.