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

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4.  
  5. #define        CUBE        1
  6. #define        TOPLEFT        2
  7. #define        TOPRIGHT    3
  8. #define        BOTTOMLEFT    4
  9. #define        BOTTOMRIGHT    5
  10.  
  11. /*
  12.  * Demonstrate just how much you can put in an object
  13.  */
  14. main()
  15. {
  16.     char device[20];
  17.  
  18.     fprintf(stderr,"Enter device name: ");
  19.     gets(device);
  20.     vinit(device);
  21.     pushviewport();
  22.  
  23.     textsize(0.5, 0.9);
  24.     font("futura.m");
  25.  
  26.     color(BLACK);
  27.     clear();
  28.  
  29.     makecube();
  30.  
  31.     /*
  32.      * set up an object which draws in the top left of the screen.
  33.      */
  34.     makeobj(TOPLEFT);
  35.         viewport(-1.0, 0.0, 0.0, 1.0);
  36.         ortho2(-5.0, 5.0, -5.0, 5.0);
  37.  
  38.         color(RED);
  39.  
  40.         rect(-5.0, -5.0, 5.0, 5.0);
  41.  
  42.         perspective(40.0, 1.0, 0.1, 1000.0);
  43.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  44.  
  45.         callobj(CUBE);
  46.  
  47.         color(GREEN);
  48.  
  49.         move2(-4.5, -4.5);
  50.         drawstr("perspective/lookat");
  51.     closeobj();
  52.  
  53.     /*
  54.      * now set up one which draws in the top right of the screen
  55.      */
  56.     makeobj(TOPRIGHT);
  57.         viewport(0.0, 1.0, 0.0, 1.0);
  58.         ortho2(-5.0, 5.0, -5.0, 5.0);
  59.  
  60.         color(GREEN);
  61.  
  62.         rect(-5.0, -5.0, 5.0, 5.0);
  63.  
  64.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  65.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  66.  
  67.         callobj(CUBE);
  68.  
  69.         color(RED);
  70.  
  71.         move2(-4.5, -4.5);
  72.         drawstr("window/lookat");
  73.     closeobj();
  74.  
  75.     /*
  76.      * try the bottom left
  77.      */
  78.     makeobj(BOTTOMLEFT);
  79.         viewport(-1.0, 0.0, -1.0, 0.0);
  80.         ortho2(-5.0, 5.0, -5.0, 5.0);
  81.  
  82.         color(MAGENTA);
  83.  
  84.         rect(-5.0, -5.0, 5.0, 5.0);
  85.  
  86.         perspective(40.0, 1.0, 0.1, 1000.0);
  87.         polarview(15.0, 30.0, 30.0, 30.0);
  88.  
  89.         callobj(CUBE);
  90.  
  91.         color(YELLOW);
  92.  
  93.         move2(-4.5, -4.5);
  94.         drawstr("perspective/polarview");
  95.     closeobj();
  96.  
  97.     /*
  98.      * and the bottom right
  99.      */
  100.     makeobj(BOTTOMRIGHT);
  101.         viewport(0.0, 1.0, -1.0, 0.0);
  102.         ortho2(-5.0, 5.0, -5.0, 5.0);
  103.  
  104.         color(CYAN);
  105.  
  106.         rect(-5.0, -5.0, 5.0, 5.0);
  107.  
  108.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  109.         polarview(8.0, -18.0, -3.0, 18.0);
  110.  
  111.         callobj(CUBE);
  112.  
  113.         color(BLUE);
  114.  
  115.         move2(-4.5, -4.5);
  116.         drawstr("window/polarview");
  117.     closeobj();
  118.  
  119.     /*
  120.      * now draw them
  121.      */
  122.     callobj(TOPLEFT);
  123.     callobj(TOPRIGHT);
  124.     callobj(BOTTOMLEFT);
  125.     callobj(BOTTOMRIGHT);
  126.  
  127.     getkey();
  128.  
  129.     vexit();
  130. }
  131.  
  132. /*
  133.  * makecube
  134.  *
  135.  *    set up a cube
  136.  */
  137. makecube()
  138. {
  139.  
  140.     makeobj(CUBE);
  141.  
  142.         /*
  143.          * The border around the cube
  144.          */
  145.         rect(-5.0, -5.0, 10.0, 10.0);
  146.  
  147.         /*
  148.          * Make the cube from 4 squares
  149.          */
  150.         pushmatrix();
  151.             side();
  152.             rotate(90.0, 'x');
  153.             side();
  154.             rotate(90.0, 'x');
  155.             side();
  156.             rotate(90.0, 'x');
  157.             side();
  158.         popmatrix();
  159.  
  160.     closeobj();
  161. }
  162.  
  163. /*
  164.  * side
  165.  *
  166.  *    define a face for the cube
  167.  */
  168. side()
  169. {
  170.     pushmatrix();
  171.         translate(0.0, 0.0, 1.0);
  172.         rect(-1.0, -1.0, 1.0, 1.0);
  173.     popmatrix();
  174. }
  175.  
  176.