home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / amivogl-1.03.lzh / vogl / examples / world.c < prev   
Encoding:
C/C++ Source or Header  |  1994-07-16  |  2.9 KB  |  168 lines

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