home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / OBJVWS.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  3KB  |  172 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.     vinit("mswin");
  17.     pushviewport();
  18.  
  19.     textsize(0.5, 0.9);
  20.     font("futura.m");
  21.  
  22.     color(BLACK);
  23.     clear();
  24.  
  25.     makecube();
  26.  
  27.     /*
  28.      * set up an object which draws in the top left of the screen.
  29.      */
  30.     makeobj(TOPLEFT);
  31.         viewport(-1.0, 0.0, 0.0, 1.0);
  32.         ortho2(-5.0, 5.0, -5.0, 5.0);
  33.  
  34.         color(RED);
  35.  
  36.         rect(-5.0, -5.0, 5.0, 5.0);
  37.  
  38.         perspective(40.0, 1.0, 0.1, 1000.0);
  39.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  40.  
  41.         callobj(CUBE);
  42.  
  43.         color(GREEN);
  44.  
  45.         move2(-4.5, -4.5);
  46.         drawstr("perspective/lookat");
  47.     closeobj();
  48.  
  49.     /*
  50.      * now set up one which draws in the top right of the screen
  51.      */
  52.     makeobj(TOPRIGHT);
  53.         viewport(0.0, 1.0, 0.0, 1.0);
  54.         ortho2(-5.0, 5.0, -5.0, 5.0);
  55.  
  56.         color(GREEN);
  57.  
  58.         rect(-5.0, -5.0, 5.0, 5.0);
  59.  
  60.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  61.         lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  62.  
  63.         callobj(CUBE);
  64.  
  65.         color(RED);
  66.  
  67.         move2(-4.5, -4.5);
  68.         drawstr("window/lookat");
  69.     closeobj();
  70.  
  71.     /*
  72.      * try the bottom left
  73.      */
  74.     makeobj(BOTTOMLEFT);
  75.         viewport(-1.0, 0.0, -1.0, 0.0);
  76.         ortho2(-5.0, 5.0, -5.0, 5.0);
  77.  
  78.         color(MAGENTA);
  79.  
  80.         rect(-5.0, -5.0, 5.0, 5.0);
  81.  
  82.         perspective(40.0, 1.0, 0.1, 1000.0);
  83.         polarview(15.0, 30.0, 30.0, 30.0);
  84.  
  85.         callobj(CUBE);
  86.  
  87.         color(YELLOW);
  88.  
  89.         move2(-4.5, -4.5);
  90.         drawstr("perspective/polarview");
  91.     closeobj();
  92.  
  93.     /*
  94.      * and the bottom right
  95.      */
  96.     makeobj(BOTTOMRIGHT);
  97.         viewport(0.0, 1.0, -1.0, 0.0);
  98.         ortho2(-5.0, 5.0, -5.0, 5.0);
  99.  
  100.         color(CYAN);
  101.  
  102.         rect(-5.0, -5.0, 5.0, 5.0);
  103.  
  104.         window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  105.         polarview(8.0, -18.0, -3.0, 18.0);
  106.  
  107.         callobj(CUBE);
  108.  
  109.         color(BLUE);
  110.  
  111.         move2(-4.5, -4.5);
  112.         drawstr("window/polarview");
  113.     closeobj();
  114.  
  115.     /*
  116.      * now draw them
  117.      */
  118.     callobj(TOPLEFT);
  119.     callobj(TOPRIGHT);
  120.     callobj(BOTTOMLEFT);
  121.     callobj(BOTTOMRIGHT);
  122.  
  123.     getkey();
  124.  
  125.     vexit();
  126. }
  127.  
  128. /*
  129.  * makecube
  130.  *
  131.  *    set up a cube
  132.  */
  133. makecube()
  134. {
  135.  
  136.     makeobj(CUBE);
  137.  
  138.         /*
  139.          * The border around the cube
  140.          */
  141.         rect(-5.0, -5.0, 10.0, 10.0);
  142.  
  143.         /*
  144.          * Make the cube from 4 squares
  145.          */
  146.         pushmatrix();
  147.             side();
  148.             rotate(90.0, 'x');
  149.             side();
  150.             rotate(90.0, 'x');
  151.             side();
  152.             rotate(90.0, 'x');
  153.             side();
  154.         popmatrix();
  155.  
  156.     closeobj();
  157. }
  158.  
  159. /*
  160.  * side
  161.  *
  162.  *    define a face for the cube
  163.  */
  164. side()
  165. {
  166.     pushmatrix();
  167.         translate(0.0, 0.0, 1.0);
  168.         rect(-1.0, -1.0, 1.0, 1.0);
  169.     popmatrix();
  170. }
  171.  
  172.