#!/usr/bin/perl

$zstart =0.2;
$zend = -0.2;
$increment = 0.05;
$y=0.0;
$i=1;


# print($zstart,"  ",$zend,"  ",$increment,"\n");

$zclip=$zstart;

while ($zclip >= $zend) {
   for($y = -1 ; $y <=0; $y += 0.1) {
      open(OUT,">bounding.r3d") || die("Can't open bounding.r3d\n");
      print OUT  "8\n";
      print OUT  "7.  0.6   0.5 0.7 1.0   0.0   0 0 0 3\n";
      print OUT  "SOLID   0.800   0.800   0.700\n";
      print OUT  "BOUNDING_COLOR 0.800   0.800   0.700\n";
      print OUT  "BOUNDING_PLANE 0 0.0 0.0 $zclip    0.0 $y 1.0\n";
      close(OUT);
      print   "BOUNDING_PLANE 0 0.0 0.0 $zclip    0.0 $y 1.0\n";
      # For SGI
      #   $ImgFileSpec = sprintf("animate_%03d.rgb",$i);
      #   system("render -sgi $ImgFileSpec < master.r3d");

      # For Linux 
      $ImgFileSpec = sprintf("animate_bounding_%03d.png",$i);
      system("render -png temp.png < master.r3d");
      system("convert -font \"/usr/share/fonts/default/TrueType/helb____.ttf\" -pointsize 24 -fill red -draw \'text 10,20 \"Zclip=  $zclip\"\' temp.png $ImgFileSpec");      system("convert -font \"/usr/share/fonts/default/TrueType/helr____.ttf\" -pointsize 24 -fill red -draw \'text 10,20 \"Zclip=  $zclip  y=$y \"\' temp.png $ImgFileSpec");

      $i++;
   }
   $zclip -= $increment;
   system("rm \$TMPDIR/R3D*")
}

system("rm temp.png");
