// magf05.pov
// rotate around x axis

#declare  starscale =  200              ;
#declare  starsize  =  0.003            ;

#include "colors.inc"
#include "screen.inc"
#include "shapes.inc"
#include "meter.inc"
#include "earth1.inc"
#include "starmap1.inc"

#declare  rad = 3.141593265/180.0 ;

#declare  L2_half = 0.5*2.0             ;
#declare  L1_half = 0.5*1.1             ;

// dipole angular direction components
#declare  angl_n  = 10.26               ; // degrees
#declare  angl_e  = 71.78-180           ; // degrees ( to west )

// angular dipole displacement components
#declare  offs_r  = 552.0*KM/R_Earth    ; // normalized to 1 RE
#declare  offs_n  = 22.2*rad            ; // degrees to radians
#declare  offs_e  = (180.0-141.6)*rad   ; // degrees to radians

// find Cartesian displacement components
#declare  offs_h  = offs_r*cos(offs_n)  ;
#declare  offs_x  = offs_h*sin(offs_e)  ;
#declare  offs_y  = offs_r*sin(offs_n)  ;
#declare  offs_z  = offs_h*cos(offs_e)  ;

// server sky
#declare  m288    = 12789.0*KM/R_Earth  ;

//---------------------------------------------------------------------------

Set_Camera_Location ( <   0.0,   2.0, -10.0 > )
Set_Camera_Look_At  ( <   0.0,   0.0,   0.0 > )
Set_Camera_Angle    ( 25.0 )

light_source{ < -10.0,  0.0, -50.0 > color     White }

//---------------------------------------------------------------------------

#declare  magfield = color rgbt < 1.0, 1.0, 0.0, 0.8 > ;

// squash torus to approximate McIlwain sin()^2
#declare  magv     = sqrt( 1.0 / ( sqrt( 8.0 ) - 1 ) ) ; 

#declare earthfield = union {
   union {
      object   { earth1 rotate -90*y }
      cylinder { -1.100*y, 1.100*y, 0.010 texture { pigment { color <1,0,0> }}}
      cylinder { -0.002*y, 0.002*y, 1.003 texture { pigment { color <1,0,0> }}}
      cylinder { -0.002*z, 0.002*z, 1.003 texture { pigment { color <0,0,1> }}}
      cylinder { -0.002*x, 0.002*x, 1.003 texture { pigment { color <1,1,1> }}}

      // longitude and latitude
      #declare  lat = -80.0*rad ;
      #while( lat < 81.0*rad )
         #declare sm    = sin(lat) - 0.001 ;
         #declare sp    = sin(lat) + 0.001 ;
         #declare cp    = cos(lat) + 0.001 ;
         // #debug concat( str(lat,8,1), str(sp,8,4), str(cp,8,4), "\n" ) 
         cylinder { sm*y, sp*y, cp texture { pigment { color <0.5,0.5,0.5> }}}
         #declare lat = lat + 10.0*rad  ;
      #end

      #declare  long = 0 ;
      #while( long < 180 ) 
         cylinder { -0.002*x, 0.002*x, 1.002
                     texture { pigment { color <0.5,0.5,0.5> }}
                     rotate long*y
         }
         #declare long = long+10 ;
      #end
   }
   union {
      difference {
         torus { L2_half, L2_half }
         torus { L1_half, L1_half }
         texture { pigment { color magfield }
                   finish  { ambient 0.9 diffuse 0.2 } }
         scale < 1.0, magv, 1.0 >
      }
      cylinder { -1.1*y, 1.1*y, 0.01 texture { pigment { color <1,1,0> } } }
      rotate    angl_n * x
      rotate    angl_e * y
      translate < offs_x , offs_y, offs_z >
   }

   object { torus { m288, 0.002 }
            texture { pigment { color <1,1,1> }
                      finish  { ambient 1.0 diffuse 0.0 } }
            // rotate 90*x 
   }
}

object { earthfield rotate -clock*y }   // 0, 45, 90, 135 ... 315
union  { AllStars( White ) }

