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