? "===============================================================\n",
  " Fly through of a small asteroid field.\n",
  " The sequence is currently not finished.  Animations should set\n",
  " total frames to 500, first frame to 1, and last frame to 80.\n",
  "===============================================================\n";


!--------------------------------------------------------------------
!!
!! Global variables...
!!
!--------------------------------------------------------------------

 integer MakeReplicas = 1;

 matrix MAT;

 vector CPOS;

 
!--------------------------------------------------------------------
!!
!! Colors ...
!!
!--------------------------------------------------------------------
 WHITE   : color( RGB, [1.0, 1.0, 1.0] );
 PALEGRN : color( RGB, [0.8, 0.9, 0.8] );
 GRAY    : color( RGB, [0.5, 0.5, 0.5] );
 BLACK   : color( RGB, [0.0, 0.0, 0.0] );
 RED     : color( RGB, [0.9, 0.0, 0.0] );
 BLUE    : color( RGB, [0.0, 0.0, 0.8] );


 asteroid_tm : texturemap( "asteroid.ilbm" );
 stars_tm    : texturemap( "starfield.ilbm" );


!--------------------------------------------------------------------
!!
!! Surfaces ...
!!
!--------------------------------------------------------------------

!                           ka   kd   ks    n    km   kr   ri   kb
 STARSURF: surface( PHONG, 1.5, 0.0, 0.0,  0.0, 0.0, 0.0, 0.0, 0.0, 0 );
 DULL    : surface( PHONG, 0.5, 0.4, 0.0,  0.0, 0.0, 0.0, 0.0, 0.0, 0 );

 asteroid_bm : bumpmap( "asteroid.ilbm" );


!--------------------------------------------------------------------
!!
!! Procedure to import the asteroids...
!!
!--------------------------------------------------------------------

 proc LOADBACKASTEROIDS()
   vector   arot, apos;
   matrix   amat;


   boundary

!
! Huge asteroids
!
     arot = [130,1300*PROGRESS,10+40*PROGRESS];
     apos = [-100,10000,150];
     amat = xform(arot);
     bast_0 : boundary( apos )
       ast0 : IMPORT( "ast5_b.obj", apos, [1,1,1], arot, [1,1,1], PHONG );
       txt0 : texture( sphere, asteroid_tm, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 6,3, SMOOTH5 );
       bmp0 : bump( sphere, asteroid_bm, dull, 5.0, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 6,3, NEGATIVE );

       ast0.color[0] = txt0;
       ast0.surface[0] = bmp0;
     endboundary


!
! Big asteroids
!
     arot = [800*PROGRESS,30,10];
     apos = [1000,0,300];
     amat = xform(arot);
     bast_1 : boundary( apos )
       asta : IMPORT( "ast4_a.obj", apos, [1,1,1], arot, [1,1,1], PHONG );
       txta : texture( sphere, asteroid_tm, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 2,1, SMOOTH5 );
       bmpa : bump( sphere, asteroid_bm, dull, 5.0, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 2,1, NEGATIVE );

       asta.color[0] = txta;
       asta.surface[0] = bmpa;
     endboundary

     if (MakeReplicas) {
       arot = [10,1800*PROGRESS,130+200*PROGRESS];
       apos = [-2000,3000,100];
       replica( bast_1, apos, arot );

       arot = [-1100*PROGRESS,10,130];
       apos = [-2300,1000,1300];
       replica( bast_1, apos, arot );

       arot = [0,200-200*PROGRESS,1000*PROGRESS];
       apos = [2900,4000,-500];
       replica( bast_1, apos, arot );

       arot = [30,-600*PROGRESS,PROGRESS*100-130];
       apos = [-500,-1900,-1300];
       replica( bast_1, apos, arot );
     }


!
! Littler asteroids
!

     arot = [300,1800*PROGRESS,10];
     apos = [-500,-200,300];
     amat = xform(arot);
     bast_2 : boundary( apos )
       astb : IMPORT( "ast4_b.obj", apos, [1,1,1]*0.6, arot, [1,1,1], PHONG );
       txtb : texture( sphere, asteroid_tm, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 1,1, SMOOTH5 );
       bmpb : bump( sphere, asteroid_bm, dull, 5.0, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 1,1, NEGATIVE );

       astb.color[0] = txtb;
       astb.surface[0] = bmpb;
     endboundary

     if (MakeReplicas) {
       arot = [10,-1900*PROGRESS,130+400*PROGRESS];
       apos = [-700,-2000,-200];
       replica( bast_2, apos, arot );
  
       arot = [-1100*PROGRESS,60,130];
       apos = [-1300,-1000,-1300];
       replica( bast_2, apos, arot );

       arot = [50,200+400*PROGRESS,-1000*PROGRESS];
       apos = [600,-3100,-400];
       replica( bast_2, apos, arot );

       arot = [130,-600*PROGRESS,-PROGRESS*100-130];
       apos = [250,1000,100]+[-500,-150,-100]*PROGRESS*9;
       replica( bast_2, apos, arot );
     }

!
! Littlest asteroids
!

     arot = [50,230,-1050*PROGRESS];
     apos = [500,-2000,1300];
     amat = xform(arot);
     bast_3 : boundary( apos )
       astc : IMPORT( "ast4_c.obj", apos, [1,1,1]*0.4, arot, [1,1,1], PHONG );
       txtc : texture( sphere, asteroid_tm, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 1,1, SMOOTH5 );
       bmpc : bump( sphere, asteroid_bm, dull, 5.0, apos,
	   [0,0,1]#amat, [1,0,0]#amat, 1,1, NEGATIVE );

       astc.color[0] = txtc;
       astc.surface[0] = bmpc;
     endboundary


     if (MakeReplicas) {
       arot = [10,-1900*PROGRESS,130+400*PROGRESS];
       apos = [-1700,-2000,-200];
       replica( bast_3, apos, arot );

       arot = [-1900*PROGRESS,60,-130];
       apos = [1300,1000,-1300];
       replica( bast_3, apos, arot );

       arot = [200+500*PROGRESS,150,900*PROGRESS];
       apos = [400,-2700,-400];
       replica( bast_3, apos, arot );

       arot = [130,-2600*PROGRESS,PROGRESS*100-130];
       apos = [-250,-2000,100]+[500,-150,-100]*PROGRESS*10;
       replica( bast_3, apos, arot );
     }
   endboundary optimize

 endproc


!====================================================================
!!
!! Now we are ready to generate our pictures.
!!
!! Progress points of interest...
!!  0.0 - Start of the scene
!!  0.1 - Start of 1st fly by...
!!  0.3 - Start of 2nd fly by...
!!  0.4 - Start of encounter forcing us toward large asteroid.
!!  0.6 - Start of the orbital sequence
!!  1.0 - End of scene
!!
!! Camera maintains position with xy plane as ground plane
!! other stu reference...
!!
!====================================================================

 frameloop

  clearscene;


! Move the camera
  CPOS : tween( PLANE, PROGRESS
	$ 0.0, [0,-40000,0] $
        $ 1.0, [0, 10000,0] $ );

  camera'POS = CPOS;
  camera'TARGET = camera'POS + [0,100,0];


! Create background starfield
  starmap : texture( SPHERE, stars_tm, [0,0,0],
    [0,0,1], [1,0,0], 10,10, smooth3 repeat );
  sphere( [0,0,0], 10000000, starmap, STARSURF );


!--------------------------------------------------------------------
!!
!! Background asteroids only...
!!
!! We start this sequence with the camera at [0,0,-5000]
!! and finish with it at [0,0,-1000]
!!
!--------------------------------------------------------------------


  LOADBACKASTEROIDS();

!--------------------------------------------------------------------
!!
!! Lighting...
!!
!--------------------------------------------------------------------

   star   ( [30000,-40000,80000], [1.0, 1.0, 1.0 ], 6000 );
   ambient( [0,0,0], [0.6,0.6,0.6], [0,0,1], 0, 0 );


!--------------------------------------------------------------------
!!
!! Background ...
!!
!--------------------------------------------------------------------

   background( PLAIN, [0,0,0] );


   render;

 nextframe

END
