home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / avogl.tar.gz / avogl.tar / vogl / examples / world.c < prev   
C/C++ Source or Header  |  1992-09-22  |  2KB  |  153 lines

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