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

  1. c
  2. c    Draws patches of various bases
  3. c
  4.     program fpatch
  5.  
  6.     character *20 dev
  7.  
  8.     integer BLACK, RED, GREEN, YELLOW, BLUE,
  9.      +        CYAN, WHITE
  10.     parameter (BLACK = 0, RED = 1, GREEN = 2,
  11.      +        YELLOW = 3, BLUE = 4, CYAN = 5, WHITE = 7)
  12.           
  13. c
  14. c  patch basis types
  15. c
  16.     real bezier(4,4), cardinal(4, 4), bspline(4, 4)
  17.     real power(4, 4)
  18.     real x1(4, 4), y1(4, 4), z1(4, 4)
  19.     real x2(4, 4), y2(4, 4), z2(4, 4)
  20.  
  21.     character *50 labels(4)
  22.  
  23.     real    basis(64)
  24.     equivalence (basis(1), bezier(1, 1))
  25.     equivalence (basis(17), cardinal(1, 1))
  26.     equivalence (basis(33), bspline(1, 1))
  27.     equivalence (basis(49), power(1, 1))
  28.  
  29.     data bezier/
  30.      +        -1.0,    3.0,    -3.0,    1.0,
  31.      +        3.0,    -6.0,    3.0,    0.0,
  32.      +        -3.0,    3.0,    0.0,    0.0,
  33.      +        1.0,    0.0,    0.0,    0.0/ 
  34.  
  35.     data cardinal/
  36.      +        -0.5,    1.5,    -1.5,    0.5,
  37.      +        1.0,    -2.5,    2.0,    -0.5,
  38.      +        -0.5,    0.0,    0.5,    0.0,
  39.      +        0.0,    1.0,    0.0,    0.0/
  40.  
  41.     data bspline/
  42.      +         -0.166666,     0.5,     -0.5,     0.166666,
  43.      +         0.5,          -1.0,      0.5,     0.0,
  44.      +            -0.5,          0.0,      0.5,     0.0, 
  45.      +         0.166666,     0.666666, 0.166666, 0.0 /
  46.  
  47.     data power/
  48.      +        1.0, 0.0, 0.0, 0.0,
  49.      +        0.0, 1.0, 0.0, 0.0,
  50.      +        0.0, 0.0, 1.0, 0.0,
  51.      +        0.0, 0.0, 0.0, 1.0/
  52.  
  53.     data    x1 / 
  54.      +        0.0,   0.2588,   0.5,   0.7071,
  55.      +        0.0,   0.51764,  1.0,   1.4142,
  56.      +        0.0,   0.51764,  1.0,   1.4142,
  57.      +        0.0,   0.2588,   0.5,   0.7071/
  58.  
  59.     data    y1 / 
  60.      +        1.0,   0.966,   0.866,  0.7071,
  61.      +        2.0,   1.9318,  1.732,  1.4142,
  62.      +        2.0,   1.9318,  1.732,  1.4142,
  63.      +        1.0,   0.966,   0.866,  0.7071/
  64.  
  65.     data    z1 / 
  66.      +        1.0,   1.0,     1.0,    1.0,
  67.      +        1.0,   1.0,     1.0,    1.0,
  68.      +        0.0,   0.0,     0.0,    0.0,
  69.      +        0.0,   0.0,     0.0,    0.0/
  70.  
  71.     data    x2 / 
  72.      +        0.7071, 0.8660, 0.9660, 1.0,
  73.      +        1.4142, 1.7320, 1.932,  2.0,
  74.      +        1.4142, 1.7320, 1.932,  2.0,
  75.      +        0.7071, 0.8660, 0.9660, 1.0/
  76.  
  77.     data    y2 / 
  78.      +        0.7071, 0.5,    0.2588, 0.0,
  79.      +        1.4142, 1.0,    0.5176, 0.0,
  80.      +        1.4142, 1.0,    0.5176, 0.0,
  81.      +        0.7071, 0.5,    0.2588, 0.0/
  82.  
  83.     data    z2 / 
  84.      +        1.0,   1.0,     1.0,    1.0,
  85.      +        1.0,   1.0,     1.0,    1.0,
  86.      +        0.0,   0.0,     0.0,    0.0,
  87.      +        0.0,   0.0,     0.0,    0.0/
  88.  
  89.  
  90.     data labels /
  91.      +        'Bezier Patch(es)',
  92.      +        'Cardinal Patch(es)',
  93.      +        'B-Spline Patch(es)',
  94.      +        '''Power'' Patch(es)' /
  95.  
  96. c
  97. c  demonstrate patches
  98. c
  99.  
  100.     write (*,*)'Enter device:'
  101.     read(*,'(a)') dev
  102.  
  103.     call vinit(dev)
  104.  
  105.     call vsetflush(.false.)
  106.  
  107.     call color(BLACK)
  108.     call clear
  109.  
  110. c
  111. c Set up two viewports (They actually overlap)
  112. c
  113.  
  114.     call viewport(-1.0, 0.3, -1.0, 0.3)
  115.     call ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0)
  116.     call lookat(0.0, 0.0, 0.0, -3.0, 2.0, -4.0, 0.0)
  117. c
  118. c    Save it 
  119. c
  120.     call pushviewport
  121.     call pushmatrix
  122.  
  123.     call viewport(-0.3, 1.0, -0.3, 1.0)
  124.     call ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0)
  125.     call lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0)
  126.  
  127.     call textsize(0.4, 0.4)
  128.  
  129. c
  130. c    patchcurves provides a number of curves in the t and u
  131. c    directions. patchprecision gives the minimum number of line
  132. c    segments making up the curves in the t and u directions. The
  133. c    actual number of linesegments in t or u is equal to the closest
  134. c    integer multiple of the number of curves, > nsegs, in t or u,
  135. c    greater than or equal to the number set by patchprecision in u or
  136. c    t. eg. curves in t will be made up of 21 line segments so that we
  137. c    can match up the 7 curves in u; curves in u will have 24 as 4 by 5
  138. c    gives 20.
  139. c
  140.     call patchcurves(4, 7)
  141.     call patchprecision(20, 20)
  142.  
  143.     do 10 i = 0, 3
  144.  
  145.         call axes
  146.  
  147.  
  148. c
  149. c         patchbasis sets the basis matrices for the t and u
  150. c         functions
  151. c
  152.         call patchbasis(basis(i*16 + 1), basis(i*16 + 1))
  153.  
  154. c        Draw with viewport 2
  155. c
  156.         call move(0.0, 4.0, 0.0)
  157.         call drawstr(labels(i+1))
  158.  
  159. c
  160. c        Now draw the patches according to the geometry matrices in
  161. c        x1, y1, and z1, x2, y2, z2.
  162. c
  163.         call drawhull(x1, y1, z1)
  164.         call patch(x1, y1, z1)
  165.  
  166.         call drawhull(x2, y2, z2)
  167.         call patch(x2, y2, z2)
  168. c
  169. c         Now with viewport 1
  170. c
  171.         call popviewport
  172.         call popmatrix
  173.  
  174.         call axes
  175.  
  176.         call move(0.0, 4.0, 0.0)
  177.         call drawstr(labels(i + 1))
  178.  
  179. c
  180. c        now draw the patches according to the geometry matrices in
  181. c         x1, y1, and z1, x2, y2, z2.
  182. c
  183.         call drawhull(x1, y1, z1)
  184.         call patch(x1, y1, z1)
  185.  
  186.         call drawhull(x2, y2, z2)
  187.         call patch(x2, y2, z2)
  188.  
  189.         call getkey
  190.  
  191. c
  192. c         Save viewport 1 again and reset to viewport 2
  193. c
  194.         call pushviewport
  195.         call pushmatrix
  196.  
  197.         call viewport(-0.3, 1.0, -0.3, 1.0)
  198.         call ortho(-1.5, 5.0, -1.5, 5.0, -1.5, 5.0)
  199.         call lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0)
  200.  
  201.         call color(BLACK)
  202.         call clear
  203. 10    continue
  204.  
  205.     call vexit
  206.  
  207.     end
  208.  
  209.  
  210.     subroutine drawhull(x, y, z)
  211.     real    x(4,4), y(4,4), z(4,4)
  212.  
  213.     integer MAGENTA, WHITE, GREEN
  214.     parameter (MAGENTA = 5, WHITE = 7, GREEN = 2)
  215.  
  216.     call color(MAGENTA)    
  217.     do 10 i = 1,4
  218.         call move(x(i,1), y(i,1), z(i,1))
  219.         do 5 j = 1,4
  220.             call draw(x(i,j), y(i,j), z(i,j))
  221. 5        continue
  222. 10    continue
  223.     
  224.     do 20 i = 1,4
  225.         call move(x(1,i), y(1,i), z(1,i))
  226.         do 15 j = 1,4
  227.             call draw(x(j,i), y(j,i), z(j,i))
  228. 15        continue
  229. 20    continue
  230.  
  231.     call color(GREEN)
  232.     end
  233.  
  234. c
  235. c axes
  236. c
  237. c    draw the axes
  238. c
  239.  
  240.     subroutine axes
  241.  
  242.     integer YELLOW
  243.     parameter (YELLOW = 3)
  244.  
  245.     call color(YELLOW)
  246.     call move(0.0, 0.0, 0.0)
  247.     call draw(4.0, 0.0, 0.0)
  248.  
  249.     call move(0.0, 0.0, 0.0)
  250.     call draw(0.0, 4.0, 0.0)
  251.  
  252.     call move(0.0, 0.0, 0.0)
  253.     call draw(0.0, 0.0, 4.0)
  254.  
  255.     end
  256.