home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / LCUBE.C < prev    next >
Text File  |  1993-05-28  |  4KB  |  207 lines

  1.  
  2. #include <stdio.h>
  3. #include <vogle.h>
  4.  
  5. #define    CUBE_SIZE    200.0
  6. #define    TRANS        25.0
  7. #define    SCAL        0.1
  8. #define FACE        1
  9. #define FILLED        2
  10. #define OUTLINE        3
  11.  
  12. main(argc, argv)
  13.     int    argc;
  14.     char    *argv[];
  15. {
  16.     float    x, y, tdir = TRANS;
  17.     float    scal = 1.0 + SCAL;
  18.     int    but, nplanes;
  19.     int    back, fill, hatch, i, n;
  20.  
  21.  
  22.     prefposition(50, 50);
  23.     prefsize(250, 250);
  24.  
  25.     vinit("mswin");
  26.  
  27.     window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
  28.     lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0.0);
  29.  
  30.     /*
  31.      * Start with a very ordinary filled cube like the old demo..
  32.      */
  33.     polyhatch(0);
  34.     hatchang(45.0);
  35.     hatchpitch(40.0);
  36.     polyfill(1);
  37.  
  38.     fill = 1;
  39.     hatch = 0;
  40.     back = 1;
  41.  
  42.     makeobj(FACE);     /* hatched or filled polygon */
  43.         makepoly();
  44.             rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  45.         closepoly();
  46.     closeobj();
  47.  
  48.     makecube(FILLED);
  49.  
  50.     if ((nplanes = getdepth()) == 1)
  51.         makecube(OUTLINE);
  52.  
  53.     backface(1);
  54.         
  55.     if (backbuffer() < 0) {
  56.         verror("lcube: device doesn't support double buffering.\n"); 
  57.     }        
  58.  
  59.     while((but = slocator(&x, &y)) != 44) {
  60.         pushmatrix();
  61.             rotate(100.0 * x, 'y');
  62.             rotate(100.0 * y, 'x');
  63.             color(BLACK);
  64.             clear();
  65.             callobj(FILLED);    /* The filled or hatched one */
  66.             if (nplanes == 1 && (fill || hatch))
  67.                 callobj(OUTLINE);    /* The outline */
  68.  
  69.         popmatrix();
  70.         swapbuffers();
  71.  
  72.         switch (but = checkkey()) {
  73.         case 'p':
  74.             voutput("lcube.ps");
  75.             vnewdev("postscript");
  76.             pushmatrix();
  77.                 rotate(100.0 * x, 'y');
  78.                 rotate(100.0 * y, 'x');
  79.                 color(BLACK);
  80.                 clear();
  81.                 callobj(FILLED);
  82.                 if (nplanes == 1 && (fill || hatch))
  83.                     callobj(OUTLINE);
  84.             popmatrix();
  85.             vnewdev("mswin");
  86.             (void)backbuffer();
  87.             break;
  88.         case 'f':    /* Toggle filling */
  89.             fill = !fill;
  90.             hatch = 0;
  91.             polyfill(fill);
  92.             break;
  93.         case 'h':    /* Toggle hatching */
  94.             hatch = !hatch;
  95.             fill = 0;
  96.             polyhatch(hatch);
  97.             break;
  98.         case 'b':     /* Toggle backfacing */
  99.             back = !back;
  100.             backface(back);
  101.             break;
  102.         case 's':
  103.             scale(scal, scal, scal);
  104.             break;
  105.         case 'x':
  106.             translate(tdir, 0.0, 0.0);
  107.             break;
  108.         case 'y':
  109.             translate(0.0, tdir, 0.0);
  110.             break;
  111.         case 'z':
  112.             translate(0.0, 0.0, tdir);
  113.             break;
  114.         case '-':
  115.             tdir = -tdir;
  116.  
  117.             if (scal < 1.0)
  118.                 scal = 1.0 + SCAL;
  119.             else
  120.                 scal = 1.0 - SCAL;
  121.  
  122.             break;
  123.         case '+':
  124.             tdir = TRANS;
  125.             break;
  126.         case 27: /* ESC */
  127.         case 'q':
  128.             vexit();
  129.             exit(0);
  130.         default:
  131.             ;
  132.         }
  133.     }
  134.  
  135.     vexit();
  136. }
  137.  
  138. makecube(obj)
  139.     int    obj;
  140. {
  141.     makeobj(obj);
  142.         if (obj == OUTLINE) {
  143.             pushattributes();
  144.             polyfill(0);
  145.             polyhatch(0);
  146.             color(BLACK);
  147.         }
  148.  
  149.         pushmatrix();
  150.             translate(0.0, 0.0, CUBE_SIZE);
  151.             if (obj == FILLED)
  152.                 color(RED);
  153.  
  154.             callobj(FACE);
  155.         popmatrix();
  156.  
  157.         pushmatrix();
  158.             translate(CUBE_SIZE, 0.0, 0.0);
  159.             rotate(90.0, 'y');
  160.             if (obj == FILLED)
  161.                 color(GREEN);
  162.  
  163.             callobj(FACE);
  164.         popmatrix();
  165.  
  166.         pushmatrix();
  167.             translate(0.0, 0.0, -CUBE_SIZE);
  168.             rotate(180.0, 'y');
  169.             if (obj == FILLED)
  170.                 color(BLUE);
  171.  
  172.             callobj(FACE);
  173.         popmatrix();
  174.  
  175.         pushmatrix();
  176.             translate(-CUBE_SIZE, 0.0, 0.0);
  177.             rotate(-90.0, 'y');
  178.             if (obj == FILLED)
  179.                 color(CYAN);
  180.  
  181.             callobj(FACE);
  182.         popmatrix();
  183.  
  184.         pushmatrix();
  185.             translate(0.0, CUBE_SIZE, 0.0);
  186.             rotate(-90.0, 'x');
  187.             if (obj == FILLED)
  188.                 color(MAGENTA);
  189.  
  190.             callobj(FACE);
  191.         popmatrix();
  192.  
  193.         pushmatrix();
  194.             translate(0.0, -CUBE_SIZE, 0.0);
  195.             rotate(90.0, 'x');
  196.             if (obj == FILLED)
  197.                 color(YELLOW);
  198.  
  199.             callobj(FACE);
  200.         popmatrix();
  201.  
  202.         if (obj == OUTLINE)
  203.             popattributes();
  204.         
  205.     closeobj();
  206. }
  207.