home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / VIEWS.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  3KB  |  155 lines

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. /*
  5.  *    Shows various combinations of viewing and
  6.  *    projection transformations.
  7.  */
  8. main()
  9. {
  10.     vinit("mswin");
  11.  
  12.     color(BLACK);
  13.     clear();
  14.  
  15.     /*
  16.      * we want to draw just within the boundaries of the screen
  17.      */
  18.     viewport(-0.9, 0.9, -0.9, 0.9);
  19.  
  20.  
  21.     ortho2(-5.0, 5.0, -5.0, 5.0);    /* set the world size */
  22.  
  23.     color(RED);
  24.     rect(-5.0, -5.0, 5.0, 5.0);    /* draw a boundary frame */
  25.  
  26.     /*
  27.      * set up a perspective projection with a field of view of
  28.      * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
  29.      * and the far clipping plane at 1000.0.
  30.      */
  31.     perspective(40.0, 1.0, 0.1, 1000.0);
  32.  
  33.     /*
  34.      * we want the drawing to be done with our eye point at (5.0, 8.0, 5.0)
  35.      * looking towards (0.0, 0.0, 0.0). The last parameter gives a twist
  36.      * in degrees around the line of sight, in this case zero.
  37.      */
  38.     lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  39.  
  40.     drawtetra();
  41.  
  42.     move2(-4.5, -4.5);
  43.     textsize(0.6, 0.9);        /* set the text size */
  44.     drawstr("perspective/lookat");
  45.  
  46.     getkey();
  47.  
  48.     /*
  49.      * window can also be used to give a perspective projection. Its
  50.      * arguments are 6 clipping planes, left, right, bottom, top, near,
  51.      * and far.
  52.      */
  53.     window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  54.     /*
  55.      * as window replaces the current transformation matrix we must
  56.      * specify our viewpoint again.
  57.      */
  58.     lookat(5.0, 8.0, 5.0, 0.0, 0.0, 0.0, 0.0);
  59.  
  60.     color(BLACK);
  61.     clear();
  62.  
  63.     color(GREEN);
  64.     rect(-5.0, -5.0, 5.0, 5.0);
  65.  
  66.     drawtetra();
  67.  
  68.     move2(-4.5,-4.5);
  69.     textsize(0.6, 0.9);        /* set the text size */
  70.     drawstr("window/lookat");
  71.  
  72.     getkey();
  73.  
  74.     /*
  75.      * set up our original perspective projection again.
  76.      */
  77.     perspective(40.0, 1.0, 0.1, 1000.0);
  78.     /*
  79.      * polarview also specifies our viewpoint, but, unlike lookat, in polar
  80.      * coordinates. Its arguments are the distance from the world origin, an
  81.      * azimuthal angle in the x-y plane measured from the y axis, an 
  82.      * incidence angle in the y-z plane measured from the z axis, and a
  83.      * twist around the line of sight.
  84.      */
  85.     polarview(15.0, 30.0, 30.0, 30.0);
  86.  
  87.     color(BLACK);
  88.     clear();
  89.  
  90.     color(MAGENTA);
  91.     rect(-5.0, -5.0, 5.0, 5.0);
  92.  
  93.     drawtetra();
  94.  
  95.     move2(-4.5,-4.5);
  96.     textsize(0.6, 0.9);        /* set the text size */
  97.     drawstr("perspective/polarview");
  98.  
  99.     getkey();
  100.  
  101.     /*
  102.      * once more with window for comparison
  103.      */
  104.     window(-4.0, 4.0, -4.0, 4.0, -4.0, 4.0);
  105.     polarview(6.0, 20.0, -30.0, 70.0);
  106.  
  107.     color(BLACK);
  108.     clear();
  109.  
  110.     color(YELLOW);
  111.     rect(-5.0, -5.0, 5.0, 5.0);
  112.  
  113.     drawtetra();
  114.  
  115.     move2(-4.5,-4.5);
  116.     textsize(0.6, 0.9);        /* set the text size */
  117.     drawstr("window/polarview");
  118.  
  119.     getkey();
  120.  
  121.     vexit();
  122. }
  123.  
  124. /*
  125.  * drawtetra
  126.  *
  127.  *    generate a tetraedron as a series of move draws
  128.  */
  129. drawtetra()
  130. {
  131.     
  132.     move(-0.5,  0.866, -0.5);
  133.     draw(-0.5, -0.866, -0.5);
  134.     draw( 1.0,  0.0,   -0.5);
  135.     draw(-0.5,  0.866, -0.5);
  136.     draw( 0.0,  0.0,    1.5);
  137.     draw(-0.5, -0.866, -0.5);
  138.     move( 1.0,  0.0,   -0.5);
  139.     draw( 0.0,  0.0,    1.5);
  140.     
  141.     /* 
  142.      * Label the vertices.
  143.      */
  144.     color(WHITE);
  145.     textsize(0.3, 0.5);        /* set the text size */
  146.     move(-0.5,  0.866, -0.5);
  147.     drawchar('a');
  148.     move(-0.5, -0.866, -0.5);
  149.     drawchar('b');
  150.     move( 1.0,  0.0,   -0.5);
  151.     drawchar('c');
  152.     move( 0.0,  0.0,    1.5);
  153.     drawchar('d');
  154. }
  155.