#!/usr/bin/perl

open(OLDDAT, "mapleeye3.dat");

$n=0;
while(<OLDDAT>){
    $nn=2000 - $n;

   $file=$nn.".pov";
   open(NEWDAT, ">$file");
   @data1=split(/\s+/);
   $next1=<OLDDAT>;
    $next2=<OLDDAT>;
    $next3=<OLDDAT>;
    $next4=<OLDDAT>;
    $next5=<OLDDAT>;
   @data2=split(/\s+/,$next);
   @data3=split(/\s+/,$next);
   @data4=split(/\s+/,$next);
    @data5=split(/\s+/,$next);
   $xx=(($data1[0]+$data2[0]+$data3[0]+$data4[0]+$data5[0])/5 +$xxold)/2;
   $yy=(($data1[1]+$data2[1]+$data3[1]+$data4[1]+$data5[0])/5 + $yyold)/2;
   $zz=(($data1[2]+$data2[2]+$data3[2]+$data4[2]+$data5[0])/5 + $zzold)/2;
   $all="location<".$xx."+0.03,".$yy."+0.02,".$zz."+0.09>";
   $lookx=($data5[0]-$data1[0])/sqrt(($data5[0]-$data1[0])*($data5[0]-$data1[0]));
   $looky=($data5[1]-$data1[1])/sqrt(($data5[1]-$data1[1])*($data5[1]-$data1[1]));
   $lookz=($data5[2]-$data1[2])/sqrt(($data5[2]-$data1[2])*($data5[2]-$data1[2]));
   $all2="look_at <0,0,0>";  #".$xx.",".$yy.",".$zz.">";
   $all3="light_source\{<".$xx."+0.09,".$yy."+0.09,".$zz."+0.09> color White*0.7\} ";
   print NEWDAT ("#include \"colors.inc\"","\n");
   print NEWDAT ("#include \"textures.inc\"","\n");
   print NEWDAT ("#declare Cam1 =camera \{", "\n");
   print NEWDAT ($all, "\n" );
   print NEWDAT ($all2, "\n");
   print NEWDAT ("\}", "\n");
   print NEWDAT ("camera{Cam1}", "\n");
   print NEWDAT ($all3, "\n");
   system("cat top.pov >> $file");
   system("cat rosspo.dat >> $file");
   system("cat minpo.dat >> $file");
   system("povray go.ini $file Display=False");
    $n++;
    $xxold=$xx;
    $yyold=$yy;
    $zzold=$zz;
   }
