home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / amivogl-1.03.lzh / vogl / examples / lcube.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  3.6 KB  |  197 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #ifdef SGI
  5. #include "gl.h"
  6. #include "device.h"
  7. #include "hershey.h"
  8. #else
  9. #include "vogl.h"
  10. #include "vodevice.h"
  11. #endif
  12.  
  13. /* ---------------------------------------------------------------------
  14.  * Definitions:
  15.  */
  16.  
  17. #define    CUBE_SIZE    200.0
  18. #define    TRANS        25.0
  19. #define    SCAL        0.1
  20.  
  21. /* ---------------------------------------------------------------------
  22.  * Prototypes:
  23.  */
  24. int main(void);                                        /* lcube.c         */
  25. int makecubes(int);                                    /* lcube.c         */
  26.  
  27.  
  28. /* ---------------------------------------------------------------------
  29.  * Source Code:
  30.  */
  31.  
  32. int main(void)
  33. {
  34.         char    *p;
  35.     float    tdir = TRANS;
  36.     float    scal = 1.0 + SCAL;
  37.     int    but, nplanes;
  38.     int    x, y, i, n;
  39.     short    val;
  40.  
  41.     prefsize(500L, 500L);
  42.  
  43.     winopen("lcube");
  44.  
  45.     unqdevice(INPUTCHANGE);
  46.     qdevice(SKEY);
  47.     qdevice(XKEY);
  48.     qdevice(YKEY);
  49.     qdevice(ZKEY);
  50.     qdevice(EQUALKEY);
  51.     qdevice(MINUSKEY);
  52.     qdevice(ESCKEY);
  53.     qdevice(QKEY);
  54.     
  55.  
  56.     window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
  57.     lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);
  58.  
  59.     if ((nplanes = getplanes()) == 1)
  60.         makecubes(0);
  61.  
  62.     makecubes(1);
  63.  
  64.     backface(1);
  65.         
  66.     doublebuffer();
  67.     gconfig();
  68.  
  69.     /*
  70.      * Doublebuffer does a backbuffer(TRUE)....
  71.      */
  72.  
  73.     while(1) {
  74.         x = 500 - (int)getvaluator(MOUSEX);
  75.         y = 500 - (int)getvaluator(MOUSEY);
  76.         x *= 3;
  77.         y *= 3;
  78.         pushmatrix();
  79.             rotate(x, 'y');
  80.             rotate(y, 'x');
  81.             color(BLACK);
  82.             clear();
  83.             callobj((Object)3);
  84.             if (nplanes == 1)
  85.                 callobj((Object)2);
  86.         popmatrix();
  87.         swapbuffers();
  88.  
  89.         if (qtest()) {
  90.             but = qread(&val);
  91.             but = qread(&val);    /* swallow up event */
  92.  
  93.             switch (but) {
  94.  
  95.             case SKEY:
  96.                 scale(scal, scal, scal);
  97.                 break;
  98.             case XKEY:
  99.                 translate(tdir, 0.0, 0.0);
  100.                 break;
  101.             case YKEY:
  102.                 translate(0.0, tdir, 0.0);
  103.                 break;
  104.             case ZKEY:
  105.                 translate(0.0, 0.0, tdir);
  106.                 break;
  107.             case MINUSKEY:
  108.                 tdir = -tdir;
  109.  
  110.                 if (scal < 1.0)
  111.                     scal = 1.0 + SCAL;
  112.                 else
  113.                     scal = 1.0 - SCAL;
  114.  
  115.                 break;
  116.             case EQUALKEY:
  117.                 tdir = TRANS;
  118.                 break;
  119.             case ESCKEY:
  120.             case QKEY:
  121.                 gexit();
  122.                 exit(0);
  123.             default:
  124.                 ;
  125.             }
  126.         }
  127.     }
  128. }
  129.  
  130. int makecubes(int fill)
  131. {
  132.     makeobj((Object)(fill + 2));
  133.         if (!fill)
  134.             color(BLACK);
  135.  
  136.         pushmatrix();
  137.             translate(0.0, 0.0, CUBE_SIZE);
  138.             if (fill) {
  139.                 color(RED);
  140.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  141.             } else
  142.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  143.         popmatrix();
  144.  
  145.         pushmatrix();
  146.             translate(CUBE_SIZE, 0.0, 0.0);
  147.             rotate(900, 'y');
  148.             if (fill) {
  149.                 color(GREEN);
  150.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  151.             } else
  152.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  153.         popmatrix();
  154.  
  155.         pushmatrix();
  156.             translate(0.0, 0.0, -CUBE_SIZE);
  157.             rotate(1800, 'y');
  158.             if (fill) {
  159.                 color(BLUE);
  160.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  161.             } else 
  162.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  163.         popmatrix();
  164.  
  165.         pushmatrix();
  166.             translate(-CUBE_SIZE, 0.0, 0.0);
  167.             rotate(-900, 'y');
  168.             if (fill) {
  169.                 color(CYAN);
  170.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  171.             } else
  172.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  173.         popmatrix();
  174.  
  175.         pushmatrix();
  176.             translate(0.0, CUBE_SIZE, 0.0);
  177.             rotate(-900, 'x');
  178.             if (fill) {
  179.                 color(MAGENTA);
  180.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  181.             } else
  182.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  183.         popmatrix();
  184.  
  185.         pushmatrix();
  186.             translate(0.0, -CUBE_SIZE, 0.0);
  187.             rotate(900, 'x');
  188.             if (fill) {
  189.                 color(YELLOW);
  190.                 rectf(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  191.             } else
  192.                 rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
  193.         popmatrix();
  194.  
  195.     closeobj();
  196. }
  197.