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

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. extern double    sin(), cos();
  5.  
  6. /*
  7.  * A program showing basic line styles.
  8.  */
  9. main()
  10. {
  11.     char    device[20];
  12.  
  13.     fprintf(stderr,"Enter output device: ");
  14.     gets(device);
  15.  
  16.     vinit(device);        /* set up device */
  17.     vsetflush(0);
  18.     linewidth(THICK);
  19.     up(0.0, 1.0, 0.0);
  20.     perspective(90.0, 1.0, 0.3, 3.0);
  21.     translate(0.0, 0.0, -1.3);
  22.  
  23.     drawscene();
  24.     rotate(-30.0, 'y');
  25.     rotate(-30.0, 'x');
  26.     linestyle("");
  27.     drawscene();
  28.  
  29.     vexit();        /* set the screen back to its original state */
  30. }
  31.  
  32. drawscene()
  33. {
  34.     color(BLACK);        /* set current color */
  35.     clear();        /* clear screen to current color */
  36.  
  37.     color(GREEN);
  38.     setdash(0.03);
  39.             /* 2 d move to start where we want drawstr to start */
  40.  
  41.     xcentertext();
  42.     move2(-0.45, 0.9);
  43.     drawstr("Linestyle: \"10\"");
  44.     move2(-0.45, 0.7);
  45.     drawstr("Linestyle: \"110\"");
  46.     move2(-0.45, 0.5);
  47.     drawstr("Linestyle: \"111010\"");
  48.     move2(-0.45, 0.3);
  49.     drawstr("Linestyle: \"0001\"");
  50.  
  51.     linestyle("10");
  52.     move2(-0.9, 0.9);
  53.     draw2( 0.0, 0.9);
  54.     circle(0.6, 0.6, 0.4);    /* Should be pi * 0.2 /0.03 dashes ~= 21 */
  55.  
  56.     drawbox(0.9);
  57.     drawsine(0.9);
  58.  
  59.     color(RED);
  60.     linestyle("110");
  61.     move2(-0.9, 0.7);
  62.     draw2( 0.0, 0.7);
  63.     circle(0.6, 0.6, 0.3);
  64.     drawbox(0.7);
  65.     drawsine(0.7);
  66.  
  67.     color(CYAN);
  68.     linestyle("111010");
  69.     move2(-0.9, 0.5);
  70.     draw2( 0.0, 0.5);
  71.     circle(0.6, 0.6, 0.2);
  72.     drawbox(0.5);
  73.     drawsine(0.5);
  74.  
  75.     color(YELLOW);
  76.     linestyle("0001");
  77.     move2(-0.9, 0.3);
  78.     draw2( 0.0, 0.3);
  79.     circle(0.6, 0.6, 0.1);
  80.     drawbox(0.3);
  81.     drawsine(0.3);
  82.  
  83.     getkey();        /* wait for some input */
  84.  
  85. }
  86.  
  87. drawbox(s)
  88.     float    s;
  89. {
  90.     pushmatrix();
  91.  
  92.     rotate(30.0, 'x');
  93.     rotate(60.0, 'y');
  94.     translate(-0.7, -1.2, 0.0);
  95.     scale(s, s, s);
  96.  
  97.     move(0.0, 0.0, 0.0);
  98.  
  99.     draw(1.0, 0.0, 0.0);
  100.     draw(1.0, 1.0, 0.0);
  101.     draw(0.0, 1.0, 0.0);
  102.     draw(0.0, 0.0, 0.0);
  103.  
  104.     draw(0.0, 0.0, -1.0);
  105.     draw(1.0, 0.0, -1.0);
  106.     draw(1.0, 1.0, -1.0);
  107.     draw(0.0, 1.0, -1.0);
  108.     draw(0.0, 0.0, -1.0);
  109.  
  110.     move(0.0, 1.0, -1.0);
  111.     draw(0.0, 1.0, 0.0);
  112.  
  113.     move(1.0, 1.0, 0.0);
  114.     draw(1.0, 1.0, -1.0);
  115.  
  116.     move(1.0, 0.0, 0.0);
  117.     draw(1.0, 0.0, -1.0);
  118.  
  119.     popmatrix();
  120. }
  121.  
  122. #define RAD 0.5
  123. #define AMP 0.03
  124.  
  125. drawsine(s)
  126.     float    s;
  127. {
  128.     float    a, x, y, z;
  129.     int    i;
  130.  
  131.     pushmatrix();
  132.  
  133.     translate(RAD + 0.2, -0.5, 0.0);
  134.     scale(s, s, s);
  135.  
  136.     move(RAD, 0.0, 0.0);
  137.     for (a = 0.0; a <= 2 * 3.1415926; a += 0.02) {
  138.         x = RAD * cos(a);
  139.         z = RAD * sin(a);
  140.         y = AMP * sin(a * 6.0);
  141.  
  142.         draw(x, y, z);
  143.     }
  144.  
  145.     popmatrix();
  146. }
  147.