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

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. #ifdef    TC
  5. #define    poly    _poly
  6. #endif 
  7.  
  8. #include <math.h>
  9.  
  10. #ifdef TC
  11. #undef    poly
  12. #define    poly    poly
  13. #endif
  14.  
  15. #define RADIUS    10.0
  16. #define    SPHERE    1
  17.  
  18. /*
  19.  * most of the things in this program have been done before but it has
  20.  * a certain novelty value.
  21.  */
  22. main()
  23. {
  24.     int    i;
  25.     float    r, z, a;
  26.  
  27.     vinit("mswin");
  28.     vdevice.clipoff = 1;
  29.  
  30.     font("futura.m");
  31.  
  32.     perspective(80.0, 1.0, 0.001, 50.0);
  33.     lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0.0);
  34.  
  35.     color(BLACK);
  36.     clear();
  37.  
  38.     makesphere();
  39.  
  40.     /*
  41.      * draw the main one in cyan
  42.      */
  43.     color(CYAN);
  44.  
  45.     callobj(SPHERE);
  46.  
  47.     /*
  48.      * draw a smaller one outside the main one in white
  49.      */
  50.     color(WHITE);
  51.  
  52.     pushmatrix();
  53.         translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  54.         scale(0.3, 0.3, 0.3);
  55.         callobj(SPHERE);
  56.     popmatrix();
  57.  
  58.     /*
  59.      * scale the text
  60.      */
  61.     boxfit(2.0 * PI * RADIUS, 0.25 * RADIUS, 31);
  62.  
  63.     /*
  64.      * now write the text in rings around the main sphere
  65.      */
  66.  
  67.     color(GREEN);
  68.     showroundtext("Around the world in eighty days ");
  69.  
  70.     color(BLUE);
  71.     /*
  72.      * note: that software text is rotated here as
  73.      * anything else would be whether you use textang
  74.      * or rotate depends on what you are trying to do.
  75.      * Experience is the best teacher here.
  76.      */
  77.     rotate(90.0, 'x');
  78.     showroundtext("Around the world in eighty days ");
  79.  
  80.     color(RED);
  81.     rotate(90.0, 'z');
  82.     showroundtext("Around the world in eighty days ");
  83.  
  84.     getkey();
  85.  
  86.     vexit();
  87. }
  88.  
  89. /*
  90.  * showroundtext
  91.  *
  92.  *    draw string str wrapped around a circle in 3d
  93.  */
  94. showroundtext(str)
  95.     char    *str;
  96. {
  97.     float    i, inc;
  98.  
  99.     inc = 360.0 / (float)strlen(str);
  100.  
  101.     for (i = 0; i < 360.0; i += inc) {
  102.         pushmatrix();
  103.             /*
  104.              * find the spot on the edge of the sphere
  105.              * by making it (0, 0, 0) in world coordinates
  106.              */
  107.             rotate(i, 'y');
  108.             translate(0.0, 0.0, RADIUS);
  109.  
  110.             move(0.0, 0.0, 0.0);
  111.  
  112.             drawchar(*str++);
  113.         popmatrix();
  114.     }
  115. }
  116.  
  117. /*
  118.  * makesphere
  119.  *
  120.  *    create the sphere object
  121.  */
  122. makesphere()
  123. {
  124.     float    i, r, z, a;
  125.  
  126.     makeobj(SPHERE);
  127.  
  128.         for (i = 0; i < 180; i += 20) {
  129.             pushmatrix();
  130.                 rotate(i, 'y');
  131.                 circle(0.0, 0.0, RADIUS);
  132.             popmatrix();
  133.         }
  134.         
  135.         pushmatrix();
  136.             rotate(90.0, 'x');
  137.             for (a = -90.0; a < 90.0; a += 20.0) {
  138.                 r = RADIUS * cos((double)a * PI / 180.0);
  139.                 z = RADIUS * sin((double)a * PI / 180.0);
  140.                 pushmatrix();
  141.                     translate(0.0, 0.0, -z);
  142.                     circle(0.0, 0.0, r);
  143.                 popmatrix();    
  144.             }
  145.         popmatrix();
  146.  
  147.     closeobj();
  148. }
  149.