home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / EXAMPLES / OS2PM / LSTYLES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-01  |  2.2 KB  |  139 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.     vinit("os2pm");        /* set up device */
  12.     up(0.0, 1.0, 0.0);
  13.     perspective(90.0, 1.0, 0.3, 3.0);
  14.     translate(0.0, 0.0, -1.3);
  15.  
  16.     drawscene();
  17.     rotate(-30.0, 'y');
  18.     rotate(-30.0, 'x');
  19.     drawscene();
  20.  
  21.     vexit();        /* set the screen back to its original state */
  22. }
  23.  
  24. drawscene()
  25. {
  26.     color(BLACK);        /* set current color */
  27.     clear();        /* clear screen to current color */
  28.  
  29.     color(GREEN);
  30.     setdash(0.03);
  31.             /* 2 d move to start where we want drawstr to start */
  32.  
  33.     xcentertext();
  34.     move2(-0.45, 0.9);
  35.     drawstr("Linestyle: \"10\"");
  36.     move2(-0.45, 0.7);
  37.     drawstr("Linestyle: \"110\"");
  38.     move2(-0.45, 0.5);
  39.     drawstr("Linestyle: \"111010\"");
  40.     move2(-0.45, 0.3);
  41.     drawstr("Linestyle: \"0001\"");
  42.  
  43.     linestyle("10");
  44.     move2(-0.9, 0.9);
  45.     draw2( 0.0, 0.9);
  46.     circle(0.6, 0.6, 0.4);    /* Should be pi * 0.2 /0.03 dashes ~= 21 */
  47.  
  48.     drawbox(0.9);
  49.     drawsine(0.9);
  50.  
  51.     color(RED);
  52.     linestyle("110");
  53.     move2(-0.9, 0.7);
  54.     draw2( 0.0, 0.7);
  55.     circle(0.6, 0.6, 0.3);
  56.     drawbox(0.7);
  57.     drawsine(0.7);
  58.  
  59.     color(CYAN);
  60.     linestyle("111010");
  61.     move2(-0.9, 0.5);
  62.     draw2( 0.0, 0.5);
  63.     circle(0.6, 0.6, 0.2);
  64.     drawbox(0.5);
  65.     drawsine(0.5);
  66.  
  67.     color(YELLOW);
  68.     linestyle("0001");
  69.     move2(-0.9, 0.3);
  70.     draw2( 0.0, 0.3);
  71.     circle(0.6, 0.6, 0.1);
  72.     drawbox(0.3);
  73.     drawsine(0.3);
  74.  
  75.     getkey();        /* wait for some input */
  76.  
  77. }
  78.  
  79. drawbox(s)
  80.     float    s;
  81. {
  82.     pushmatrix();
  83.  
  84.     rotate(30.0, 'x');
  85.     rotate(60.0, 'y');
  86.     translate(-0.7, -1.2, 0.0);
  87.     scale(s, s, s);
  88.  
  89.     move(0.0, 0.0, 0.0);
  90.  
  91.     draw(1.0, 0.0, 0.0);
  92.     draw(1.0, 1.0, 0.0);
  93.     draw(0.0, 1.0, 0.0);
  94.     draw(0.0, 0.0, 0.0);
  95.  
  96.     draw(0.0, 0.0, -1.0);
  97.     draw(1.0, 0.0, -1.0);
  98.     draw(1.0, 1.0, -1.0);
  99.     draw(0.0, 1.0, -1.0);
  100.     draw(0.0, 0.0, -1.0);
  101.  
  102.     move(0.0, 1.0, -1.0);
  103.     draw(0.0, 1.0, 0.0);
  104.  
  105.     move(1.0, 1.0, 0.0);
  106.     draw(1.0, 1.0, -1.0);
  107.  
  108.     move(1.0, 0.0, 0.0);
  109.     draw(1.0, 0.0, -1.0);
  110.  
  111.     popmatrix();
  112. }
  113.  
  114. #define RAD 0.5
  115. #define AMP 0.03
  116.  
  117. drawsine(s)
  118.     float    s;
  119. {
  120.     float    a, x, y, z;
  121.     int    i;
  122.  
  123.     pushmatrix();
  124.  
  125.     translate(RAD + 0.2, -0.5, 0.0);
  126.     scale(s, s, s);
  127.  
  128.     move(RAD, 0.0, 0.0);
  129.     for (a = 0.0; a <= 2 * 3.1415926; a += 0.02) {
  130.         x = RAD * cos(a);
  131.         z = RAD * sin(a);
  132.         y = AMP * sin(a * 6.0);
  133.  
  134.         draw(x, y, z);
  135.     }
  136.  
  137.     popmatrix();
  138. }
  139.