home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / EXAMPLES / LICOSA.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  3KB  |  158 lines

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