home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / EXAMPLES / PBALLS.P < prev    next >
Text File  |  2000-02-11  |  3KB  |  157 lines

  1. program balls;
  2.  
  3. #include 'Vogle.h'
  4.  
  5. const
  6.     RADIUS = 10.0;
  7.     SPHERE = 1;
  8.     PI     = 3.14159265358979;
  9. var
  10.     dev: string_t;
  11.     dum: integer;
  12.  
  13.     (*
  14.      * makesphere
  15.      *
  16.      *    make a sphere object
  17.      *)
  18.     procedure makesphere;
  19.  
  20.         var    ir, r, z, a: real;
  21.             i: integer;
  22.     begin
  23.  
  24.         MakeObj(SPHERE);
  25.  
  26.             (*
  27.              * create the latitudinal rings
  28.              *)
  29.             for i := 0 to 9 do
  30.             begin
  31.                 ir := i * 20.0;
  32.                 PushMatrix;
  33.                     Rotate(ir, 'y');
  34.                     Circle(0.0, 0.0, RADIUS);
  35.                 PopMatrix
  36.             end;
  37.             
  38.             (*
  39.              * create the longitudinal rings
  40.              *)
  41.             PushMatrix;
  42.                 Rotate(90.0, 'x');
  43.                 for i := 0 to 9 do
  44.                 begin
  45.                     a := -90.0 + i * 20.0;
  46.                     r := RADIUS * cos(a * PI / 180.0);
  47.                     z := RADIUS * sin(a * PI / 180.0);
  48.                     PushMatrix;
  49.                         Translate(0.0, 0.0, -z);
  50.                         Circle(0.0, 0.0, r);
  51.                     PopMatrix
  52.                 end;
  53.             PopMatrix;
  54.  
  55.         CloseObj
  56.     end;
  57.  
  58. (*
  59.  * a demonstration of objects
  60.  *)
  61. begin
  62.  
  63.     write('Enter device: ');
  64.     readln(dev);
  65.  
  66.     Vinit(dev);
  67.     VsetFlush(false);
  68.  
  69.     (*
  70.      * set up our viewing transformation
  71.      *)
  72.     Perspective(90.0, 1.0, 0.001, 500.0);
  73.     LookAt(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0.0);
  74.  
  75.     Color(BLACK);
  76.     Clear;
  77.  
  78.     (*
  79.      * Call a routine to make the sphere object
  80.      *)
  81.     makesphere;
  82.  
  83.     (*
  84.      * Now draw the sphere object scaled down. We use the pushmatrix
  85.      * and the popmatrix to preserve the transformation matrix so
  86.      * that only this sphere is drawn scaled.
  87.      *)
  88.     Color(CYAN);
  89.  
  90.     PushMatrix;
  91.         Scale(0.5, 0.5, 0.5);
  92.         CallObj(SPHERE);
  93.     PopMatrix;
  94.  
  95.     (*
  96.      * now we draw the same sphere translated, with a different
  97.      * scale and color.
  98.      *)
  99.  
  100.     Color(WHITE);
  101.  
  102.     PushMatrix;
  103.         Translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  104.         Scale(0.3, 0.3, 0.3);
  105.         CallObj(SPHERE);
  106.     PopMatrix;
  107.  
  108.     (*
  109.      * and maybe a few more times....
  110.      *)
  111.  
  112.  
  113.     Color(RED);
  114.  
  115.     PushMatrix;
  116.         Translate(0.0, RADIUS, 0.7 * RADIUS);
  117.         Scale(0.2, 0.2, 0.2);
  118.         CallObj(SPHERE);
  119.     PopMatrix;
  120.  
  121.     Color(GREEN);
  122.  
  123.     PushMatrix;
  124.         Translate(0.0, 1.5 * RADIUS, -RADIUS);
  125.         Scale(0.15, 0.15, 0.15);
  126.         CallObj(SPHERE);
  127.     PopMatrix;
  128.  
  129.     Color(YELLOW);
  130.  
  131.     PushMatrix;
  132.         Translate(0.0, -RADIUS, -RADIUS);
  133.         Scale(0.12, 0.12, 0.12);
  134.         CallObj(SPHERE);
  135.     PopMatrix;
  136.  
  137.     Color(BLUE);
  138.  
  139.     PushMatrix;
  140.         Translate(0.0, -2.0*RADIUS, -RADIUS);
  141.         Scale(0.3, 0.3, 0.3);
  142.         CallObj(SPHERE);
  143.     PopMatrix;
  144.  
  145.     Font('times.rb');
  146.     Ortho2(0.0, 1.0, 0.0, 1.0);
  147.     CenterText(true);
  148.     TextSize(0.08, 0.15);
  149.     Move2(0.8, 0.5);
  150.     TextAng(-90.0);
  151.     DrawStr('I''m very ordinary!');
  152.  
  153.     dum := GetKey;
  154.  
  155.     Vexit
  156. end.
  157.