home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / graphic / irit / morphing.irt < prev    next >
Text File  |  1992-08-23  |  8KB  |  282 lines

  1. #
  2. # A simple example of morphing.
  3. #
  4. #                    Gershon Elber, July 1992.
  5. #
  6.  
  7. save_res = resolution;
  8. resolution = 10;
  9. if ( machine, "=", msdos, ( resolution = 7 ) );
  10. step = 0.05;
  11. if ( machine, "=", msdos, ( step = 0.2 ) );
  12.  
  13. # Needs these variable in loops.
  14. SrfIso = 0;
  15. MSrf = 0;
  16.  
  17. FloorLvl = -0.72;
  18.  
  19. v1 = vector( -16.0, -16.0, FloorLvl );
  20. V2 = vector( -16.0,  16.0, FloorLvl );
  21. v3 = vector(  16.0,  16.0, FloorLvl );
  22. v4 = vector(  16.0, -16.0, FloorLvl );
  23. Floor = poly( list( v1, v2, v3, v4 ) );
  24. color( Floor, red );
  25. attrib( Floor, "rgb", "244,164,96" );
  26. attrib( Floor, "texture", "wood" );
  27. attrib( Floor, "reflect", "0.3" );
  28.  
  29. #############################################################################
  30. # First Morphing Sequence.                            #
  31. #############################################################################
  32.  
  33. Srf1 = ruledsrf( circle( vector( 0.0, 0.0, FloorLvl + 0.01 ), 1.0 ),
  34.          circle( vector( 0.0, 0.0, FloorLvl + 0.01 ), 0.01 ) );
  35. color( Srf1, yellow );
  36.  
  37. bcross = cbspline( 3,
  38.            list( ctlpt( E3,  0.0,  0.0, -0.71 ),
  39.                  ctlpt( E3,  0.2,  0.0, -0.72 ),
  40.                  ctlpt( E3,  0.25, 0.0, -0.7 ),
  41.                  ctlpt( E3,  0.25, 0.0, -0.1 ),
  42.                  ctlpt( E3,  0.2,  0.0, -0.05 ),
  43.                  ctlpt( E3,  0.15, 0.0,  0.0 ),
  44.                  ctlpt( E3,  0.1,  0.0,  0.6 ),
  45.              ctlpt( E3,  0.11, 0.0,  0.61 ),
  46.              ctlpt( E3,  0.12, 0.0,  0.61 ),
  47.              ctlpt( E3,  0.12, 0.0,  0.65 ),
  48.              ctlpt( E3,  0.09, 0.0,  0.65 ),
  49.              ctlpt( E3,  0.07, 0.0,  0.64 ),
  50.              ctlpt( E3,  0.10, 0.0, -0.05 ),
  51.              ctlpt( E3,  0.21, 0.0, -0.1 ),
  52.              ctlpt( E3,  0.21, 0.0, -0.64 ),
  53.              ctlpt( E3,  0.18, 0.0, -0.67),
  54.              ctlpt( E3,  0.0,  0.0, -0.66 ) ),
  55.            list( KV_OPEN ) );
  56. Srf2 = surfrev( bcross );
  57. free( bcross );
  58. color( Srf2, green );
  59.  
  60. #
  61. # Must make them compatible before doing some morphing.
  62. #
  63. ffcompat( Srf1, Srf2 );
  64.  
  65. #
  66. # Since we would like the animation to look as good as possible we need
  67. # to precompute as much as possible before invoking view to erase old
  68. # drawing and display new one. That is why we precompute isolines.
  69. #
  70. for ( ( i = 0 ), step, 1.0,
  71.     (
  72.       ( SrfIso = gpolyline( smorph( Srf1, Srf2, i ) ) ):
  73.       view( SrfIso, true )
  74.     )
  75. );
  76.  
  77. view( list( Srf1, Srf2 ), true );
  78. for ( ( i = step ), step, 1.0 - step,
  79.     (
  80.       ( SrfIso = gpolyline( smorph( Srf1, Srf2, i ) ) ):
  81.       view( SrfIso, false )
  82.     )
  83. );
  84.  
  85. #
  86. # Now dump 12 steps in this morphing sequence as 12 distinct files.
  87. #
  88.  
  89. for ( ( i = 0.0 ), 1.0, 11.0,
  90.     (
  91.       ( Msrf = smorph( Srf1, Srf2, i / 11.0 ) ):
  92.       color( Msrf, white ):
  93.       attrib( Msrf, "rgb", "255,255,255" ):
  94.       attrib( Msrf, "reflect", "0.7" ):
  95.       save( "morp1-" + i, list( view_mat, Msrf, Floor ) )
  96.     )
  97. );
  98.  
  99. #############################################################################
  100. # Second Morphing Sequence.                            #
  101. #############################################################################
  102.  
  103. bcross = cbspline( 3,
  104.            list( ctlpt( E3,  0.0,  0.0, -0.71 ),
  105.                  ctlpt( E3,  0.2,  0.0, -0.72 ),
  106.                  ctlpt( E3,  0.25, 0.0, -0.7 ),
  107.                  ctlpt( E3,  0.25, 0.0, -0.1 ),
  108.                  ctlpt( E3,  0.2,  0.0, -0.05 ),
  109.                  ctlpt( E3,  0.15, 0.0,  0.0 ),
  110.                  ctlpt( E3,  0.1,  0.0,  0.6 ),
  111.              ctlpt( E3,  0.11, 0.0,  0.61 ),
  112.              ctlpt( E3,  0.12, 0.0,  0.61 ),
  113.              ctlpt( E3,  0.12, 0.0,  0.65 ),
  114.              ctlpt( E3,  0.09, 0.0,  0.65 ),
  115.              ctlpt( E3,  0.07, 0.0,  0.64 ),
  116.              ctlpt( E3,  0.10, 0.0, -0.05 ),
  117.              ctlpt( E3,  0.21, 0.0, -0.1 ),
  118.              ctlpt( E3,  0.21, 0.0, -0.64 ),
  119.              ctlpt( E3,  0.18, 0.0, -0.67),
  120.              ctlpt( E3,  0.0,  0.0, -0.66 ) ),
  121.            list( KV_OPEN ) );
  122. Srf2 = surfrev( bcross );
  123. free( bcross );
  124. color( Srf2, green );
  125.  
  126. gcross = cbspline( 3,
  127.            list( ctlpt( E3, 0.001, 0.0, 0.02 ),
  128.                ctlpt( E3, 0.2,   0.0, 0.02 ),
  129.              ctlpt( E3, 0.22,  0.0, 0. ),
  130.              ctlpt( E3, 0.22,  0.0, 0.03 ),
  131.              ctlpt( E3, 0.03,  0.0, 0.03 ),
  132.              ctlpt( E3, 0.03,  0.0, 0.07 ),
  133.              ctlpt( E3, 0.04,  0.0, 0.3 ),
  134.              ctlpt( E3, 0.3,   0.0, 0.3 ),
  135.              ctlpt( E3, 0.4,   0.0, 0.4 ),
  136.              ctlpt( E3, 0.3,   0.0, 0.7 ),
  137.              ctlpt( E3, 0.28,  0.0, 0.7 ),
  138.              ctlpt( E3, 0.37,  0.0, 0.42 ),
  139.              ctlpt( E3, 0.31,  0.0, 0.32 ),
  140.              ctlpt( E3, 0.001, 0.0, 0.32 ) ),
  141.         list( KV_OPEN ) );
  142. Srf3 = surfrev( gcross * trans( vector( 0.0, 0.0, -0.45 ) ) *
  143.              scale( vector( 1.6, 1.6, 1.6 ) ) );
  144. free( gcross );
  145. color( Srf3, cyan );
  146.  
  147. #
  148. # Must make them compatible before doing some morphing.
  149. #
  150. ffcompat( Srf2, Srf3 );
  151.  
  152. for ( ( i = 0 ), step, 1.0,
  153.     (
  154.       ( SrfIso = gpolyline( smorph( Srf2, Srf3, i ) ) ):
  155.       view( SrfIso, true )
  156.     )
  157. );
  158.  
  159. view( list( Srf2, Srf3 ), true );
  160. for ( ( i = step ), step, 1.0 - step,
  161.     (
  162.       ( SrfIso = gpolyline( smorph( Srf2, Srf3, i ) ) ):
  163.       view( SrfIso, false )
  164.     )
  165. );
  166.  
  167. #
  168. # Now dump 12 steps in this morphing sequence as 12 distinct files.
  169. #
  170.  
  171. for ( ( i = 0.0 ), 1.0, 11.0,
  172.     (
  173.       ( Msrf = smorph( Srf2, Srf3, i / 11.0 ) ):
  174.       color( Msrf, white ):
  175.       attrib( Msrf, "rgb", "255,255,255" ):
  176.       attrib( Msrf, "reflect", "1.0" ):
  177.       attrib( Msrf, "transp", "0.95" ):
  178.       attrib( Msrf, "index", "1.4" ):
  179.       save( "morp2-" + i, list( view_mat, Msrf, Floor ) )
  180.     )
  181. );
  182.  
  183. #############################################################################
  184. # Third Morphing Sequence.                            #
  185. #############################################################################
  186.  
  187. gcross = cbspline( 3,
  188.            list( ctlpt( E3, 0.001, 0.0, 0.02 ),
  189.                ctlpt( E3, 0.2,   0.0, 0.02 ),
  190.              ctlpt( E3, 0.22,  0.0, 0. ),
  191.              ctlpt( E3, 0.22,  0.0, 0.03 ),
  192.              ctlpt( E3, 0.03,  0.0, 0.03 ),
  193.              ctlpt( E3, 0.03,  0.0, 0.07 ),
  194.              ctlpt( E3, 0.04,  0.0, 0.3 ),
  195.              ctlpt( E3, 0.3,   0.0, 0.3 ),
  196.              ctlpt( E3, 0.4,   0.0, 0.4 ),
  197.              ctlpt( E3, 0.3,   0.0, 0.7 ),
  198.              ctlpt( E3, 0.28,  0.0, 0.7 ),
  199.              ctlpt( E3, 0.37,  0.0, 0.42 ),
  200.              ctlpt( E3, 0.31,  0.0, 0.32 ),
  201.              ctlpt( E3, 0.001, 0.0, 0.32 ) ),
  202.         list( KV_OPEN ) );
  203. Srf3 = surfrev( gcross * trans( vector( 0.0, 0.0, -0.45 ) ) *
  204.              scale( vector( 1.6, 1.6, 1.6 ) ) );
  205. free( gcross );
  206. color( Srf3, cyan );
  207.  
  208. s45 = sin( 45 );
  209. HelixAux = cbspline( 3,
  210.              list( ctlpt( P3, 1, 1, 0, 0 ),
  211.                ctlpt( P3, s45, s45, s45, 0.2 * s45 ),
  212.                ctlpt( P3, 1, 0, 1, 0.4 ),
  213.                ctlpt( P3, s45, -s45, s45, 0.6 * s45 ),
  214.                ctlpt( P3, 1, -1, 0, 0.8 ),
  215.                ctlpt( P3, s45, -s45, -s45, 1.0 * s45 ),
  216.                ctlpt( P3, 1, 0, -1, 1.2 ),
  217.                ctlpt( P3, s45, s45, -s45, 1.4 * s45 ),
  218.                ctlpt( P3, 1, 1, 0, 1.6 ) ),
  219.              list( 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4 ) );
  220. HelixApx = HelixAux +
  221.        HelixAux * trans( vector( 0.0, 0.0, 1.6 ) ) +
  222.        HelixAux * trans( vector( 0.0, 0.0, 3.2 ) );
  223.  
  224. ScaleCrv = cbezier( list( ctlpt( E2, 0.0, 0.01 ),
  225.               ctlpt( E2, 1.0, 1.0 ) ) );
  226.  
  227. Srf4 = sweepsrf( circle( vector( 0.0, 0.0, 0.0 ), 0.8 ), HelixApx, ScaleCrv ) *
  228.     scale( vector( 0.2, 0.2, 0.2 ) ) *
  229.     trans( vector( 0.0, 0.0, FloorLvl ) );
  230.  
  231. free( HelixAux );
  232. free( HelixApx );
  233. free( ScaleCrv );
  234. color( Srf4, magenta );
  235.  
  236. #
  237. # Must make them compatible before doing some morphing.
  238. #
  239. ffcompat( Srf3, Srf4 );
  240.  
  241. for ( ( i = 0 ), step, 1.0,
  242.     (
  243.       ( SrfIso = gpolyline( smorph( Srf3, Srf4, i ) ) ):
  244.       view( SrfIso, true )
  245.     )
  246. );
  247.  
  248. view( list( Srf3, Srf4 ), true );
  249. for ( ( i = step ), step, 1.0 - step,
  250.     (
  251.       ( SrfIso = gpolyline( smorph( Srf3, Srf4, i ) ) ):
  252.       view( SrfIso, false )
  253.     )
  254. );
  255.  
  256. #
  257. # Now dump 12 steps in this morphing sequence as 12 distinct files.
  258. #
  259.  
  260. for ( ( i = 0.0 ), 1.0, 11.0,
  261.     (
  262.       ( Msrf = smorph( Srf3, Srf4, i / 11.0 ) ):
  263.       color( Msrf, white ):
  264.       attrib( Msrf, "rgb", "255,255,255" ):
  265.       attrib( Msrf, "reflect", "1.0" ):
  266.       attrib( Msrf, "transp", "0.95" ):
  267.       attrib( Msrf, "index", "1.4" ):
  268.       save( "morp3-" + i, list( view_mat, Msrf, Floor ) )
  269.     )
  270. );
  271.  
  272.  
  273. free(Srf);
  274. free(Msrf);
  275. free(Srf1);
  276. free(Srf2);
  277. free(Srf3);
  278. free(Srf4);
  279.  
  280. resolution = save_res;
  281.  
  282.